Skip to content

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

Merged
merged 6 commits into from
Nov 23, 2016
Merged

tickvals / ticktext edge cases #1191

merged 6 commits into from
Nov 23, 2016

Conversation

alexcjohnson
Copy link
Collaborator

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

@etpinard

if(suffix) {
if(hover) {
// hover puts it all on one line, so suffix works best up front
tt = suffix + (tt ? ' ' + tt : '');
Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.

Looks we're getting a little too much information on regular date axis (e.g. the date_axis mock)

gifrecord_2016-11-22_170028

Copy link
Collaborator Author

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.

@etpinard etpinard added status: reviewable bug something broken labels Nov 22, 2016
var index = ax._categories.indexOf(v);
if(index !== -1) return index;
if(typeof v === 'number') return v;
};
Copy link
Collaborator Author

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);
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Collaborator Author

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 : '');
Copy link
Contributor

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 : '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.

Looks we're getting a little too much information on regular date axis (e.g. the date_axis mock)

gifrecord_2016-11-22_170028

'3',
'3.999' // 3.999 does not get rounded
'30',
'39.999' // 39.999 does not get rounded
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Collaborator Author

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'],
Copy link
Contributor

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 🏦

Copy link
Contributor

@etpinard etpinard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcjohnson
Copy link
Collaborator Author

Man, this code has a ridiculous number of edge cases, but all the ones I can think of are tested now (including the date_axis hovertext you pointed out). Any more?

// 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 = '';
Copy link
Contributor

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, [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@alexcjohnson alexcjohnson merged commit bd24421 into master Nov 23, 2016
@alexcjohnson alexcjohnson deleted the tickvals-edge-cases branch November 23, 2016 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants