@staticmethod
    def _sort_legend(legend_sort_field, legend_sort_direction, legends, attributes):
        if legend_sort_field:
            if len(attributes[legend_sort_field].columns) > 0:

                # TODO(fpliger): attributes should be consistent and not
                #               need any type checking but for
                #               the moment it is not, specially when going
                #               though a process like binning or when data
                #               is built for HeatMap, Scatter, etc...
                item_order = [x[0] if isinstance(x, tuple) else x
                    for x in attributes[legend_sort_field].items]

                item_order = [str(x) if not isinstance(x, string_types)
                    else x for x in item_order]

                def foo(leg):
                    return item_order.index(leg[0])
                reverse = legend_sort_direction == 'descending'
                return list(sorted(legends, key=foo, reverse=reverse))

        return legends
Test the creation of a simple XlsxWriter file.
dataset/ETHPy150Open bokeh/bokeh/bokeh/charts/builder.py/Builder._sort_legend--crossover with--dataset/ETHPy150Open jmcnamara/XlsxWriter/xlsxwriter/test/comparison/test_chart_display_units01.py/TestCompareXLSXFiles.test_create_file