-
Notifications
You must be signed in to change notification settings - Fork 628
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
Custom sort order #2915
Comments
Great idea! Being able to specify facet ordering seems like an essential feature. FWIW, as a Vega-Lite noob, I tried the following:
Then I tried this (your proposal here):
I think the above syntax would be really great. As a separate thought, if the notion of "ordinal" is there in Vega, and is distinct from "nominal", wouldn't it be nice to be able to specify in the data definition the natural ordering of a column? |
The same data field can be treated as ordinal or nominal so it makes more sense to specify it as |
Makes sense. Thanks for your reply. |
Column used to be implemented with scales but now we use Vega layouts (which is more flexible and produces nicer output). Does the code snippet with scale pass JSON schema validation in the editor? |
@domoritz No, it does not pass schema validation. I discovered the validation in the editor only after trying the configuration (rather blindly) in my code. |
Okay, that's what I wanted. When we implement this feature, you'll use |
Sounds good! If I had some time to dig and try to implement this, where would be the place to start? |
I'd first check how to sort facets in Vega, then see where in Vega-Lite we already generate the order property, and then lastly I'd write some code to let users override the default (+tests). |
I would say start with non-facet channel like x and y first. Try to see how you can derive a new field by generating a Vega formula transform and then use the new field to sort scale. For facet channel, then you would similar use the same formula flow, but apply it to facet mark definition groups and headers. Note that there is also the stack case that you should handle for consistency. To make review easier, u might want to just tackle the simplest case which is the non-facet channels first. |
Maybe I'm missing something, but as far as I can tell, non-facet channels like X and Y already support custom sort ordering by explicitly setting the scale domain, right? |
Yes! The difference is that faceting doesn't use scales but Vega layouts instead. |
Yes, we already support scale domain for non-facet channels. But if Another thing that is better about the proposal for |
Aha that's a great point! |
Currently, for unit encoding, we can specify custom order for normal (non-facet) encoding channel by specifying
scale.domain
directly.However, we don't have similar support for
Since facet does not have scale domain, we can't use similar syntax. But facet has
sort
property like other encoding channel. Thus, I think we should makesort
support a custom array, which derives a formula like this so that it's safer than setting domain directly (as domain would still include omitted values).For stack, we can then also make stack order orders by color/detail (or any other stack-by field) by default.
The text was updated successfully, but these errors were encountered: