Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Modify shape xref/yref coercion logic
  • Loading branch information
alexshoe committed Dec 5, 2025
commit a910d42f0091679bd27cbac1b305a0477bc83f09
4 changes: 2 additions & 2 deletions src/components/shapes/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {

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

// Need to register the shape with all referenced axes for redrawing purposes
Expand Down
4 changes: 2 additions & 2 deletions src/components/shapes/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ exports.extractPathCoords = function(path, paramsToUse, isRaw) {
return extractedCoordinates;
};

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

var segments = path.match(constants.segmentRE);
Expand Down
14 changes: 9 additions & 5 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,31 @@ axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption
* 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) {
axes.coerceRefArray = function(containerIn, containerOut, gd, attr, dflt, extraOption, 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';

// 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
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(!(axRef[i] === 'paper' || cartesianConstants.idRegex[axLetter].test(axRef[i]))) {
if(!axlist.includes(axRef[i])) {
axRef[i] = dflt;
}
}
Expand All @@ -173,7 +178,6 @@ axes.coerceRefArray = function(containerIn, containerOut, gd, attr, expectedLen)
*/
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'; }
Expand Down