Skip to content
Open
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
Next Next commit
fix: preserve z-indexed subplots during relayout for correct pan/zoom
When traces have different `zorder` values, plotly.js creates z-indexed
subplots (e.g., `xyz2`, `xyz3`) in `drawFramework`. However, when
`relayout` is called (e.g., during resize), `supplyDefaults` resets
`_plots` via `linkSubplots`, losing these z-indexed subplots. Since
`relayout` doesn't trigger `drawFramework`, they aren't recreated.

This caused pan/zoom to fail on the first attempt in react-plotly.js,
because `updateSubplots` in `dragbox.js` couldn't find the z-indexed
subplots to transform.

Fix:
1. In `linkSubplots`, preserve z-indexed subplots from `oldSubplots`
2. In `updateSubplots`, include z-indexed subplots from `_plots`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
  • Loading branch information
ryan-williams and claude committed Nov 27, 2025
commit e54fbac945bc5db5b977178485cd44a13cb03307
11 changes: 10 additions & 1 deletion src/plots/cartesian/dragbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,9 +872,18 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
function updateSubplots(viewBox) {
var fullLayout = gd._fullLayout;
var plotinfos = fullLayout._plots;
var subplots = fullLayout._subplots.cartesian;
var subplots = fullLayout._subplots.cartesian.slice();
var i, sp, xa, ya;

// Include z-indexed subplots from _plots that may not be in _subplots.cartesian
// (e.g., after a relayout that resets _subplots.cartesian but preserves _plots)
var zindexSeparator = constants.zindexSeparator;
for(var plotId in plotinfos) {
if(plotId.indexOf(zindexSeparator) !== -1 && subplots.indexOf(plotId) === -1) {
subplots.push(plotId);
}
}

if(hasSplom) {
Registry.subplotsRegistry.splom.drag(gd);
}
Expand Down
14 changes: 14 additions & 0 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var Color = require('../components/color');
var BADNUM = require('../constants/numerical').BADNUM;

var axisIDs = require('./cartesian/axis_ids');
var cartesianConstants = require('./cartesian/constants');
var clearOutline = require('../components/shapes/handle_outline').clearOutline;
var scatterAttrs = require('../traces/scatter/layout_attributes');

Expand Down Expand Up @@ -895,6 +896,19 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
}
}

// Preserve z-indexed subplots (e.g. 'xyz2', 'xyz3') from oldSubplots to _plots only.
// These are created by drawFramework when traces have different zorder values.
// We preserve them to _plots (not _subplots.cartesian) so that drag/pan operations
// in dragbox.js can still transform them during relayout operations that don't
// trigger a full redraw (e.g., resize). If drawFramework runs later, it will
// properly update/remove these subplots as needed.
var zindexSeparator = cartesianConstants.zindexSeparator;
for(var oldId in oldSubplots) {
if(oldId.indexOf(zindexSeparator) !== -1 && !newSubplots[oldId]) {
newSubplots[oldId] = oldSubplots[oldId];
}
}

// while we're at it, link overlaying axes to their main axes and
// anchored axes to the axes they're anchored to
var axList = axisIDs.list(mockGd, null, true);
Expand Down