tickvals / ticktext edge cases#1191
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.
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.
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.
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.
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.
|
|
||
| // 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.
Thanks for that comment. Very useful.
| 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.
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.
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.
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 : ''); |
| '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.
Bonus points for reusing an existing test case. 🎉
| // 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.
Is that || 0 fallback testing somewhere? It looks fragile.
There was a problem hiding this comment.
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.
This looks pretty useful. Nice feature to have in the 🏦
etpinard
left a comment
There was a problem hiding this comment.
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 = ''; |
| ax.range = ['1999-12-31 23:59', '2000-01-01 00:01']; | ||
| mockCalc(ax); | ||
|
|
||
| checkHovers(ax, [ |

Fixes #738 as well as a bunch of other odd edge cases around tickvals with or without ticktext on all axis types.
@etpinard