-
Notifications
You must be signed in to change notification settings - Fork 794
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
docs: Add example of reordering stacked bars #3395
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So simple and convenient! I'll definitely start using this :)
I have just some minor comments.
tests/examples_arguments_syntax/interactive_reorder_stacked_bars.py
Outdated
Show resolved
Hide resolved
tests/examples_arguments_syntax/interactive_reorder_stacked_bars.py
Outdated
Show resolved
Hide resolved
tests/examples_arguments_syntax/interactive_reorder_stacked_bars.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Stefan Binder <binder_stefan@outlook.com>
Thanks @binste ! I updated with your suggested changes. |
source = data.barley.url | ||
|
||
alt.Chart(source).mark_bar().transform_calculate( | ||
site_order=f"if({selection.name}.site && indexof({selection.name}.site, datum.site) !== -1, 0, 1)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im fine with current approach, but an observation is that this is JavaScript syntax. I'm not sure if the Python syntax for this type of Vega expressions is more readable.
While often underestimated in efficiency, we don't really have a good approach documented to work with these Vega expressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, @jonmmease made a similar comment in #3362 (comment) and I would also prefer to change to the Python syntax in general in the docs. However, I think we should solve #3366 first, so that the Py syntax covers everything that the JS syntax can do (this instance is the only difference I'm aware of).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, I remember being bitten by this recently too!
This example shows how to reorder bar segments via a click interaction in the legend. Credit to @dwootton who came up with the spec in this very neat tweet which I modified slightly to include opacity changes and to allow for sorting multiple segments.
recording-2024-04-06_16.42.20.mp4