-
-
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
Control categorical ordering from layout #189
Comments
right I was thinking about adding two axis attributes:
|
(from @chriddyp):
eventually the min-max -> alphabetical -> natural sorting would be a really nice interactive addition to the bar charts |
Looking into this. |
Here are my initial thoughts in the form of (obviously, currently failing) test cases. Basically, the category order spec would override the order in which the points were supplied. Glad to receive any feedback on whether it's the right track. https://github.com/plotly/plotly.js/compare/master...monfera:189-ordinal-scale-domain-item-ordering?diff=unified&expand=1&name=189-ordinal-scale-domain-item-ordering |
To clarify on ordering: for simplicity, my plan is to rearrange the data points according to the category order spec (if supplied), arriving at a trace order different from what would follow from the user-supplied point series. However, if adjacent points are linked via lines or curves, then in general, there is a difference between
It might eventually be desirable to reorder the columns without impacting the tracing order. As a visual analogy, consider something like the snail trail chart, e.g. http://southpoint.frbatlanta.org/.a/6a011572565d3f970b0120a540feff970b-pi Again, I'm not planning to make this distinction in this CR as I see no requirement for it and its utility is questionable, but wanted to expose the issue for future consideration. |
First, Resolving the issue should:
|
@etpinard yes, I started off with them as seen in the test cases. Added a couple more categorymodes: https://github.com/monfera/plotly.js/blob/189-ordinal-scale-domain-item-ordering/src/plots/cartesian/layout_attributes.js#L449-L474 Step 3 hasn't achieved the desired effect. Doing some insertion sort at the suggested point makes ax.d2c return incorrect array indices (as subsequent insertions may cause array element shifts, making previously returned indices out of sync). As an alternative, I sorted right before the loop ax.d2c is called from, but it doesn't reorder the Y values into the corresponding order, i.e. the wrong Y values are plotted. I'm in the process of identifying what the best point is for the sort, it might need to be an earlier point. I'll also consider the corresponding Y value reordering in ax.makeCalcdata as it's closest in the call stack to the point you specified. |
Minor comment: an old commit explicitly deletes an axis layout attribute called |
@monfera Looks like you're already pretty far along. Nice 🍻 Would you mind making a PR to this repo with what you've got already? This would make the comment & review process easier. Thanks! |
@etpinard Here's changeset monfera#1 with these two parts:
The 'array' mode implementation is simple, and it alone might already be an acceptable solution to the problem described by @cpsievert in which case I'm glad to progress it into a PR (coercing isn't added and test cases don't work yet), which could be followed by a subsequent PR for the other options which are a bit trickier. Looking forward to guidance and input. Glad to hop on a call or chat if that's more efficient. |
@etpinard I wrote on the distinction between tracing order and (X) axis tick order. Just found that one of the most popular public charts demonstrate an analogy to it: |
Personally, I don't need anything that fancy (yet?). At this point, I would settle for a way to do the following:
I'd happily do my plots with Right now I don't think it's even possible to do that. Having said that, it would be great if it were also possible to do discontinuous axis spacing with this, i.e. if my x-axis is going to look like this:
and then swap in labels for display purposes after the ticks are positioned. |
…if there's no category encountered for a specific categorylist, it should yield null rather than being skipped over)
…ecked; no assumption about trace order (unlike my first cut of the test cases)
… axis order checking
… axis order checking
…ategory ascending', 'category descending']
… at beginning / end
…an axis tail tick
…t's not part of this CR
…ng, fully overlapping category sets
…ss trivial places
…ems to be used across the entire suite)
…trings (with test cases)
Axis category ordering - adds feature #189
done in #419 |
The ordering of a categorical axis is currently determined by the order of values supplied in traces. It would be useful if we could override this ordering in the layout.
I primarily need this for our ggplot2 converter, as we have no way to guarantee ordering of the axis when there are missing values in the first trace (as in plotly/plotly.R#242, plotly/plotly.R#399, plotly/plotly.R#379)
The text was updated successfully, but these errors were encountered: