vega / vega-lite

A concise grammar of interactive graphics, built on Vega.
https://vega.github.io/vega-lite/
BSD 3-Clause "New" or "Revised" License
4.58k stars 598 forks source link

Avoid filtering out entries from legends when the data is filtered via the legend #9360

Closed joelostblom closed 2 days ago

joelostblom commented 2 months ago

Enhancement Description

If a legend filters the data when clicked, the legend will also be updated to remove all categories that are not selected. This has a few undesirable side effects, such as the color of the category changing after the click, not being able to select multiple legend entries, and having to double click to go back and select another entry (which is not clear unless you know this is how the interaction works). A current workaround for this is to specify a constant domain, but that only works if all the unique values are known ahead of time (which e.g. is not the case when creating a more general spec that will work with multiple data sources, such as in https://github.com/vega/altair/pull/3394).

Would it be possible to add an option so that legends are not filtered when the data is filtered, so that the legend entries correspond to the unique data values from the initial view only?

Here is an example image Open the Chart in the Vega Editor

If I click to select "Japan", the color scheme changes to show "Japan" in blue instead of as in Orange in the original picture, and there is not way to shift click to add e.g. "USA" to the selection since the other legend entries are now filtered out

image

Here is an example of keeping all the entries in the legend even when the data is filtered https://plotly.com/python/plotly-express/#gallery

PBI-David commented 2 months ago

Is this any help as a workaround: https://stackoverflow.com/questions/78066133/vega-lite-pie-chart-with-multi-selection-in-the-legend

joelostblom commented 1 month ago

Thanks for your suggestion @PBI-David ! I want to avoid a layered spec if possible so I opened https://github.com/vega/vega-lite/pull/9374 to enable another way of doing this in Vega-Lite.