Skip to content

Commit 0c1d6d5

Browse files
authored
Merge pull request #2857 from plotly/yaxis-over-yaxis2
Fix 'yaxis-over-yaxis2' behavior
2 parents 28bc3e9 + ee2ac26 commit 0c1d6d5

File tree

3 files changed

+100
-7
lines changed

3 files changed

+100
-7
lines changed

src/plots/cartesian/index.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,12 @@ function makeSubplotData(gd) {
392392
var fullLayout = gd._fullLayout;
393393
var ids = fullLayout._subplots.cartesian;
394394
var len = ids.length;
395-
var subplotData = new Array(len);
396395
var i, j, id, plotinfo, xa, ya;
397396

397+
// split 'regular' and 'overlaying' subplots
398+
var regulars = [];
399+
var overlays = [];
400+
398401
for(i = 0; i < len; i++) {
399402
id = ids[i];
400403
plotinfo = fullLayout._plots[id];
@@ -408,25 +411,35 @@ function makeSubplotData(gd) {
408411
plotinfo.overlays = [];
409412

410413
if(mainplot !== id && mainplotinfo) {
411-
// link 'main plot' ref in overlaying plotinfo
412414
plotinfo.mainplot = mainplot;
413415
plotinfo.mainplotinfo = mainplotinfo;
414-
// fill in list of overlaying subplots in 'main plot'
415-
mainplotinfo.overlays.push(plotinfo);
416+
overlays.push(id);
416417
} else {
417418
plotinfo.mainplot = undefined;
418419
plotinfo.mainPlotinfo = undefined;
420+
regulars.push(id);
419421
}
420422
}
421423

422-
// use info about axis layer and overlaying pattern
423-
// to clean what need to be cleaned up in exit selection
424+
// fill in list of overlaying subplots in 'main plot'
425+
for(i = 0; i < overlays.length; i++) {
426+
id = overlays[i];
427+
plotinfo = fullLayout._plots[id];
428+
plotinfo.mainplotinfo.overlays.push(plotinfo);
429+
}
430+
431+
// put 'regular' subplot data before 'overlaying'
432+
var subplotIds = regulars.concat(overlays);
433+
var subplotData = new Array(len);
434+
424435
for(i = 0; i < len; i++) {
425-
id = ids[i];
436+
id = subplotIds[i];
426437
plotinfo = fullLayout._plots[id];
427438
xa = plotinfo.xaxis;
428439
ya = plotinfo.yaxis;
429440

441+
// use info about axis layer and overlaying pattern
442+
// to clean what need to be cleaned up in exit selection
430443
var d = [id, xa.layer, ya.layer, xa.overlaying || '', ya.overlaying || ''];
431444
for(j = 0; j < plotinfo.overlays.length; j++) {
432445
d.push(plotinfo.overlays[j].id);
25 KB
Loading
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"data": [
3+
{
4+
"x": [
5+
"2018-05-09 11:33:32.330",
6+
"2018-05-09 11:33:32.367",
7+
"2018-05-09 11:33:32.367",
8+
"2018-05-09 11:33:32.374",
9+
"2018-05-09 11:33:32.379"
10+
],
11+
"y": [
12+
1.2,
13+
1.3,
14+
1.1,
15+
1.4,
16+
0.9
17+
],
18+
"mode": "lines",
19+
"name": "Reference Bid",
20+
"line": {
21+
"shape": "hv",
22+
"dash": "solid"
23+
},
24+
"fill": "none"
25+
},
26+
{
27+
"x": [
28+
"2018-05-09 11:33:32.330",
29+
"2018-05-09 11:33:32.367",
30+
"2018-05-09 11:33:32.367",
31+
"2018-05-09 11:33:32.374",
32+
"2018-05-09 11:33:32.379"
33+
],
34+
"y": [
35+
0,
36+
0.2,
37+
0.4,
38+
0.6,
39+
1
40+
],
41+
"mode": "lines",
42+
"name": "y2",
43+
"yaxis": "y2",
44+
"line": {
45+
"shape": "vh",
46+
"dash": "solid"
47+
},
48+
"fill": "tozeroy",
49+
"marker": {
50+
"color": "rgba(168, 216, 234, 0.5)"
51+
}
52+
}
53+
],
54+
"layout": {
55+
"margin": {
56+
"b": 100,
57+
"l": 120,
58+
"t": 25,
59+
"r": 10,
60+
"pad": 10
61+
},
62+
"xaxis": {
63+
"title": "x1"
64+
},
65+
"yaxis": {
66+
"title": "y1",
67+
"overlaying": "y2"
68+
},
69+
"yaxis2": {
70+
"side": "right",
71+
"title": "y2"
72+
},
73+
"legend": {
74+
"x": 1.1,
75+
"y": 1
76+
},
77+
"hovermode": "closest",
78+
"dragmode": "zoom"
79+
}
80+
}

0 commit comments

Comments
 (0)