Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joelostblom opened this issue May 30, 2024 · 2 comments · Fixed by #9374
Closed

Comments

@joelostblom
Copy link
Contributor

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 vega/altair#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
Copy link
Contributor

@joelostblom
Copy link
Contributor Author

Thanks for your suggestion @PBI-David ! I want to avoid a layered spec if possible so I opened #9374 to enable another way of doing this in Vega-Lite.

domoritz pushed a commit that referenced this issue Jul 28, 2024
## PR Description

Currently the Vega-Lite schema does not officially support the use of
the option `react` to params. It still works to use it in the online
editor, but it raises an error when validating the spec in Altair. We
want to use it to create a constant color domain like in [this
example](https://vega.github.io/editor/#/url/vega-lite/N4Igxg9gdgZglgcxALlANzgUwO4tJKAFzigFcJSBnAdTgBNCALFAZgAY2AacaYsiygAlMiRoVYcAvpO50AhoTl4QpAE4AbFCDGEADpWQB6Q2DpQAdACtKdTOrhpV5qJkKGougLaG0mBHIBaeUVKV0oAATQARnMAJgBOczZDYLkTOVVKK0poEBkQXQy5T0oUAG1QKGLMLULVYoB9FhBuUPVMMHFUEEIAT10a5AKIEnFuTChIOhIEUuQynnUIVRAAXXyAIxI6LXaECZ2ZSuraos8AFhaQTAAPXRWhughPORIACgBySCXVD4BKPKcY6eQaLZYNJ4vEhXVSYOSdFAwOTqULjO4PApnS6SVbcQj1KCUGDLTzlUDwdSETAPUB1YqneqeJp5HHcF6qADWyj6A1qIyIVwp7R2yHxpEw+QmUxmym+y2U8DsIpAAHlVIhoXj+qCoM8SMirpQwMjBqBIa8oMpbvctHLVBDnhaWfkbgqsOplYJlqFdBBsNSrjzQQBHUhyIhwRTEXyAkC9N1KrQAWTg7UoDQG9oA4silpatbyhqHw8Qow4atJuAASI2MTAvLQ6fRGHx+OTmBCRxikDbmOAQQy1+tpXz+AL2Kk+ACs5iiAHYktlcpIgA)
originally from
vega/altair#3394 (comment). Adding
this functionality would allow us to have a constant color domain even
when filtering which is very useful (and could even be a good default
option for using the legend to filter colors). Without setting a
constant domain, it is not possible to click additional categories since
they disappear from the legend as described in
#9360

close #9360

## Checklist

- [x] This PR is atomic (i.e., it fixes one issue at a time).
- [x] The title is a concise [semantic commit
message](https://www.conventionalcommits.org/) (e.g. "fix: correctly
handle undefined properties").
- [x] `yarn test` runs successfully
- For new features:
  - [ ] Has unit tests.
  - [ ] Has documentation under `site/docs/` + examples.

---------

Co-authored-by: GitHub Actions Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants