Skip to content

Commit

Permalink
Merge pull request #2857 from plotly/yaxis-over-yaxis2
Browse files Browse the repository at this point in the history
Fix 'yaxis-over-yaxis2' behavior
  • Loading branch information
etpinard authored Jul 30, 2018
2 parents 28bc3e9 + ee2ac26 commit 0c1d6d5
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,12 @@ function makeSubplotData(gd) {
var fullLayout = gd._fullLayout;
var ids = fullLayout._subplots.cartesian;
var len = ids.length;
var subplotData = new Array(len);
var i, j, id, plotinfo, xa, ya;

// split 'regular' and 'overlaying' subplots
var regulars = [];
var overlays = [];

for(i = 0; i < len; i++) {
id = ids[i];
plotinfo = fullLayout._plots[id];
Expand All @@ -408,25 +411,35 @@ function makeSubplotData(gd) {
plotinfo.overlays = [];

if(mainplot !== id && mainplotinfo) {
// link 'main plot' ref in overlaying plotinfo
plotinfo.mainplot = mainplot;
plotinfo.mainplotinfo = mainplotinfo;
// fill in list of overlaying subplots in 'main plot'
mainplotinfo.overlays.push(plotinfo);
overlays.push(id);
} else {
plotinfo.mainplot = undefined;
plotinfo.mainPlotinfo = undefined;
regulars.push(id);
}
}

// use info about axis layer and overlaying pattern
// to clean what need to be cleaned up in exit selection
// fill in list of overlaying subplots in 'main plot'
for(i = 0; i < overlays.length; i++) {
id = overlays[i];
plotinfo = fullLayout._plots[id];
plotinfo.mainplotinfo.overlays.push(plotinfo);
}

// put 'regular' subplot data before 'overlaying'
var subplotIds = regulars.concat(overlays);
var subplotData = new Array(len);

for(i = 0; i < len; i++) {
id = ids[i];
id = subplotIds[i];
plotinfo = fullLayout._plots[id];
xa = plotinfo.xaxis;
ya = plotinfo.yaxis;

// use info about axis layer and overlaying pattern
// to clean what need to be cleaned up in exit selection
var d = [id, xa.layer, ya.layer, xa.overlaying || '', ya.overlaying || ''];
for(j = 0; j < plotinfo.overlays.length; j++) {
d.push(plotinfo.overlays[j].id);
Expand Down
Binary file added test/image/baselines/yaxis-over-yaxis2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions test/image/mocks/yaxis-over-yaxis2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"data": [
{
"x": [
"2018-05-09 11:33:32.330",
"2018-05-09 11:33:32.367",
"2018-05-09 11:33:32.367",
"2018-05-09 11:33:32.374",
"2018-05-09 11:33:32.379"
],
"y": [
1.2,
1.3,
1.1,
1.4,
0.9
],
"mode": "lines",
"name": "Reference Bid",
"line": {
"shape": "hv",
"dash": "solid"
},
"fill": "none"
},
{
"x": [
"2018-05-09 11:33:32.330",
"2018-05-09 11:33:32.367",
"2018-05-09 11:33:32.367",
"2018-05-09 11:33:32.374",
"2018-05-09 11:33:32.379"
],
"y": [
0,
0.2,
0.4,
0.6,
1
],
"mode": "lines",
"name": "y2",
"yaxis": "y2",
"line": {
"shape": "vh",
"dash": "solid"
},
"fill": "tozeroy",
"marker": {
"color": "rgba(168, 216, 234, 0.5)"
}
}
],
"layout": {
"margin": {
"b": 100,
"l": 120,
"t": 25,
"r": 10,
"pad": 10
},
"xaxis": {
"title": "x1"
},
"yaxis": {
"title": "y1",
"overlaying": "y2"
},
"yaxis2": {
"side": "right",
"title": "y2"
},
"legend": {
"x": 1.1,
"y": 1
},
"hovermode": "closest",
"dragmode": "zoom"
}
}

0 comments on commit 0c1d6d5

Please sign in to comment.