-
-
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 3 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 |
|---|---|---|
|
|
@@ -53,6 +53,25 @@ exports.extractPathCoords = function(path, paramsToUse, isRaw) { | |
| return extractedCoordinates; | ||
| }; | ||
|
|
||
| exports.countDefiningCoords = function(path, isNotPath) { | ||
| // non-path shapes always have 2 defining coordinates | ||
| if(isNotPath) return 2; | ||
| if(!path) return 0; | ||
|
|
||
| var segments = path.match(constants.segmentRE); | ||
| if(!segments) return 0; | ||
|
|
||
| var coordCount = 0; | ||
| segments.forEach(function(segment) { | ||
| // for each path command, check if there is a drawn coordinate | ||
| var segmentType = segment.charAt(0); | ||
| var hasDrawnX = constants.paramIsX[segmentType].drawn !== undefined; | ||
| var hasDrawnY = constants.paramIsY[segmentType].drawn !== undefined; | ||
| if(hasDrawnX || hasDrawnY) coordCount++; | ||
|
Comment on lines
+66
to
+70
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. Hmm. For example here is a rectangular path: There are four segments (not counting {
"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 That said, it seems probably better than the other alternative that comes to mind, which would be to force the user to add an |
||
| }); | ||
| return coordCount; | ||
| }; | ||
|
|
||
| exports.getDataToPixel = function(gd, axis, shift, isVertical, refType) { | ||
| var gs = gd._fullLayout._size; | ||
| var dataToPixel; | ||
|
|
||
| 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,44 @@ 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, expectedLen) { | ||
|
||
| var axLetter = attr.charAt(attr.length - 1); | ||
| var axlist = gd._fullLayout._subplots[axLetter + 'axis']; | ||
| axlist = axlist.concat(axlist.map(function(x) { return x + ' domain'; })); | ||
| var refAttr = attr + 'ref'; | ||
| var axRef = containerIn[refAttr]; | ||
| var dflt = axlist.length ? axlist[0] : 'paper'; | ||
|
|
||
| // 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 | ||
| axRef = axRef.slice(0, expectedLen); | ||
| } else if(axRef.length < expectedLen) { | ||
| // if the array is shorter than the expected length, extend using the 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(!(axRef[i] === 'paper' || cartesianConstants.idRegex[axLetter].test(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 | ||
|
|
@@ -134,6 +173,7 @@ axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption | |
| */ | ||
| axes.getRefType = function(ar) { | ||
| if(ar === undefined) { return ar; } | ||
| if(Array.isArray(ar)) { return 'array'; } | ||
|
||
| if(ar === 'paper') { return 'paper'; } | ||
| if(ar === 'pixel') { return 'pixel'; } | ||
| if(/( domain)$/.test(ar)) { return 'domain'; } else { return 'range'; } | ||
|
|
||
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.
a more intuitive function signature here would be
function(shapeType, path)I think