-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
value ascending / value descending #3606
Comments
It could, but maybe we want this sorting-by-value feature for non-category axes also? |
What would it mean to sort a non-category (ie continuous) axis? |
I can't think of any use case for this off the top of my head |
In the presence of multiple traces, one should be able to specify how to aggregate the values (sum, mean, max, median, etc...). This will require a new attribute. @nicolaskruchten can you remind me the name you suggested for this attribute. |
I don't think I had a good name for it :) Please note that this will need to apply not only across traces but across all values of the same category (i.e. you can have multiple data rows at the same category within a trace too!) |
In branch Unfortunately, running cc @plotly/plotly_js, @alexcjohnson |
Very nicely done @antoinerg I don't think we can implement this w/o calling Looks like the trickiest part of this PR now becomes this block: for(var k = 0; k < cd.length; k++) {
if(type === 'scatter') {
categoriesValue[cd[k].x][1] += cd[k].y;
} else if(type === 'histogram') {
categoriesValue[cd[k].p][1] += cd[k].s;
}
} which will be hard to generalize. Note that if(type === 'scatter') {
categoriesValue[cd[k].x][1] += cd[k].y;
} works when the x-axis has a set if(type === 'scatter') {
categoriesValue[cd[k].y][1] += cd[k].x;
} for y-axes with |
You could say the same about I guess with a categorical Y axis you generally do read the graph from top to bottom, as opposed to numerical axes that you almost always read bottom to top. But making that the default behavior I think has much more extensive consequences than just choosing it for the new feature. So unless we're prepared to alter the rest of that behavior, I think ascending has to put the biggest at the top. |
Yes, indeed. What trace types should initially be supported? @nicolaskruchten What aggregation do we want to support initially? Would |
Sum/min/max is a fine start for this release, yes! |
Adding avg can be done in one pass also though no? |
Re trace types I would say bar and histogram are quite important |
ALL 2d cartesian please. |
Ok, then I will need to inspect the output of
To support all traces, we could either have a long list of To be continued |
sounds like the winner to me! To be computed & added only when necessary. |
Good, I also think it's a winner. I now need to write tests to ensure all cartesian traces have Thanks @alexcjohnson for pointing me in the right direction! |
Ok, I made good progress in branch
To be continued |
Awesome work @antoinerg ! Would you be interested in trying to fix #1097 at some point this week? Sounds like fixing that bug and adding some custom logic for |
Ok good to know. They are indeed a bit different and I wasn't sure how to tackle them on Friday :) I'll focus on |
Note: if we add |
Does the current design leave room for a future way of saying "sort by the values of trace X" ? |
How "future"? Does the data/traces split count? 😉 |
less future than that :) ... I guess if we added "first" and "last" and expected people to reorder their traces to match that'd be a workaround. But it would be nice to maybe sort by the nth? |
Thank you for the comment @nicolaskruchten. It will be easy to include in the code: when collecting values associated with each category, we could loop only over the traces we care about at this line: https://github.com/plotly/plotly.js/compare/sort-by-value#diff-ad4f76ccd6044ed16514297078e13b84R2855. As for how it should be specified via attributes, I am not sure yet. In the end, we need to deduce the indices of the traces we want to consider. So maybe an array of trace indices? 🤔 |
Just leaving a note here: I assume that this sorting will take into account |
As discussed in private, adding support for median or say mean raises the following question in the presence of multiple traces: do you want the mean of the means or the mean of all values. We probably will need to support both. |
wanted to braindump part of a conversation I had with @antoinerg here. It's not critical to resolve this for 1.48 but I want to make sure we don't lock ourselves out of a more complete API. It seems that in
The motivation for 1 is that I might want to sort the axis by a single trace, and we'd likely want to specify a way of breaking ties, so in extremis we'd want to allow an exhaustive ordered list, and we'd also want to specify "no among-trace order preference". The motivation for 2 is that in the case of grouped bars at least, I might want to sort by the height of the maximum stack, rather than the maximum single element. The motivation for 3 is pretty clear: we need to aggregate somehow. Taking just the case of 3 and 2 together, we might imagine an attr that takes two functions that interact such that my max-stack idea would be "max sum". In that case, the options that @antoinerg already implemented already work nicely as "max max", "min min" and "sum sum". It would also allow us to do something like "mean median" to order grouped box-plots in a particular way. Not all options make sense, clearly, such as "min max" or "mean mean" or "median median" so we could imagine a world where we enumerate the options perhaps. So in terms of a half-baked attempt at an API, we could accept two attrs: a composite aggregation function that accepts |
I'll leave the comment above as-is but upon further reflection, I think that point 1 is maybe interesting but doesn't allow you to sort by 'trace 1 with ties broken by trace 3'. For that we need a modification on point 3. Elaborating: Maybe the 'outer' operator needs to be able to say not only |
@antoinerg can you open a new issue about up-coming |
I'm making categorical histograms (with and without
z
andhistfunc: sum
). I'd like to be able to sort these histograms in descending by value order without using transforms.Maybe this would fit under
categoryorder: 'value ascending'
andcategoryorder: 'value descending'
? https://github.com/plotly/plotly.js/pull/419/files#diff-0e41c2e162564438ff091d0ed6b5b455R472The text was updated successfully, but these errors were encountered: