-
-
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
4d70fd3
d3208e9
e5a71ad
4a571aa
5f7eedf
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) { | ||
alexshoe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // 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++; | ||
|
||
| }); | ||
| return coordCount; | ||
alexshoe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| 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? | ||
alexshoe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * Only required if it's different from `dflt` | ||
| */ | ||
| axes.coerceRefArray = function(containerIn, containerOut, gd, attr, expectedLen) { | ||
alexshoe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
alexshoe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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]))) { | ||
alexshoe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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
Contributor
Author
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. just documenting that we chatted about this and decided we'd look deeper into |
||
| 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'; } | ||
alexshoe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if(ar === 'paper') { return 'paper'; } | ||
| if(ar === 'pixel') { return 'pixel'; } | ||
| if(/( domain)$/.test(ar)) { return 'domain'; } else { return 'range'; } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.