def _sort_categories()

in chartify/_core/plot.py [0:0]


    def _sort_categories(source, categorical_columns, categorical_order_by, categorical_order_ascending):
        is_string = isinstance(categorical_order_by, str)
        order_length = getattr(categorical_order_by, "__len__", None)
        # Sort the categories
        if is_string and categorical_order_by == "values":
            return PlotMixedTypeXY._sort_categories_by_value(source, categorical_columns, categorical_order_ascending)
        elif is_string and categorical_order_by == "labels":
            return source.sort_index(axis=0, ascending=categorical_order_ascending)
        # Manual sort
        elif not is_string and order_length is not None:
            return source.reindex(categorical_order_by, axis="index")

        raise ValueError("""Must be 'values', 'labels', or a list of values.""")