Skip to content

fix plotinfo when mainplot is no longer linked #2516

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

Merged
merged 2 commits into from
Apr 3, 2018
Merged
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 src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
@@ -372,6 +372,7 @@ function makeSubplotData(gd) {
overlays.push(k);
} else {
subplotData.push(k);
plotinfo.mainplot = undefined;
}
}

78 changes: 60 additions & 18 deletions test/jasmine/tests/cartesian_test.js
Original file line number Diff line number Diff line change
@@ -450,25 +450,67 @@ describe('subplot creation / deletion:', function() {
.then(done);
});

it('puts plot backgrounds behind everything except if they overlap', function(done) {
function checkBGLayers(behindCount, x2y2Count) {
expect(gd.querySelectorAll('.bglayer rect.bg').length).toBe(behindCount);
expect(gd.querySelectorAll('.subplot.x2y2 rect.bg').length).toBe(x2y2Count);
function checkBGLayers(behindCount, x2y2Count, subplots) {
expect(gd.querySelectorAll('.bglayer rect.bg').length).toBe(behindCount);
expect(gd.querySelectorAll('.subplot.x2y2 rect.bg').length).toBe(x2y2Count);

// xy is the first subplot, so it never gets put in front of others
expect(gd.querySelectorAll('.subplot.xy rect.bg').length).toBe(0);

// xy is the first subplot, so it never gets put in front of others
expect(gd.querySelectorAll('.subplot.xy rect.bg').length).toBe(0);
// xy3 is an overlay, so never gets its own bg
expect(gd.querySelectorAll('.subplot.xy3 rect.bg').length).toBe(0);

// verify that these are *all* the subplots and backgrounds we have
expect(gd.querySelectorAll('.subplot').length).toBe(subplots.length);
subplots.forEach(function(subplot) {
expect(gd.querySelectorAll('.subplot.' + subplot).length).toBe(1);
});
expect(gd.querySelectorAll('.bg').length).toBe(behindCount + x2y2Count);
}

// xy3 is an overlay, so never gets its own bg
expect(gd.querySelectorAll('.subplot.xy3 rect.bg').length).toBe(0);
it('makes new backgrounds when switching between overlaying and separate subplots', function(done) {
Plotly.newPlot(gd, [
{x: [1], y: [2]},
{x: [3], y: [4], xaxis: 'x2', yaxis: 'y2'}
], {
xaxis2: {overlaying: 'x'},
yaxis2: {overlaying: 'y'},
plot_bgcolor: 'red',
showlegend: false
})
.then(function() {
checkBGLayers(1, 0, ['xy', 'x2y2']);

// verify that these are *all* the subplots and backgrounds we have
expect(gd.querySelectorAll('.subplot').length).toBe(3);
['xy', 'x2y2', 'xy3'].forEach(function(subplot) {
expect(gd.querySelectorAll('.subplot.' + subplot).length).toBe(1);
return Plotly.relayout(gd, {
'xaxis.domain': [0, 0.4],
'xaxis2.domain': [0.6, 1],
'xaxis2.overlaying': null
});
expect(gd.querySelectorAll('.bg').length).toBe(behindCount + x2y2Count);
}
})
.then(function() {
checkBGLayers(2, 0, ['xy', 'x2y2']);

return Plotly.relayout(gd, {
'xaxis2.overlaying': 'x'
});
})
.then(function() {
checkBGLayers(1, 0, ['xy', 'x2y2']);

return Plotly.relayout(gd, {
'xaxis.domain': [0, 0.6],
'xaxis2.domain': [0.4, 1],
'xaxis2.overlaying': null
});
})
.then(function() {
checkBGLayers(1, 1, ['xy', 'x2y2']);
})
.catch(failTest)
.then(done);
});

it('puts plot backgrounds behind everything except if they overlap', function(done) {
Plotly.plot(gd, [
{y: [1, 2, 3]},
{y: [2, 3, 1], xaxis: 'x2', yaxis: 'y2'},
@@ -484,19 +526,19 @@ describe('subplot creation / deletion:', function() {
})
.then(function() {
// touching but not overlapping: all backgrounds are in back
checkBGLayers(2, 0);
checkBGLayers(2, 0, ['xy', 'x2y2', 'xy3']);

// now add a slight overlap: that's enough to put x2y2 in front
return Plotly.relayout(gd, {'xaxis2.domain': [0.49, 1]});
})
.then(function() {
checkBGLayers(1, 1);
checkBGLayers(1, 1, ['xy', 'x2y2', 'xy3']);

// x ranges overlap, but now y ranges are disjoint
return Plotly.relayout(gd, {'xaxis2.domain': [0, 1], 'yaxis.domain': [0, 0.5]});
})
.then(function() {
checkBGLayers(2, 0);
checkBGLayers(2, 0, ['xy', 'x2y2', 'xy3']);

// regular inset
return Plotly.relayout(gd, {
@@ -507,7 +549,7 @@ describe('subplot creation / deletion:', function() {
});
})
.then(function() {
checkBGLayers(1, 1);
checkBGLayers(1, 1, ['xy', 'x2y2', 'xy3']);
})
.catch(failTest)
.then(done);