-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Multi-axis Shapes #7666
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
base: master
Are you sure you want to change the base?
Multi-axis Shapes #7666
Changes from all commits
c8be45f
a7b3bb2
ace820b
a910d42
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 |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ var Drawing = require('../../components/drawing'); | |
|
|
||
| var axAttrs = require('./layout_attributes'); | ||
| var cleanTicks = require('./clean_ticks'); | ||
| var cartesianConstants = require('./constants'); | ||
|
|
||
| var constants = require('../../constants/numerical'); | ||
| var ONEMAXYEAR = constants.ONEMAXYEAR; | ||
|
|
@@ -124,6 +125,49 @@ axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption | |
| return Lib.coerce(containerIn, containerOut, attrDef, refAttr); | ||
| }; | ||
|
|
||
| /* | ||
| * Coerce an array of axis references. Used by shapes for per-coordinate axis references. | ||
| * | ||
| * attr: the attribute we're generating a reference for. Should end in 'x' or 'y' | ||
| * but can be prefixed, like 'ax' for annotation's arrow x | ||
| * dflt: the default to coerce to, or blank to use the first axis (falling back on | ||
| * extraOption if there is no axis) | ||
| * extraOption: aside from existing axes with this letter, what non-axis value is allowed? | ||
| * Only required if it's different from `dflt` | ||
| */ | ||
| axes.coerceRefArray = function(containerIn, containerOut, gd, attr, dflt, extraOption, expectedLen) { | ||
| var axLetter = attr.charAt(attr.length - 1); | ||
| var axlist = gd._fullLayout._subplots[axLetter + 'axis']; | ||
| var refAttr = attr + 'ref'; | ||
| var axRef = containerIn[refAttr]; | ||
|
|
||
| // Build the axis list, which we use to validate the axis references | ||
| if(!dflt) dflt = axlist[0] || (typeof extraOption === 'string' ? extraOption : extraOption[0]); | ||
| axlist = axlist.concat(axlist.map(function(x) { return x + ' domain'; })); | ||
| axlist = axlist.concat(extraOption ? extraOption : []); | ||
|
|
||
| // Handle array length mismatch | ||
|
Contributor
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. Should probably raise a warning in both of these cases |
||
| if(axRef.length > expectedLen) { | ||
| // if the array is longer than the expected length, truncate it | ||
| Lib.warn('Array attribute ' + refAttr + ' has more entries than expected, truncating to ' + expectedLen); | ||
| axRef = axRef.slice(0, expectedLen); | ||
| } else if(axRef.length < expectedLen) { | ||
| // if the array is shorter than the expected length, extend using the default value | ||
| Lib.warn('Array attribute ' + refAttr + ' has fewer entries than expected, extending with default value'); | ||
| axRef = axRef.concat(Array(expectedLen - axRef.length).fill(dflt)); | ||
| } | ||
|
|
||
| // Check all references, replace with default if invalid | ||
| for(var i = 0; i < axRef.length; i++) { | ||
| if(!axlist.includes(axRef[i])) { | ||
| axRef[i] = dflt; | ||
| } | ||
| } | ||
|
|
||
| containerOut[refAttr] = axRef; | ||
|
Contributor
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. The core |
||
| return axRef; | ||
| }; | ||
|
|
||
| /* | ||
| * Get the type of an axis reference. This can be 'range', 'domain', or 'paper'. | ||
| * This assumes ar is a valid axis reference and returns 'range' if it doesn't | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
HandVsegments cause an odd usability issue I hadn't considered: if a path containsHandVsegments then the expected lengths ofxrefandyrefmay be different, and the corresponding list items will be "out of sync" with respect to which path segments they correspond to (i.e. it will not always be the case thatxref[n]andyref[n]refer to the same path segment).For example here is a rectangular path:
M0,0H10V5H0Z(see visualization)There are four segments (not counting
Z), but only 3 x-values and 2 y-values are needed to define the shape. So you would have:{ "path": "M0,0H10V5H0Z", "xref": ["x", "x2", "x"], "yref": ["y", "y2"], }which is a bit odd, and sort a high cognitive load for the user to figure out the right
xrefandyreflists.That said, it seems probably better than the other alternative that comes to mind, which would be to force the user to add an
xrefand ayreffor every single segment, even if it will be ignored for some segments.