From 7c8cfdf6c9f13929bbf106cbac962f78abb1eafe Mon Sep 17 00:00:00 2001 From: Farkites Date: Thu, 21 Mar 2024 11:53:44 +0000 Subject: [PATCH 1/6] Add mock with zindex on overlaying axis --- test/image/mocks/zindex_mult_axes.json | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/image/mocks/zindex_mult_axes.json diff --git a/test/image/mocks/zindex_mult_axes.json b/test/image/mocks/zindex_mult_axes.json new file mode 100644 index 00000000000..00617243c79 --- /dev/null +++ b/test/image/mocks/zindex_mult_axes.json @@ -0,0 +1,55 @@ +{ + "data": [ + { + "x": [2, 3, 4, 5], + "y": [4, 3, 9, 5], + "name": "blue", + "type": "scatter", + "marker": {"size": 20}, + "line": {"width": 6}, + "yaxis": "y", + "zindex": 5 + }, + { + "x": [2, 3, 4, 5, 6], + "y": [2, 5, 4, 6, 4], + "name": "orange", + "type": "scatter", + "marker": {"size": 20}, + "line": {"width": 6}, + "yaxis": "y", + "zindex": 1 + }, + { + "x": [3, 4, 5, 6, 7], + "y": [1, 8, 6, 8, 5], + "name": "green", + "type": "scatter", + "marker": {"size": 20}, + "line": {"width": 6}, + "yaxis": "y2" + }, + + { + "x": [2, 3, 4, 5, 6, 7], + "y": [4, 2, 6, 1, 6, 9], + "name": "bar", + "type": "bar", + "yaxis": "y2", + "zindex": 20 + } + ], + "layout": { + "xaxis": { + "title": { + "text": "zindex stacking" + } + }, + "yaxis": { + "side": "right" + }, + "y2axis": { + "title":{"text":"y2"}, "overlaying": "y" + } + } +} From 5949b8e750c87d2b6e3f7fdbae4bd0b7b145e1ec Mon Sep 17 00:00:00 2001 From: Farkites Date: Fri, 22 Mar 2024 10:44:01 +0000 Subject: [PATCH 2/6] sort subplots --- src/plots/cartesian/index.js | 204 ++++++++++++------ ...x_mult_axes.json => zorder_mult_axes.json} | 29 ++- 2 files changed, 154 insertions(+), 79 deletions(-) rename test/image/mocks/{zindex_mult_axes.json => zorder_mult_axes.json} (65%) diff --git a/src/plots/cartesian/index.js b/src/plots/cartesian/index.js index 2a52d2628e0..01d7822ff0d 100644 --- a/src/plots/cartesian/index.js +++ b/src/plots/cartesian/index.js @@ -126,7 +126,6 @@ exports.finalizeSubplots = function(layoutIn, layoutOut) { */ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) { var fullLayout = gd._fullLayout; - var subplots = fullLayout._subplots.cartesian; var calcdata = gd.calcdata; var i; @@ -141,55 +140,75 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) { for(i = 0; i < calcdata.length; i++) traces.push(i); } - // For each subplot - for(i = 0; i < subplots.length; i++) { - var subplot = subplots[i]; - var subplotInfo = fullLayout._plots[subplot]; - - // Get all calcdata (traces) for this subplot: - var cdSubplot = []; - var pcd; - - // For each trace - for(var j = 0; j < calcdata.length; j++) { - var cd = calcdata[j]; - var trace = cd[0].trace; - - // Skip trace if whitelist provided and it's not whitelisted: - // if (Array.isArray(traces) && traces.indexOf(i) === -1) continue; - if(trace.xaxis + trace.yaxis === subplot) { - // XXX: Should trace carpet dependencies. Only replot all carpet plots if the carpet - // axis has actually changed: - // - // If this trace is specifically requested, add it to the list: - if(traces.indexOf(trace.index) !== -1 || trace.carpet) { - // Okay, so example: traces 0, 1, and 2 have fill = tonext. You animate - // traces 0 and 2. Trace 1 also needs to be updated, otherwise its fill - // is outdated. So this retroactively adds the previous trace if the - // traces are interdependent. - if( - pcd && - pcd[0].trace.xaxis + pcd[0].trace.yaxis === subplot && - ['tonextx', 'tonexty', 'tonext'].indexOf(trace.fill) !== -1 && - cdSubplot.indexOf(pcd) === -1 - ) { - cdSubplot.push(pcd); + var trace; + var subplot; + var subplotZindexGroups = {}; + for(var t = 0; t < calcdata.length; t++) { + trace = calcdata[t][0].trace; + var zi = trace.zindex || 0; + subplot = trace.xaxis + trace.yaxis; + if(!subplotZindexGroups[zi]) subplotZindexGroups[zi] = {}; + if(!subplotZindexGroups[zi][subplot]) subplotZindexGroups[zi][subplot] = []; + subplotZindexGroups[zi][subplot].push(calcdata[t]); + } + var zindices = Object.keys(subplotZindexGroups) + .map(Number) + .sort(Lib.sorterAsc); + + var subplots; + var zindex; + var subplotLayerData = {}; + for(i = 0; i < zindices.length; i++) { + zindex = zindices[i]; + subplots = Object.keys(subplotZindexGroups[zindex]); + + // For each subplot + for(var j = 0; j < subplots.length; j++) { + subplot = subplots[j]; + var subplotInfo = fullLayout._plots[subplot]; + + // Get all calcdata (traces) for this subplot: + var cdSubplot = []; + var pcd; + // For each trace + for(var k = 0; k < subplotZindexGroups[zindex][subplot].length; k++) { + var cd = subplotZindexGroups[zindex][subplot][k]; + trace = cd[0].trace; + // Skip trace if whitelist provided and it's not whitelisted: + // if (Array.isArray(traces) && traces.indexOf(i) === -1) continue; + if(trace.xaxis + trace.yaxis === subplot) { + // XXX: Should trace carpet dependencies. Only replot all carpet plots if the carpet + // axis has actually changed: + // + // If this trace is specifically requested, add it to the list: + if(traces.indexOf(trace.index) !== -1 || trace.carpet) { + // Okay, so example: traces 0, 1, and 2 have fill = tonext. You animate + // traces 0 and 2. Trace 1 also needs to be updated, otherwise its fill + // is outdated. So this retroactively adds the previous trace if the + // traces are interdependent. + if( + pcd && + pcd[0].trace.xaxis + pcd[0].trace.yaxis === subplot && + ['tonextx', 'tonexty', 'tonext'].indexOf(trace.fill) !== -1 && + cdSubplot.indexOf(pcd) === -1 + ) { + cdSubplot.push(pcd); + } + cdSubplot.push(cd); } - cdSubplot.push(cd); + // Track the previous trace on this subplot for the retroactive-add step + // above: + pcd = cd; } - - // Track the previous trace on this subplot for the retroactive-add step - // above: - pcd = cd; } + if(!subplotLayerData[subplot]) subplotLayerData[subplot] = []; + subplotLayerData[subplot] = plotOne(gd, subplotInfo, cdSubplot, transitionOpts, makeOnCompleteCallback, subplotLayerData[subplot]); } - // Plot the traces for this subplot - plotOne(gd, subplotInfo, cdSubplot, transitionOpts, makeOnCompleteCallback); } }; -function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback) { +function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback, layerData) { var traceLayerClasses = constants.traceLayerClasses; var fullLayout = gd._fullLayout; var modules = fullLayout._modules; @@ -205,7 +224,6 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback traceZorderGroups[zi].push(cdSubplot[t]); } - var layerData = []; var zoomScaleQueryParts = []; // Plot each zorder group in ascending order @@ -222,7 +240,8 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback if(categories.svg) { var classBaseName = (_module.layerName || name + 'layer'); - var className = classBaseName + (z ? Number(z) + 1 : ''); + //var className = classBaseName + (z ? Number(z) + 1 : ''); + var className = classBaseName + '_' + zorder; var plotMethod = _module.plot; // plot all visible traces of this type on this subplot at once @@ -235,7 +254,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback if(cdModule.length) { layerData.push({ i: traceLayerClasses.indexOf(classBaseName), - zorder: z, + zorder: zorder, className: className, plotMethod: plotMethod, cdModule: cdModule @@ -307,6 +326,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback plotinfo.zoomScaleTxt = traces.selectAll('.textpoint'); } } + return layerData; } exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) { @@ -378,15 +398,16 @@ exports.drawFramework = function(gd) { var subplotLayers = fullLayout._cartesianlayer.selectAll('.subplot') .data(subplotData, String); - + subplotLayers.enter().append('g') .attr('class', function(d) { return 'subplot ' + d[0]; }); - subplotLayers.order(); - - subplotLayers.exit() - .call(purgeSubplotLayers, fullLayout); + //subplotLayers.order(); + //subplotLayers.exit() + // .call(purgeSubplotLayers, fullLayout); + console.log("Subplotlayers") + console.log(subplotLayers) subplotLayers.each(function(d) { var id = d[0]; var plotinfo = fullLayout._plots[id]; @@ -417,29 +438,67 @@ function makeSubplotData(gd) { var regulars = []; var overlays = []; - for(i = 0; i < len; i++) { - id = ids[i]; - plotinfo = fullLayout._plots[id]; - xa = plotinfo.xaxis; - ya = plotinfo.yaxis; - - var xa2 = xa._mainAxis; - var ya2 = ya._mainAxis; - var mainplot = xa2._id + ya2._id; - var mainplotinfo = fullLayout._plots[mainplot]; - plotinfo.overlays = []; + var calcdata = gd.calcdata; - if(mainplot !== id && mainplotinfo) { - plotinfo.mainplot = mainplot; - plotinfo.mainplotinfo = mainplotinfo; - overlays.push(id); - } else { - plotinfo.mainplot = undefined; - plotinfo.mainplotinfo = undefined; - regulars.push(id); + var trace; + var subplot; + var subplotZindexGroups = {}; + for(var t = 0; t < calcdata.length; t++) { + trace = calcdata[t][0].trace; + var zi = trace.zindex || 0; + subplot = trace.xaxis + trace.yaxis; + if(!subplotZindexGroups[zi]) subplotZindexGroups[zi] = {}; + if(!subplotZindexGroups[zi][subplot]) subplotZindexGroups[zi][subplot] = []; + subplotZindexGroups[zi][subplot].push(calcdata[t]); + } + var zindices = Object.keys(subplotZindexGroups) + .map(Number) + .sort(Lib.sorterAsc); + + console.log(subplotZindexGroups) + + for(i = 0; i < zindices.length; i++) { + console.log(i) + var zindex = subplotZindexGroups[zindices[i]]; + console.log(zindex) + console.log() + var ids = Object.keys(zindex); + for(var j=0; j Date: Wed, 27 Mar 2024 18:43:38 +0000 Subject: [PATCH 3/6] Auto assign bottom subplot in overlaying with zindex --- src/plots/cartesian/index.js | 100 ++++++++++++++++------------------- 1 file changed, 46 insertions(+), 54 deletions(-) diff --git a/src/plots/cartesian/index.js b/src/plots/cartesian/index.js index 01d7822ff0d..bf5375880b6 100644 --- a/src/plots/cartesian/index.js +++ b/src/plots/cartesian/index.js @@ -282,7 +282,6 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback .attr('class', function(d) { return d.className; }) .classed('mlayer', true) .classed('rangeplot', plotinfo.isRangePlot); - layers.exit().remove(); layers.order(); @@ -402,12 +401,11 @@ exports.drawFramework = function(gd) { subplotLayers.enter().append('g') .attr('class', function(d) { return 'subplot ' + d[0]; }); - //subplotLayers.order(); + subplotLayers.order(); + + subplotLayers.exit() + .call(purgeSubplotLayers, fullLayout); - //subplotLayers.exit() - // .call(purgeSubplotLayers, fullLayout); - console.log("Subplotlayers") - console.log(subplotLayers) subplotLayers.each(function(d) { var id = d[0]; var plotinfo = fullLayout._plots[id]; @@ -431,7 +429,7 @@ exports.rangePlot = function(gd, plotinfo, cdSubplot) { function makeSubplotData(gd) { var fullLayout = gd._fullLayout; var ids = fullLayout._subplots.cartesian; - var len = ids.length; + var i, j, id, plotinfo, xa, ya; // split 'regular' and 'overlaying' subplots @@ -454,29 +452,24 @@ function makeSubplotData(gd) { var zindices = Object.keys(subplotZindexGroups) .map(Number) .sort(Lib.sorterAsc); - - console.log(subplotZindexGroups) + var len = zindices.length; - for(i = 0; i < zindices.length; i++) { - console.log(i) + for(i = 0; i < len; i++) { var zindex = subplotZindexGroups[zindices[i]]; - console.log(zindex) - console.log() var ids = Object.keys(zindex); for(var j=0; j Date: Tue, 23 Apr 2024 14:50:08 +0100 Subject: [PATCH 4/6] Apply zorder to traces on overlaying axes --- src/plots/cartesian/index.js | 122 +++++++++++++++---------- test/image/mocks/zorder_mult_axes.json | 23 ++--- 2 files changed, 79 insertions(+), 66 deletions(-) diff --git a/src/plots/cartesian/index.js b/src/plots/cartesian/index.js index bf5375880b6..602c47d09df 100644 --- a/src/plots/cartesian/index.js +++ b/src/plots/cartesian/index.js @@ -127,7 +127,7 @@ exports.finalizeSubplots = function(layoutIn, layoutOut) { exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) { var fullLayout = gd._fullLayout; var calcdata = gd.calcdata; - var i; + var i, j; // Traces is a list of trace indices to (re)plot. If it's not provided, // then it's a complete replot so we create a new list and add all trace indices @@ -142,28 +142,51 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) { var trace; var subplot; - var subplotZindexGroups = {}; + var subplotZorderGroups = {}; for(var t = 0; t < calcdata.length; t++) { trace = calcdata[t][0].trace; - var zi = trace.zindex || 0; + var zi = trace.zorder || 0; subplot = trace.xaxis + trace.yaxis; - if(!subplotZindexGroups[zi]) subplotZindexGroups[zi] = {}; - if(!subplotZindexGroups[zi][subplot]) subplotZindexGroups[zi][subplot] = []; - subplotZindexGroups[zi][subplot].push(calcdata[t]); + if(!subplotZorderGroups[zi]) subplotZorderGroups[zi] = {}; + if(!subplotZorderGroups[zi][subplot]) subplotZorderGroups[zi][subplot] = []; + subplotZorderGroups[zi][subplot].push(calcdata[t]); } - var zindices = Object.keys(subplotZindexGroups) + var zindices = Object.keys(subplotZorderGroups) .map(Number) .sort(Lib.sorterAsc); + var prevSubplots = []; var subplots; + var zin; + var subplotId; + var newsubplotZorderGroups = {}; + for(i = 0; i < zindices.length; i++) { + zin = zindices[i]; + subplots = Object.keys(subplotZorderGroups[zin]); + + // For each subplot + for(j = 0; j < subplots.length; j++) { + subplot = subplots[j]; + if(prevSubplots.indexOf(subplot) === -1) { + prevSubplots.push(subplot); + subplotId = subplot; + } else { + subplotId = subplot + '-over-' + i; + } + if(!newsubplotZorderGroups[zin]) newsubplotZorderGroups[zin] = {}; + if(!newsubplotZorderGroups[zin][subplotId]) newsubplotZorderGroups[zin][subplotId] = []; + newsubplotZorderGroups[zin][subplotId].push(subplotZorderGroups[zin][subplot]); + } + } + var zindex; var subplotLayerData = {}; for(i = 0; i < zindices.length; i++) { zindex = zindices[i]; - subplots = Object.keys(subplotZindexGroups[zindex]); + subplots = Object.keys(newsubplotZorderGroups[zindex]); // For each subplot - for(var j = 0; j < subplots.length; j++) { + for(j = 0; j < subplots.length; j++) { subplot = subplots[j]; var subplotInfo = fullLayout._plots[subplot]; @@ -171,12 +194,13 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) { var cdSubplot = []; var pcd; // For each trace - for(var k = 0; k < subplotZindexGroups[zindex][subplot].length; k++) { - var cd = subplotZindexGroups[zindex][subplot][k]; + for(var k = 0; k < newsubplotZorderGroups[zindex][subplot].length; k++) { + var cd = newsubplotZorderGroups[zindex][subplot][k][0]; trace = cd[0].trace; + // Skip trace if whitelist provided and it's not whitelisted: // if (Array.isArray(traces) && traces.indexOf(i) === -1) continue; - if(trace.xaxis + trace.yaxis === subplot) { + if(trace.xaxis + trace.yaxis === subplot || (subplot.indexOf('-over-') !== -1 && subplot.indexOf(trace.xaxis + trace.yaxis) === 0)) { // XXX: Should trace carpet dependencies. Only replot all carpet plots if the carpet // axis has actually changed: // @@ -240,8 +264,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback if(categories.svg) { var classBaseName = (_module.layerName || name + 'layer'); - //var className = classBaseName + (z ? Number(z) + 1 : ''); - var className = classBaseName + '_' + zorder; + var className = classBaseName + (z ? Number(z) + 1 : ''); var plotMethod = _module.plot; // plot all visible traces of this type on this subplot at once @@ -254,7 +277,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback if(cdModule.length) { layerData.push({ i: traceLayerClasses.indexOf(classBaseName), - zorder: zorder, + zorder: z, className: className, plotMethod: plotMethod, cdModule: cdModule @@ -397,7 +420,7 @@ exports.drawFramework = function(gd) { var subplotLayers = fullLayout._cartesianlayer.selectAll('.subplot') .data(subplotData, String); - + subplotLayers.enter().append('g') .attr('class', function(d) { return 'subplot ' + d[0]; }); @@ -411,7 +434,7 @@ exports.drawFramework = function(gd) { var plotinfo = fullLayout._plots[id]; plotinfo.plotgroup = d3.select(this); - makeSubplotLayer(gd, plotinfo); + makeSubplotLayer(gd, plotinfo, id); // make separate drag layers for each subplot, // but append them to paper rather than the plot groups, @@ -421,7 +444,7 @@ exports.drawFramework = function(gd) { }; exports.rangePlot = function(gd, plotinfo, cdSubplot) { - makeSubplotLayer(gd, plotinfo); + makeSubplotLayer(gd, plotinfo, plotinfo.id); plotOne(gd, plotinfo, cdSubplot); Plots.style(gd); }; @@ -429,7 +452,7 @@ exports.rangePlot = function(gd, plotinfo, cdSubplot) { function makeSubplotData(gd) { var fullLayout = gd._fullLayout; var ids = fullLayout._subplots.cartesian; - + var i, j, id, plotinfo, xa, ya; // split 'regular' and 'overlaying' subplots @@ -440,35 +463,37 @@ function makeSubplotData(gd) { var trace; var subplot; - var subplotZindexGroups = {}; + var subplotZorderGroups = {}; for(var t = 0; t < calcdata.length; t++) { trace = calcdata[t][0].trace; - var zi = trace.zindex || 0; + var zi = trace.zorder || 0; subplot = trace.xaxis + trace.yaxis; - if(!subplotZindexGroups[zi]) subplotZindexGroups[zi] = {}; - if(!subplotZindexGroups[zi][subplot]) subplotZindexGroups[zi][subplot] = []; - subplotZindexGroups[zi][subplot].push(calcdata[t]); + if(!subplotZorderGroups[zi]) subplotZorderGroups[zi] = {}; + if(!subplotZorderGroups[zi][subplot]) subplotZorderGroups[zi][subplot] = []; + subplotZorderGroups[zi][subplot].push(calcdata[t]); } - var zindices = Object.keys(subplotZindexGroups) + var zindices = Object.keys(subplotZorderGroups) .map(Number) .sort(Lib.sorterAsc); var len = zindices.length; + var mainplot; + var mainplotinfo; for(i = 0; i < len; i++) { - var zindex = subplotZindexGroups[zindices[i]]; - var ids = Object.keys(zindex); - for(var j=0; j Date: Wed, 24 Apr 2024 16:54:26 +0100 Subject: [PATCH 5/6] Fix bug with hover and selection on mult axes with zorder --- src/plots/cartesian/graph_interact.js | 3 +- src/plots/cartesian/index.js | 25 ++++++------- test/image/mocks/zorder_mult_axes-copy.json | 41 +++++++++++++++++++++ 3 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 test/image/mocks/zorder_mult_axes-copy.json diff --git a/src/plots/cartesian/graph_interact.js b/src/plots/cartesian/graph_interact.js index a7e08ea41dd..c2e633347c5 100644 --- a/src/plots/cartesian/graph_interact.js +++ b/src/plots/cartesian/graph_interact.js @@ -33,6 +33,7 @@ exports.initInteractions = function initInteractions(gd) { return fullLayout._plots[a].mainplot ? 1 : -1; }); + subplots = subplots.filter(function(subplot) { return !subplot.includes('-over-'); }); subplots.forEach(function(subplot) { var plotinfo = fullLayout._plots[subplot]; var xa = plotinfo.xaxis; @@ -40,7 +41,7 @@ exports.initInteractions = function initInteractions(gd) { // main and corner draggers need not be repeated for // overlaid subplots - these draggers drag them all - if(!plotinfo.mainplot) { + if(!plotinfo.mainplot || plotinfo.mainplot === plotinfo.id) { // main dragger goes over the grids and data, so we use its // mousemove events for all data hover effects var maindrag = makeDragBox(gd, plotinfo, xa._offset, ya._offset, diff --git a/src/plots/cartesian/index.js b/src/plots/cartesian/index.js index 602c47d09df..b3dd6cfcac1 100644 --- a/src/plots/cartesian/index.js +++ b/src/plots/cartesian/index.js @@ -155,14 +155,14 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) { .map(Number) .sort(Lib.sorterAsc); - var prevSubplots = []; var subplots; - var zin; + var zindex; var subplotId; var newsubplotZorderGroups = {}; + var prevSubplots = []; for(i = 0; i < zindices.length; i++) { - zin = zindices[i]; - subplots = Object.keys(subplotZorderGroups[zin]); + zindex = zindices[i]; + subplots = Object.keys(subplotZorderGroups[zindex]); // For each subplot for(j = 0; j < subplots.length; j++) { @@ -173,13 +173,12 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) { } else { subplotId = subplot + '-over-' + i; } - if(!newsubplotZorderGroups[zin]) newsubplotZorderGroups[zin] = {}; - if(!newsubplotZorderGroups[zin][subplotId]) newsubplotZorderGroups[zin][subplotId] = []; - newsubplotZorderGroups[zin][subplotId].push(subplotZorderGroups[zin][subplot]); + if(!newsubplotZorderGroups[zindex]) newsubplotZorderGroups[zindex] = {}; + if(!newsubplotZorderGroups[zindex][subplotId]) newsubplotZorderGroups[zindex][subplotId] = []; + newsubplotZorderGroups[zindex][subplotId].push(subplotZorderGroups[zindex][subplot]); } } - var zindex; var subplotLayerData = {}; for(i = 0; i < zindices.length; i++) { zindex = zindices[i]; @@ -227,7 +226,7 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) { } } if(!subplotLayerData[subplot]) subplotLayerData[subplot] = []; - subplotLayerData[subplot] = plotOne(gd, subplotInfo, cdSubplot, transitionOpts, makeOnCompleteCallback, subplotLayerData[subplot]); + if(subplotInfo) subplotLayerData[subplot] = plotOne(gd, subplotInfo, cdSubplot, transitionOpts, makeOnCompleteCallback, subplotLayerData[subplot]); } } }; @@ -439,7 +438,7 @@ exports.drawFramework = function(gd) { // make separate drag layers for each subplot, // but append them to paper rather than the plot groups, // so they end up on top of the rest - plotinfo.draglayer = ensureSingle(fullLayout._draggers, 'g', id); + if(id.indexOf('over') === -1) plotinfo.draglayer = ensureSingle(fullLayout._draggers, 'g', id); }); }; @@ -494,7 +493,7 @@ function makeSubplotData(gd) { plotinfo.mainplot = mainplot; plotinfo.mainplotinfo = mainplotinfo; overlays.push(id + '-over-' + i); - } else if(mainplot !== id && mainplotinfo) { + } else if(mainplot !== id) { plotinfo.mainplot = mainplot; plotinfo.mainplotinfo = mainplotinfo; overlays.push(id); @@ -548,7 +547,7 @@ function makeSubplotLayer(gd, plotinfo, id) { var yLayer = constants.layerValue2layerClass[plotinfo.yaxis.layer]; var hasOnlyLargeSploms = gd._fullLayout._hasOnlyLargeSploms; - if(!plotinfo.mainplot || (plotinfo.mainplot === id && id.indexOf('-over-') === -1)) { + if(!plotinfo.mainplot || plotinfo.mainplot === id) { if(hasOnlyLargeSploms) { // TODO could do even better // - we don't need plot (but we would have to mock it in lsInner @@ -559,7 +558,7 @@ function makeSubplotLayer(gd, plotinfo, id) { plotinfo.ylines = ensureSingle(plotgroup, 'path', 'ylines-above'); plotinfo.xaxislayer = ensureSingle(plotgroup, 'g', 'xaxislayer-above'); plotinfo.yaxislayer = ensureSingle(plotgroup, 'g', 'yaxislayer-above'); - } else { + } else if(id.indexOf('-over-') === -1) { var backLayer = ensureSingle(plotgroup, 'g', 'layer-subplot'); plotinfo.shapelayer = ensureSingle(backLayer, 'g', 'shapelayer'); plotinfo.imagelayer = ensureSingle(backLayer, 'g', 'imagelayer'); diff --git a/test/image/mocks/zorder_mult_axes-copy.json b/test/image/mocks/zorder_mult_axes-copy.json new file mode 100644 index 00000000000..b3234ee8ddc --- /dev/null +++ b/test/image/mocks/zorder_mult_axes-copy.json @@ -0,0 +1,41 @@ +{ + "data": [ + { + "x": [2, 3, 4, 5], + "y": [4, 3, 9, 5], + "name": "xy - zorder 0", + "type": "scatter", + "marker": {"size": 20}, + "line": {"width": 6}, + "yaxis": "y", + "zorder": 0 + }, + + { + "x": [3, 4, 5, 6, 7], + "y": [1, 8, 6, 8, 5], + "name": "xy2 - zorder 5", + "type": "scatter", + "marker": {"size": 20}, + "line": {"width": 6}, + "yaxis": "y2", + "zorder": 5 + } + + ], + "layout": { + "xaxis": { + "side": "top", + "title": { + "text": "zorder stacking" + } + }, + "yaxis": { + "side": "right", + "title":{"text":"y"}, "overlaying": "y2" + }, + "y2axis": { + "title":{"text":"y2"} + } + } +} \ No newline at end of file From e09b2df971ef535f77a1494495c886198c1daab8 Mon Sep 17 00:00:00 2001 From: Farkites Date: Wed, 24 Apr 2024 17:08:14 +0100 Subject: [PATCH 6/6] Code cleaning --- src/plots/cartesian/index.js | 23 +++++------- test/image/mocks/zorder_mult_axes-copy.json | 41 --------------------- 2 files changed, 9 insertions(+), 55 deletions(-) delete mode 100644 test/image/mocks/zorder_mult_axes-copy.json diff --git a/src/plots/cartesian/index.js b/src/plots/cartesian/index.js index b3dd6cfcac1..79bdb0425e8 100644 --- a/src/plots/cartesian/index.js +++ b/src/plots/cartesian/index.js @@ -613,7 +613,6 @@ function makeSubplotLayer(gd, plotinfo, id) { ensureSingle(mainplotinfo.overlinesBelow, 'path', xId); ensureSingle(mainplotinfo.overlinesBelow, 'path', yId); - ensureSingle(mainplotinfo.overaxesBelow, 'g', xId); ensureSingle(mainplotinfo.overaxesBelow, 'g', yId); @@ -621,7 +620,6 @@ function makeSubplotLayer(gd, plotinfo, id) { ensureSingle(mainplotinfo.overlinesAbove, 'path', xId); ensureSingle(mainplotinfo.overlinesAbove, 'path', yId); - ensureSingle(mainplotinfo.overaxesAbove, 'g', xId); ensureSingle(mainplotinfo.overaxesAbove, 'g', yId); @@ -635,20 +633,17 @@ function makeSubplotLayer(gd, plotinfo, id) { // common attributes for all subplots, overlays or not if(!hasOnlyLargeSploms) { - if(plotinfo.minorGridlayer) { - ensureSingleAndAddDatum(plotinfo.minorGridlayer, 'g', plotinfo.xaxis._id); - ensureSingleAndAddDatum(plotinfo.minorGridlayer, 'g', plotinfo.yaxis._id); - plotinfo.minorGridlayer.selectAll('g') + ensureSingleAndAddDatum(plotinfo.minorGridlayer, 'g', plotinfo.xaxis._id); + ensureSingleAndAddDatum(plotinfo.minorGridlayer, 'g', plotinfo.yaxis._id); + plotinfo.minorGridlayer.selectAll('g') + .map(function(d) { return d[0]; }) + .sort(axisIds.idSort); + + ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.xaxis._id); + ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.yaxis._id); + plotinfo.gridlayer.selectAll('g') .map(function(d) { return d[0]; }) .sort(axisIds.idSort); - } - if(plotinfo.gridlayer) { - ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.xaxis._id); - ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.yaxis._id); - plotinfo.gridlayer.selectAll('g') - .map(function(d) { return d[0]; }) - .sort(axisIds.idSort); - } } plotinfo.xlines diff --git a/test/image/mocks/zorder_mult_axes-copy.json b/test/image/mocks/zorder_mult_axes-copy.json deleted file mode 100644 index b3234ee8ddc..00000000000 --- a/test/image/mocks/zorder_mult_axes-copy.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "data": [ - { - "x": [2, 3, 4, 5], - "y": [4, 3, 9, 5], - "name": "xy - zorder 0", - "type": "scatter", - "marker": {"size": 20}, - "line": {"width": 6}, - "yaxis": "y", - "zorder": 0 - }, - - { - "x": [3, 4, 5, 6, 7], - "y": [1, 8, 6, 8, 5], - "name": "xy2 - zorder 5", - "type": "scatter", - "marker": {"size": 20}, - "line": {"width": 6}, - "yaxis": "y2", - "zorder": 5 - } - - ], - "layout": { - "xaxis": { - "side": "top", - "title": { - "text": "zorder stacking" - } - }, - "yaxis": { - "side": "right", - "title":{"text":"y"}, "overlaying": "y2" - }, - "y2axis": { - "title":{"text":"y2"} - } - } -} \ No newline at end of file