plotly.js
plotly.js copied to clipboard
Property `drawminorticklabel` for custom tick label display
This PR introduces the property drawminorticklabel for drawing the label for each minor tick n positions away from a major tick
- has no effect for category/multicategory/log axes
- has no effect if tickformat frequency incompatible with minor tick frequency
One use case for this feature are period axes where we want to configure which period is labeled.
Current behavior
With "drawminorticklabel": -1
Disclaimer
I am required to add that…the software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
I thought based on the attribute name that this would be about labeling ALL the minor ticks, but it’s just about shifting the label away from the major tick. Is there a use case other than period ticks, where the label is already shifted but now you want to shift it the other way? If that’s the only purpose I’d suggest making this specific to period ticks, something like labelminorperiod=“first”|”last”?
@alexcjohnson: One use case for more options than last and first would be to display the label for a specific quarter within a year. Imagine a quarterly report, for which the authors want to put emphasis on the last data point.
- Major tick interval: 1 year
- Minor tick interval: 1 quarter
- Last data point (to emphasize): Q2 2024
In this example it would be desirable to display the "Q2 24" label, but to have the major ticks follow the Gregorian calendar (ticks on 1st of January).
I see, that’s reasonable. And in this case moving all the tick labels to Q2 is the desired behavior, not just a side effect? Ie would you ideally prefer Q1 to be labeled on all the earlier years (and possibly also 2024) and just label Q2 on 2024, or is what you’ve drawn with every Q2 labeled in fact the goal?
For us this would be the desired behaviour. The rationale is, that you typically want to compare the Q2 value of this year with the Q2 values of previous years.
I don't see a use case for drawing different minor tick labels for different years. I also think something like this would make the interface relatively complex. Therefore I would propose to stay with the level of control My-Tien proposed. What do you think?
Ok great, just wanted to confirm that this is truly the intent. So yes, let’s keep the behavior as implemented.
I’d still like to discuss the name, as to me drawminorticklabel implies adding extra labels rather than moving the already expected labels. It’s also a bit long: @etpinard had what I think is a great rule that no attribute name should concatenate more than three words and this is four.
What about minor.shiftlabels? ie put it inside the minor container since it only applies when there are minor ticks, but we don’t label minor ticks so it’s clear the shift applies to major tick labels.
Great! I don't have a strong opinion on the name, but minor.shiftlabels may be confused with the new property, that is currently being developed in this PR.
How about minor.labeltodisplay?
Thanks for the feedback!
Yes, finding a name is one of the more difficult problems of this PR and any help is welcome!
If we stick to period axes only, how about minor.periodtolabel or minor.labeledperiod?
The only reason why I came up with the original rather generic name is that the feature worked out of the box for linear axes as well and in case someone has a use case for that in the future, the name would still be fitting (But I currently can't think of any use case).
What would be an example of this incompatibility? "has no effect if tickformat frequency incompatible with minor tick frequency"?
What would be an example of this incompatibility? "has no effect if tickformat frequency incompatible with minor tick frequency"?
For example, if the tickformat is "%Y" and the period between minor ticks only span a month, it wouldn't make sense to see a label there.
I noticed that ticklabelmode "period" already behaves in that way: If the tickformat is incompatible with the period, labels will appear on the major tick.
@my-tien Please resolve the conflicts with master on this branch. Thank you!
Thanks for the feedback!
Yes, finding a name is one of the more difficult problems of this PR and any help is welcome!
If we stick to period axes only, how about
minor.periodtolabelorminor.labeledperiod?The only reason why I came up with the original rather generic name is that the feature worked out of the box for linear axes as well and in case someone has a use case for that in the future, the name would still be fitting (But I currently can't think of any use case).
@my-tien if ticklabelindex is working for date and linear axes, I'd suggest you add a mock and expose it for those not only period date axes.
@my-tien Just a few comments to address and we should be good to merge this PR. :star2: