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

docs: Add example of reordering stacked bars #3395

Merged
merged 2 commits into from
Apr 12, 2024
Merged

Conversation

joelostblom
Copy link
Contributor

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

Copy link
Contributor

@binste binste left a 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.

Co-authored-by: Stefan Binder <binder_stefan@outlook.com>
@joelostblom
Copy link
Contributor Author

Thanks @binste ! I updated with your suggested changes.

@joelostblom joelostblom requested a review from binste April 8, 2024 20:00
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)"
Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Contributor

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!

@joelostblom joelostblom merged commit 259d08e into main Apr 12, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants