-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
tickvals / ticktext edge cases #1191
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
Conversation
if(suffix) { | ||
if(hover) { | ||
// hover puts it all on one line, so suffix works best up front | ||
tt = suffix + (tt ? ' ' + tt : ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, hover text on date axes would not get the suffix at all. This changes it for all date axes, not just those with array ticks, to include the suffix (as a prefix... hmm, maybe we should change this name...) which is sometimes more information than you need to interpret it, but it's useful often enough that I think this is the right way to go about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, maybe we should change this name.
That would be nice. suffix
can be easily confused with axis.ticksuffix
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... yep, I see where that's coming from. Looks like I need to add some more explicit tests of Axes.tickText
with hover; the regular (non-hover) cases should all be covered by the calcTicks
test cases.
var index = ax._categories.indexOf(v); | ||
if(index !== -1) return index; | ||
if(typeof v === 'number') return v; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before this change, sometimes tickvals could add categories to the list, but it happened after autorange calculations so they didn't show up (until you zoom out on the axis). It was weird. Now that can't happen. At some point we should probably look through all other uses of ax.d2l
(or ax.d2c
and ax.d2r
, which are all the same function for category axes) and make sure they shouldn't also be using d2l_noadd
... but so far I haven't seen any other ill effects.
@@ -645,6 +648,10 @@ axes.calcTicks = function calcTicks(ax) { | |||
// now figure out rounding of tick values | |||
autoTickRound(ax); | |||
|
|||
// now that we've figured out the auto values for formatting | |||
// in case we're missing some ticktext, we can break out for array ticks | |||
if(ax.tickmode === 'array') return arrayTicks(ax); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for that comment. Very useful.
@@ -704,8 +711,11 @@ function arrayTicks(ax) { | |||
// except with more precision to the numbers | |||
if(!Array.isArray(text)) text = []; | |||
|
|||
// make sure showing ticks doesn't accidentally add new categories | |||
var tickVal2l = ax.type === 'category' ? ax.d2l_noadd : ax.d2l; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non- 🚫 . As far as I know, we only need to add new categories during the trace modules' calc
step (via ax.makeCalcdata
). So perhaps, ax.d2l
should become ax.d2l_noadd
and categories could then be added inside ax.makeCalcdata
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, like #1191 (comment) - there are a bunch of uses outside makeCalcdata
, particularly in gl code that we need to sort out first.
if(suffix) { | ||
if(hover) { | ||
// hover puts it all on one line, so suffix works best up front | ||
tt = suffix + (tt ? ' ' + tt : ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, maybe we should change this name.
That would be nice. suffix
can be easily confused with axis.ticksuffix
.
if(suffix) { | ||
if(hover) { | ||
// hover puts it all on one line, so suffix works best up front | ||
tt = suffix + (tt ? ' ' + tt : ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'3', | ||
'3.999' // 3.999 does not get rounded | ||
'30', | ||
'39.999' // 39.999 does not get rounded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bonus points for reusing an existing test case. 🎉
@@ -856,7 +872,7 @@ function autoTickRound(ax) { | |||
// not necessarily *all* the information in tick0 though, if it's really odd | |||
// minimal string length for tick0: 'd' is 10, 'M' is 16, 'S' is 19 | |||
// take off a leading minus (year < 0 so length is consistent) | |||
var tick0ms = Lib.dateTime2ms(ax.tick0), | |||
var tick0ms = Lib.dateTime2ms(ax.tick0) || 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that || 0
fallback testing somewhere? It looks fragile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's an artifact of an older iteration... not needed anymore.
'2010-01-01', '2014-01-01' // off the axis | ||
], | ||
// only the first two have text | ||
ticktext: ['New year', 'February'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty useful. Nice feature to have in the 🏦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One blocking comment: https://github.com/plotly/plotly.js/pull/1191/files#r89219806
Man, this code has a ridiculous number of edge cases, but all the ones I can think of are tested now (including the |
// latter part: ax._prevDateHead holds what we showed most recently. | ||
// Start with it cleared and mark that we're in calcTicks (ie calculating a | ||
// whole string of these so we should care what the previous date head was!) | ||
ax._prevDateHead = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
ax.range = ['1999-12-31 23:59', '2000-01-01 00:01']; | ||
mockCalc(ax); | ||
|
||
checkHovers(ax, [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good!
Fixes #738 as well as a bunch of other odd edge cases around tickvals with or without ticktext on all axis types.
@etpinard