Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zorder attribute to control stacking order of SVG traces drawn into cartesian subplots #6918

Merged
merged 49 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
df9361c
zindex first pass. scatter and bar traces only
emilykl Mar 9, 2024
176f922
Ensure zindex is compared by trace
Farkites Mar 11, 2024
7a5cdac
Add zindex basic baseline
Farkites Mar 11, 2024
1a24eaa
update plot-schema diff
Farkites Mar 11, 2024
5dcf623
Add zindex to image
Farkites Mar 11, 2024
e17739e
Add zindex to all cartesian traces
Farkites Mar 11, 2024
dbbb0d5
Update schema
Farkites Mar 11, 2024
cc2fc92
Fix scattergl zindex
Farkites Mar 11, 2024
6639de5
Add baseline /zindex-scatter-image.png
Farkites Mar 11, 2024
ac0a2a3
Restore dist
Farkites Mar 11, 2024
497b5f1
Remove scattergl zindex
Farkites Mar 11, 2024
071ac98
Remove coerce zindex from scattergl
Farkites Mar 11, 2024
a141e00
Remove zindex from funnelarea
Farkites Mar 11, 2024
cec8d65
Remove zindex from funnelarea
Farkites Mar 11, 2024
abfd1a8
Add zindex for ohlc
Farkites Mar 11, 2024
c1bfd61
Add mocks for zindex
Farkites Mar 11, 2024
32659ae
Add baselines
Farkites Mar 12, 2024
b758267
Fix zindex_violin_box mock
Farkites Mar 12, 2024
e368849
Add draftlog
Farkites Mar 12, 2024
85edbdf
Define zindex in scatter attributes
Farkites Mar 12, 2024
c422f53
Use Lib.sorterAsc for zindices
Farkites Mar 12, 2024
e5003c6
Handle zindex undefined in sort
Farkites Mar 12, 2024
4edefbd
Update draftlog
Farkites Mar 13, 2024
21a0ac1
Update description
Farkites Mar 13, 2024
ff01eb6
Update zindex-scatter-image mock
Farkites Mar 13, 2024
e92b6cd
Add mocks for zindex in histogram, heatmap, and contour traces
Farkites Mar 13, 2024
9e134e8
Add zindex to histogram traces
Farkites Mar 13, 2024
23368c9
Fix zindex routing in attributes
Farkites Mar 13, 2024
ef4d489
Update zindex description
Farkites Mar 13, 2024
edfefcd
Add baselines for zindex image, contour, heatmap, and histogram mocks
Farkites Mar 13, 2024
1ebbf61
Change zindex editType to 'plot'
Farkites Mar 13, 2024
9c1db37
Add zindex to funnel_axis_with_other_traces mock
Farkites Mar 13, 2024
d4b4c0a
Add new baseline for funnel_axis_with_other_traces
Farkites Mar 13, 2024
fe2f9d1
Update plot-schema
Farkites Mar 13, 2024
f9f7892
Fix funnel_axis_with_other_traces baseline
Farkites Mar 14, 2024
75cfb64
Remove zindex_histogram mock and baseline
Farkites Mar 14, 2024
670b55b
Reduce width and height of zindex mocks
Farkites Mar 14, 2024
c061a92
Update zindex baselines
Farkites Mar 14, 2024
27f51ec
Add Jasmine tests for zindex
Farkites Mar 21, 2024
17ffddb
Merge branch 'master' into trace-zindex
Farkites Mar 21, 2024
b76e894
Add jasmine test for clearing and adding zindex traces
Farkites Mar 22, 2024
c2c268c
Add select tests for zindex traces
Farkites Mar 25, 2024
4a1901c
Change naming of layers with zindex
Farkites Mar 25, 2024
7e2acfb
Remove focus in tests
Farkites Mar 25, 2024
1208283
Add zindex tests for bar traces
Farkites Mar 25, 2024
a9493d4
Fix index of layer names for negative zindex
Farkites Mar 25, 2024
eabedd8
Add overlaying bar traces to zindex_basic mock
Farkites Mar 25, 2024
2391afd
Extend zindex test to waterfall and funnel traces
Farkites Mar 25, 2024
efcd49f
rename zindex to zorder
archmoj Apr 9, 2024
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/6918_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add a new attribute `zindex` to SVG based Cartesian traces (not to WebGL traces). Traces with higher `zindex` values are drawn in front of traces with lower `zindex` values. This feature was anonymously sponsored: thank you to our sponsor!
86 changes: 55 additions & 31 deletions src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,27 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
var calcdata = gd.calcdata;
var i;

// 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
// which are in calcdata.

