<jupyter_start><jupyter_text>SortingVizzu provides multiple options to sort data. By default, the data is sorted by the order it is added to Vizzu. This is why we suggest to add temporal data such as dates in chronological order - from oldest to newest.You can also sort the elements by value, which will provide you with an ascending order.<jupyter_code>from ipyvizzu import Chart, Data, Config

chart = Chart()

data = Data.from_json("../data/music_example_data.json")

chart.animate(data)

chart.animate(Config({
    "channels": {
        "y": {
            "set": ["Popularity", "Types"]
        }, 
        "x": {
            "set": "Genres"
        },
        "label": {
            "attach": "Popularity"
        }
    },
    "color": {
        "attach": "Types"
    },
    "title": "Switch to ascending order..."
}))

chart.animate(Config({
    "sort": "byValue",
}))

snapshot1 = chart.store()<jupyter_output><empty_output><jupyter_text>If you want descending order instead, you have to set the reverse parameter to true. When used without setting the sorting to byValue, the elements will be in the opposite order than they are in the data set added to Vizzu.<jupyter_code>chart.animate(snapshot1)

chart.animate(Config({"title": "...or descending order."}))

chart.animate(Config({
    "reverse": True,
}))

snapshot2 = chart.store()<jupyter_output><empty_output><jupyter_text>This is how to switch back to the default sorting.<jupyter_code>chart.animate(snapshot2)

chart.animate(Config({"title": "Let's get back to where we were"}))

chart.animate(Config({
    "sort": "none",
    "reverse": False,
}))

snapshot3 = chart.store()<jupyter_output><empty_output><jupyter_text>When you have more than one dimension on a channel, their order determines how the elements are grouped.<jupyter_code>chart.animate(snapshot3)

chart.animate(Config({"title": "With two discretes on one axis..."}))

chart.animate(Config({
    "channels": {
        "y": {
            "detach": "Types"
        },
        "x": {
            "set": ["Genres", "Types"]
        },
    }
}))

snapshot4 = chart.store()<jupyter_output><empty_output><jupyter_text>When switching the order of dimensions on the x-axis Vizzu will rearrange the elements according to this new logic.<jupyter_code>chart.animate(snapshot4)

chart.animate(Config({"title": "...grouping is determined by their order."}))

chart.animate(Config({
    "channels": {
        "x": {
            "set": ["Types", "Genres"]
        },
    }
}))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13560666137985725, 'fraction_numerical': 0.0031720856463124504, 'mean_word_length': 3.521505376344086, 'pattern_counts': {'":': 26, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '498895', 'license': 'Apache-2.0', 'n_tokens_mistral': 798, 'n_tokens_neox': 777, 'n_words': 230, 'path': 'docs/examples/sorting.ipynb', 'repo_name': 'csaladenes/ipyvizzu', 'size': '2522'}