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

Maintain original drawing order of traces when traces with similar type are sent to back #6962

Merged
merged 3 commits into from
Apr 12, 2024
Merged
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/6962_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Maintain original drawing order of traces when traces with similar type are sent to back [[#6962](https://github.com/plotly/plotly.js/pull/6962)]
12 changes: 9 additions & 3 deletions src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
var categories = Registry.modules[name].categories;

if(categories.svg) {
var className = (_module.layerName || name + 'layer') + (z ? Number(z) + 1 : '');
var classBaseName = (_module.layerName || name + 'layer');
var className = classBaseName + (z ? Number(z) + 1 : '');
var plotMethod = _module.plot;

// plot all visible traces of this type on this subplot at once
Expand All @@ -233,7 +234,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback

if(cdModule.length) {
layerData.push({
i: traceLayerClasses.indexOf(className),
i: traceLayerClasses.indexOf(classBaseName),
zorder: z,
className: className,
plotMethod: plotMethod,
Expand All @@ -248,7 +249,12 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
}
}
// Sort the layers primarily by z, then by i
layerData.sort(function(a, b) { return (a.zorder || 0) - (b.zorder || 0) || a.i - b.i; });
layerData.sort(function(a, b) {
return (
(a.zorder || 0) - (b.zorder || 0) ||
(a.i - b.i)
);
});

var layers = plotinfo.plot.selectAll('g.mlayer')
.data(layerData, function(d) { return d.className; });
Expand Down
Binary file added test/image/baselines/zz-zorder_default-orders.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions test/image/mocks/zz-zorder_default-orders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"data": [
{
"marker": {
"size": 10
},
"mode": "markers",
"name": "scatter",
"type": "scatter",
"x": [
1,
2,
3,
4,
5
],
"y": [
2,
1,
6,
4,
4
]
},
{
"name": "bar",
"type": "bar",
"x": [
1,
2,
3,
4,
5
],
"y": [
1,
6,
3,
6,
1
]
},
{
"mode": "lines",
"name": "line",
"type": "scatter",
"x": [
1,
2,
3,
4,
5
],
"y": [
2,
3,
4,
3,
2
],
"zorder": -1
}
],
"layout": {
"width": 350,
"height": 350,
"title": {
"text": "Move line plot to back only"
}
}
}