if(!Array.isArray(traces)) {
// If traces is not provided, then it's a complete replot and missing
// traces are removed
traces = [];
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 for this 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;
Expand Down Expand Up @@ -178,7 +184,7 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
pcd = cd;
}
}

// Plot the traces for this subplot
plotOne(gd, subplotInfo, cdSubplot, transitionOpts, makeOnCompleteCallback);
}
};
Expand All @@ -189,41 +195,60 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
var modules = fullLayout._modules;
var _module, cdModuleAndOthers, cdModule;

// Separate traces by zindex and plot each zindex group separately
// TODO: Performance
archmoj marked this conversation as resolved.
Show resolved Hide resolved
var traceZindexGroups = {};
for(var t = 0; t < cdSubplot.length; t++) {
var trace = cdSubplot[t][0].trace;
var zi = trace.zindex || 0;
if(!traceZindexGroups[zi]) traceZindexGroups[zi] = [];
traceZindexGroups[zi].push(cdSubplot[t]);
}

var layerData = [];
var zoomScaleQueryParts = [];

for(var i = 0; i < modules.length; i++) {
_module = modules[i];
var name = _module.name;
var categories = Registry.modules[name].categories;

if(categories.svg) {
var className = (_module.layerName || name + 'layer');
var plotMethod = _module.plot;

// plot all visible traces of this type on this subplot at once
cdModuleAndOthers = getModuleCalcData(cdSubplot, plotMethod);
cdModule = cdModuleAndOthers[0];
// don't need to search the found traces again - in fact we need to NOT
// so that if two modules share the same plotter we don't double-plot
cdSubplot = cdModuleAndOthers[1];

if(cdModule.length) {
layerData.push({
i: traceLayerClasses.indexOf(className),
className: className,
plotMethod: plotMethod,
cdModule: cdModule
});
}
// Plot each zindex group in ascending order
var zindices = Object.keys(traceZindexGroups)
.map(Number)
archmoj marked this conversation as resolved.
Show resolved Hide resolved
.sort(Lib.sorterAsc);
for(var z = 0; z < zindices.length; z++) {
var zindex = zindices[z];
// For each "module" (trace type)
for(var i = 0; i < modules.length; i++) {
_module = modules[i];
var name = _module.name;
var categories = Registry.modules[name].categories;

if(categories.svg) {
var className = (_module.layerName || name + 'layer') + (zindex ? '-' + z : '');
Farkites marked this conversation as resolved.
Show resolved Hide resolved
var plotMethod = _module.plot;

// plot all visible traces of this type on this subplot at once
cdModuleAndOthers = getModuleCalcData(cdSubplot, plotMethod, zindex);
cdModule = cdModuleAndOthers[0];
// don't need to search the found traces again - in fact we need to NOT
// so that if two modules share the same plotter we don't double-plot
cdSubplot = cdModuleAndOthers[1];

if(cdModule.length) {
layerData.push({
i: traceLayerClasses.indexOf(className),
zindex: z,
className: className,
plotMethod: plotMethod,
cdModule: cdModule
});
}

if(categories.zoomScale) {
zoomScaleQueryParts.push('.' + className);
if(categories.zoomScale) {
zoomScaleQueryParts.push('.' + className);
}
}
}
}

layerData.sort(function(a, b) { return a.i - b.i; });
// Sort the layers primarily by z, then by i
layerData.sort(function(a, b) { return (a.zindex || 0) - (b.zindex || 0) || a.i - b.i; });

var layers = plotinfo.plot.selectAll('g.mlayer')
.data(layerData, function(d) { return d.className; });
Expand Down Expand Up @@ -434,7 +459,6 @@ function makeSubplotData(gd) {
}
subplotData[i] = d;
}

return subplotData;
}

Expand Down
8 changes: 5 additions & 3 deletions src/plots/get_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ exports.getSubplotCalcData = function(calcData, type, subplotId) {
* @param {array} calcdata: as in gd.calcdata
* @param {object|string|fn} arg1:
* the plotting module, or its name, or its plot method
*
* @param {int} arg2: (optional) zindex to filter on
* @return {array[array]} [foundCalcdata, remainingCalcdata]
*/
exports.getModuleCalcData = function(calcdata, arg1) {
exports.getModuleCalcData = function(calcdata, arg1, arg2) {
var moduleCalcData = [];
var remainingCalcData = [];

Expand All @@ -57,10 +57,12 @@ exports.getModuleCalcData = function(calcdata, arg1) {
if(!plotMethod) {
return [moduleCalcData, calcdata];
}
var zindex = arg2;

for(var i = 0; i < calcdata.length; i++) {
var cd = calcdata[i];
var trace = cd[0].trace;
var filterByZ = (trace.zindex !== undefined);
// N.B.
// - 'legendonly' traces do not make it past here
// - skip over 'visible' traces that got trimmed completely during calc transforms
Expand All @@ -70,7 +72,7 @@ exports.getModuleCalcData = function(calcdata, arg1) {
// would suggest), but by 'module plot method' so that if some traces
// share the same module plot method (e.g. bar and histogram), we
// only call it one!
if(trace._module && trace._module.plot === plotMethod) {
if(trace._module && trace._module.plot === plotMethod && (!filterByZ || trace.zindex === zindex)) {
moduleCalcData.push(cd);
} else {
remainingCalcData.push(cd);
Expand Down
1 change: 1 addition & 0 deletions src/traces/bar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ module.exports = {
textfont: scatterAttrs.unselected.textfont,
editType: 'style'
},
zindex: scatterAttrs.zindex,

_deprecated: {
bardir: {
Expand Down
2 changes: 2 additions & 0 deletions src/traces/bar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
coerce('xhoverformat');
coerce('yhoverformat');

coerce('zindex');

coerce('orientation', (traceOut.x && !traceOut.y) ? 'h' : 'v');
coerce('base');
coerce('offset');
Expand Down
2 changes: 1 addition & 1 deletion src/traces/bar/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var attributeOutsideTextFont = attributes.outsidetextfont;
var helpers = require('./helpers');

function style(gd) {
var s = d3.select(gd).selectAll('g.barlayer').selectAll('g.trace');
var s = d3.select(gd).selectAll('g[class^="barlayer"]').selectAll('g.trace');
archmoj marked this conversation as resolved.
Show resolved Hide resolved
resizeText(gd, s, 'bar');

var barcount = s.size();
Expand Down
3 changes: 2 additions & 1 deletion src/traces/box/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,5 +451,6 @@ module.exports = {
'Do the hover effects highlight individual boxes ',
'or sample points or both?'
].join(' ')
}
},
zindex: scatterAttrs.zindex
};
1 change: 1 addition & 0 deletions src/traces/box/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
if(notched) coerce('notchwidth');

handlePointsDefaults(traceIn, traceOut, coerce, {prefix: 'box'});
coerce('zindex');
}

function handleSampleDefaults(traceIn, traceOut, coerce, layout) {
Expand Down
2 changes: 2 additions & 0 deletions src/traces/candlestick/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var extendFlat = require('../../lib').extendFlat;
var axisHoverFormat = require('../../plots/cartesian/axis_format_attributes').axisHoverFormat;
var OHLCattrs = require('../ohlc/attributes');
var boxAttrs = require('../box/attributes');
var scatterAttrs = require('../scatter/attributes');

function directionAttrs(lineColorDefault) {
return {
Expand Down Expand Up @@ -53,4 +54,5 @@ module.exports = {
whiskerwidth: extendFlat({}, boxAttrs.whiskerwidth, { dflt: 0 }),

hoverlabel: OHLCattrs.hoverlabel,
zindex: scatterAttrs.zindex
};
1 change: 1 addition & 0 deletions src/traces/candlestick/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('whiskerwidth');

layout._requestRangeslider[traceOut.xaxis] = true;
coerce('zindex');
};

function handleDirection(traceIn, traceOut, coerce, direction) {
Expand Down
6 changes: 5 additions & 1 deletion src/traces/carpet/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ var carpetFont = fontAttrs({
editType: 'calc',
description: 'The default font used for axis & tick labels on this carpet'
});

var scatterAttrs = require('../scatter/attributes');
archmoj marked this conversation as resolved.
Show resolved Hide resolved

// TODO: inherit from global font
carpetFont.family.dflt = '"Open Sans", verdana, arial, sans-serif';
carpetFont.size.dflt = 12;
Expand Down Expand Up @@ -112,5 +115,6 @@ module.exports = {
'Individual pieces can override this.'
].join(' ')
},
transforms: undefined
transforms: undefined,
zindex: scatterAttrs.zindex
archmoj marked this conversation as resolved.
Show resolved Hide resolved
};
1 change: 1 addition & 0 deletions src/traces/carpet/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ module.exports = function supplyDefaults(traceIn, traceOut, dfltColor, fullLayou
if(traceOut._cheater) {
coerce('cheaterslope');
}
coerce('zindex');
};
3 changes: 2 additions & 1 deletion src/traces/contour/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ module.exports = extendFlat({
].join(' ')
}),
editType: 'plot'
}
},
zindex: scatterAttrs.zindex
},
colorScaleAttrs('', {
cLetter: 'z',
Expand Down
1 change: 1 addition & 0 deletions src/traces/contour/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
) {
handleHeatmapLabelDefaults(coerce, layout);
}
coerce('zindex');
};
4 changes: 3 additions & 1 deletion src/traces/contourcarpet/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var heatmapAttrs = require('../heatmap/attributes');
var contourAttrs = require('../contour/attributes');
var scatterAttrs = require('../scatter/attributes');
archmoj marked this conversation as resolved.
Show resolved Hide resolved
var colorScaleAttrs = require('../../components/colorscale/attributes');

var extendFlat = require('../../lib/extend').extendFlat;
Expand Down Expand Up @@ -70,7 +71,8 @@ module.exports = extendFlat({
editType: 'plot'
},

transforms: undefined
transforms: undefined,
zindex: scatterAttrs.zindex
archmoj marked this conversation as resolved.
Show resolved Hide resolved
},

colorScaleAttrs('', {
Expand Down
1 change: 1 addition & 0 deletions src/traces/contourcarpet/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
traceOut._defaultColor = defaultColor;
traceOut._length = null;
}
coerce('zindex');
};
4 changes: 3 additions & 1 deletion src/traces/funnel/attributes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var barAttrs = require('../bar/attributes');
var scatterAttrs = require('../scatter/attributes');
archmoj marked this conversation as resolved.
Show resolved Hide resolved
var lineAttrs = require('../scatter/attributes').line;
var baseAttrs = require('../../plots/attributes');
var axisHoverFormat = require('../../plots/cartesian/axis_format_attributes').axisHoverFormat;
Expand Down Expand Up @@ -109,7 +110,8 @@ module.exports = {
},

offsetgroup: barAttrs.offsetgroup,
alignmentgroup: barAttrs.alignmentgroup
alignmentgroup: barAttrs.alignmentgroup,
zindex: scatterAttrs.zindex
archmoj marked this conversation as resolved.
Show resolved Hide resolved
};

function funnelMarker() {
Expand Down
1 change: 1 addition & 0 deletions src/traces/funnel/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
coerce('connector.line.dash');
}
}
coerce('zindex');
}

function defaultFillColor(markerColor) {
Expand Down
2 changes: 1 addition & 1 deletion src/traces/funnel/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var resizeText = require('../bar/uniform_text').resizeText;
var styleTextPoints = barStyle.styleTextPoints;

function style(gd, cd, sel) {
var s = sel ? sel : d3.select(gd).selectAll('g.funnellayer').selectAll('g.trace');
var s = sel ? sel : d3.select(gd).selectAll('g[class^="funnellayer"]').selectAll('g.trace');
resizeText(gd, s, 'funnel');

s.style('opacity', function(d) { return d[0].trace.opacity; });
Expand Down
3 changes: 2 additions & 1 deletion src/traces/heatmap/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ module.exports = extendFlat({
description: 'Sets the text font.'
}),

showlegend: extendFlat({}, baseAttrs.showlegend, {dflt: false})
showlegend: extendFlat({}, baseAttrs.showlegend, {dflt: false}),
zindex: scatterAttrs.zindex
}, {
transforms: undefined
},
Expand Down
1 change: 1 addition & 0 deletions src/traces/heatmap/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('connectgaps', Lib.isArray1D(traceOut.z) && (traceOut.zsmooth !== false));

colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});
coerce('zindex');
};
4 changes: 3 additions & 1 deletion src/traces/image/attributes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var baseAttrs = require('../../plots/attributes');
var scatterAttrs = require('../scatter/attributes');
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
var extendFlat = require('../../lib/extend').extendFlat;
var colormodel = require('./constants').colormodel;
Expand Down Expand Up @@ -133,5 +134,6 @@ module.exports = extendFlat({
keys: ['z', 'color', 'colormodel']
}),

transforms: undefined
transforms: undefined,
zindex: scatterAttrs.zindex
archmoj marked this conversation as resolved.
Show resolved Hide resolved
});
2 changes: 2 additions & 0 deletions src/traces/image/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ module.exports = function supplyDefaults(traceIn, traceOut) {
coerce('hovertemplate');

traceOut._length = null;

coerce('zindex');
};
2 changes: 2 additions & 0 deletions src/traces/ohlc/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,6 @@ module.exports = {
].join(' ')
}
}),

zindex: scatterAttrs.zindex
};
2 changes: 2 additions & 0 deletions src/traces/ohlc/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('tickwidth');

layout._requestRangeslider[traceOut.xaxis] = true;

coerce('zindex');
};

function handleDirection(traceIn, traceOut, coerce, direction) {
Expand Down
Loading