Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions draftlogs/7659_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix pan/zoom failing on first interaction when traces have different `zorder` values [[#7659](https://github.com/plotly/plotly.js/pull/7659)]
11 changes: 10 additions & 1 deletion src/plots/cartesian/dragbox.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file can remain unchanged if you follow the suggestion in plots.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');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var cartesianConstants = require('./cartesian/constants');
const { zindexSeparator } = 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];
}
}
Comment on lines +899 to +910
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prodded Claude to dig into this and this is the resulting solution. Updating this one file should take care of the issue without updating dragbox.js. Could you give this change a shot and let me know if it fixes your problem?

Suggested change
// 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];
}
}
// Preserve z-indexed subplots (e.g. 'xyz2', 'xyz3') created by drawFramework.
// These aren't in newSubplotList.cartesian because supplyTraceDefaults only
// registers base subplot IDs. We restore them from oldSubplots so they
// survive relayout cycles that don't trigger drawFramework.
for (const [oldId, oldPlot] of Object.entries(oldSubplots)) {
if (oldId.includes(zindexSeparator) && !newSubplots[oldId]) {
const baseId = oldId.split(zindexSeparator)[0];
const basePlotinfo = newSubplots[baseId];
if (basePlotinfo) {
// Update axis refs to avoid stale references
oldPlot.xaxis = basePlotinfo.xaxis;
oldPlot.yaxis = basePlotinfo.yaxis;
oldPlot._hasClipOnAxisFalse = basePlotinfo._hasClipOnAxisFalse;
newSubplots[oldId] = oldPlot;
newSubplotList.cartesian.push(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