TargetProcess/tauCharts

Pre-select series in URL

Closed this issue · 4 comments

I have a line graph with a whole bunch of different lines plotted on to it, and the most common way people will use it is to select a few of those lines that they are interested in, using the legend. Once people have selected some lines, it would be great if they could just copy-paste the URL and have other people see the same chart as them.

It is possible in taucharts@2.5.0. I made some example.
Code of example.

Wow, thanks! This example is almost perfect, the one wrinkle it has is that when a selection is reset, every category is added to the URL, rather than the selections being entirely cleared from the URL.

I do have a list of all the categories (to define an order) which I could compare with to check if that's the situation, but I didn't know if there was a more generic way I could do it from the handler?

It's a good solution to compare ordered categories and selected categories. Maybe I'll add event type for handler ('reset', 'leave-others', 'focus-single') in the next version Taucharts.

@OddBloke I added event type param in Taucharts 2.6.0.

Taucharts.api.plugins.get('legend')({
            onSelect({type, selectedCategories}) {
                if(type !== 'reset') {
                    location.hash = 'filter=' + JSON.stringify(selectedCategories);
                } else {
                    location.hash = '';
                }
            },
            selectedCategories: selectedCategories
        })