Skip to content

Commit a910d42

Browse files
committed
Modify shape xref/yref coercion logic
1 parent ace820b commit a910d42

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/components/shapes/defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
8181

8282
if(Array.isArray(inputRef) && inputRef.length > 0) {
8383
// Array case: use coerceRefArray for validation
84-
var expectedLen = helpers.countDefiningCoords(path, noPath);
85-
axRef = Axes.coerceRefArray(shapeIn, shapeOut, gdMock, axLetter, expectedLen);
84+
var expectedLen = helpers.countDefiningCoords(shapeType, path);
85+
axRef = Axes.coerceRefArray(shapeIn, shapeOut, gdMock, axLetter, undefined, 'paper', expectedLen);
8686
shapeOut['_' + axLetter + 'refArray'] = true;
8787

8888
// Need to register the shape with all referenced axes for redrawing purposes

src/components/shapes/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ exports.extractPathCoords = function(path, paramsToUse, isRaw) {
5353
return extractedCoordinates;
5454
};
5555

56-
exports.countDefiningCoords = function(path, isNotPath) {
56+
exports.countDefiningCoords = function(shapeType, path) {
5757
// non-path shapes always have 2 defining coordinates
58-
if(isNotPath) return 2;
58+
if(shapeType !== 'path') return 2;
5959
if(!path) return 0;
6060

6161
var segments = path.match(constants.segmentRE);

src/plots/cartesian/axes.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,31 @@ axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption
135135
* extraOption: aside from existing axes with this letter, what non-axis value is allowed?
136136
* Only required if it's different from `dflt`
137137
*/
138-
axes.coerceRefArray = function(containerIn, containerOut, gd, attr, expectedLen) {
138+
axes.coerceRefArray = function(containerIn, containerOut, gd, attr, dflt, extraOption, expectedLen) {
139139
var axLetter = attr.charAt(attr.length - 1);
140140
var axlist = gd._fullLayout._subplots[axLetter + 'axis'];
141-
axlist = axlist.concat(axlist.map(function(x) { return x + ' domain'; }));
142141
var refAttr = attr + 'ref';
143142
var axRef = containerIn[refAttr];
144-
var dflt = axlist.length ? axlist[0] : 'paper';
143+
144+
// Build the axis list, which we use to validate the axis references
145+
if(!dflt) dflt = axlist[0] || (typeof extraOption === 'string' ? extraOption : extraOption[0]);
146+
axlist = axlist.concat(axlist.map(function(x) { return x + ' domain'; }));
147+
axlist = axlist.concat(extraOption ? extraOption : []);
145148

146149
// Handle array length mismatch
147150
if(axRef.length > expectedLen) {
148151
// if the array is longer than the expected length, truncate it
152+
Lib.warn('Array attribute ' + refAttr + ' has more entries than expected, truncating to ' + expectedLen);
149153
axRef = axRef.slice(0, expectedLen);
150154
} else if(axRef.length < expectedLen) {
151155
// if the array is shorter than the expected length, extend using the default value
156+
Lib.warn('Array attribute ' + refAttr + ' has fewer entries than expected, extending with default value');
152157
axRef = axRef.concat(Array(expectedLen - axRef.length).fill(dflt));
153158
}
154159

155160
// Check all references, replace with default if invalid
156161
for(var i = 0; i < axRef.length; i++) {
157-
if(!(axRef[i] === 'paper' || cartesianConstants.idRegex[axLetter].test(axRef[i]))) {
162+
if(!axlist.includes(axRef[i])) {
158163
axRef[i] = dflt;
159164
}
160165
}
@@ -173,7 +178,6 @@ axes.coerceRefArray = function(containerIn, containerOut, gd, attr, expectedLen)
173178
*/
174179
axes.getRefType = function(ar) {
175180
if(ar === undefined) { return ar; }
176-
if(Array.isArray(ar)) { return 'array'; }
177181
if(ar === 'paper') { return 'paper'; }
178182
if(ar === 'pixel') { return 'pixel'; }
179183
if(/( domain)$/.test(ar)) { return 'domain'; } else { return 'range'; }

0 commit comments

Comments
 (0)