Skip to content

Commit 8619939

Browse files
authored
Merge pull request plotly#6962 from plotly/fix6955-zorder
Maintain original drawing order of traces when traces with similar type are sent to back
2 parents 1b609e0 + f3f1090 commit 8619939

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

draftlogs/6962_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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)]

src/plots/cartesian/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
221221
var categories = Registry.modules[name].categories;
222222

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

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

234235
if(cdModule.length) {
235236
layerData.push({
236-
i: traceLayerClasses.indexOf(className),
237+
i: traceLayerClasses.indexOf(classBaseName),
237238
zorder: z,
238239
className: className,
239240
plotMethod: plotMethod,
@@ -248,7 +249,12 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
248249
}
249250
}
250251
// Sort the layers primarily by z, then by i
251-
layerData.sort(function(a, b) { return (a.zorder || 0) - (b.zorder || 0) || a.i - b.i; });
252+
layerData.sort(function(a, b) {
253+
return (
254+
(a.zorder || 0) - (b.zorder || 0) ||
255+
(a.i - b.i)
256+
);
257+
});
252258

253259
var layers = plotinfo.plot.selectAll('g.mlayer')
254260
.data(layerData, function(d) { return d.className; });
Loading
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"data": [
3+
{
4+
"marker": {
5+
"size": 10
6+
},
7+
"mode": "markers",
8+
"name": "scatter",
9+
"type": "scatter",
10+
"x": [
11+
1,
12+
2,
13+
3,
14+
4,
15+
5
16+
],
17+
"y": [
18+
2,
19+
1,
20+
6,
21+
4,
22+
4
23+
]
24+
},
25+
{
26+
"name": "bar",
27+
"type": "bar",
28+
"x": [
29+
1,
30+
2,
31+
3,
32+
4,
33+
5
34+
],
35+
"y": [
36+
1,
37+
6,
38+
3,
39+
6,
40+
1
41+
]
42+
},
43+
{
44+
"mode": "lines",
45+
"name": "line",
46+
"type": "scatter",
47+
"x": [
48+
1,
49+
2,
50+
3,
51+
4,
52+
5
53+
],
54+
"y": [
55+
2,
56+
3,
57+
4,
58+
3,
59+
2
60+
],
61+
"zorder": -1
62+
}
63+
],
64+
"layout": {
65+
"width": 350,
66+
"height": 350,
67+
"title": {
68+
"text": "Move line plot to back only"
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)