-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Improved category axes conversions #1748
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
Changes from 3 commits
134b54e
48b8131
b67657f
d8462eb
ee3b72c
071249f
4434fad
0fafe14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ var ONEDAY = constants.ONEDAY; | |
var ONEHOUR = constants.ONEHOUR; | ||
var ONEMIN = constants.ONEMIN; | ||
var ONESEC = constants.ONESEC; | ||
var BADNUM = constants.BADNUM; | ||
|
||
var axes = module.exports = {}; | ||
|
||
|
@@ -100,33 +99,20 @@ axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption | |
* - for other types: coerce them to numbers | ||
*/ | ||
axes.coercePosition = function(containerOut, gd, coerce, axRef, attr, dflt) { | ||
var pos, | ||
newPos; | ||
var ax, pos; | ||
|
||
if(axRef === 'paper' || axRef === 'pixel') { | ||
ax = { cleanPos: Lib.num }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need to pretend we're making an axis anymore... just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in 071249f |
||
pos = coerce(attr, dflt); | ||
} | ||
else { | ||
var ax = axes.getFromId(gd, axRef); | ||
|
||
} else { | ||
ax = axes.getFromId(gd, axRef); | ||
dflt = ax.fraction2r(dflt); | ||
pos = coerce(attr, dflt); | ||
|
||
if(ax.type === 'category') { | ||
// if position is given as a category name, convert it to a number | ||
if(typeof pos === 'string' && (ax._categories || []).length) { | ||
newPos = ax._categories.indexOf(pos); | ||
containerOut[attr] = (newPos === -1) ? dflt : newPos; | ||
return; | ||
} | ||
} | ||
else if(ax.type === 'date') { | ||
containerOut[attr] = Lib.cleanDate(pos, BADNUM, ax.calendar); | ||
return; | ||
} | ||
} | ||
// finally make sure we have a number (unless date type already returned a string) | ||
containerOut[attr] = isNumeric(pos) ? Number(pos) : dflt; | ||
|
||
containerOut[attr] = ax.cleanPos(pos); | ||
}; | ||
|
||
}; | ||
|
||
axes.getDataToCoordFunc = function(gd, trace, target, targetArray) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,10 +57,15 @@ module.exports = function calc(gd, trace) { | |
z = binned.z; | ||
} | ||
else { | ||
if(hasColumns(trace)) convertColumnData(trace, xa, ya, 'x', 'y', ['z']); | ||
if(hasColumns(trace)) { | ||
convertColumnData(trace, xa, ya, 'x', 'y', ['z']); | ||
x = trace.x; | ||
y = trace.y; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh interesting... were we double-converting triplet data on category and date axes before? Do we have a test of these cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right. Previously gd._fullLayout.yaxis._categories
// ["3-month", "6-month", "1-year", "2-year", "3-year", "5-year", 0, 1, 2, 3, 4, 5] which still gives the correct result though as the string categories are ignored during Now that, starting in this PR,
Good call. I added |
||
} else { | ||
x = trace.x ? xa.makeCalcdata(trace, 'x') : []; | ||
y = trace.y ? ya.makeCalcdata(trace, 'y') : []; | ||
} | ||
|
||
x = trace.x ? xa.makeCalcdata(trace, 'x') : []; | ||
y = trace.y ? ya.makeCalcdata(trace, 'y') : []; | ||
x0 = trace.x0 || 0; | ||
dx = trace.dx || 1; | ||
y0 = trace.y0 || 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.
Do we want a more descriptive name for this now that it's not just internal to one module?
ensureNumber
?safeNumber
?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.
I went with
ensureNumber
in 071249f