Skip to content

Commit aaf6312

Browse files
committed
apply no-need-for-<rect.bg> optimization to all cartesian subplots
... but do draw <rect.bg> when either plot or paper bgcolor are semi-transparent.
1 parent 6de1ae4 commit aaf6312

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

src/plot_api/subroutines.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ function lsInner(gd) {
125125
// activate mode just for large splom (which benefit the most from this
126126
// optimization), but this could apply to all cartesian subplots.
127127
var noNeedForBg = (
128-
fullLayout._hasOnlyLargeSploms &&
128+
Color.opacity(fullLayout.paper_bgcolor) === 1 &&
129+
Color.opacity(fullLayout.plot_bgcolor) === 1 &&
129130
fullLayout.paper_bgcolor === fullLayout.plot_bgcolor
130131
);
131132

test/jasmine/assets/custom_assertions.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,6 @@ exports.assertElemInside = function(elem, container, msg) {
246246
* quick plot area dimension check: test width and/or height of the inner
247247
* plot area (single subplot) to verify that the margins are as expected
248248
*
249-
* Note: if you use margin.pad on the plot, width and height will be larger
250-
* than you expected by twice that padding.
251-
*
252249
* opts can have keys (all optional):
253250
* width (exact width match)
254251
* height (exact height match)
@@ -261,7 +258,7 @@ exports.assertPlotSize = function(opts, msg) {
261258
var widthLessThan = opts.widthLessThan;
262259
var heightLessThan = opts.heightLessThan;
263260

264-
var plotBB = d3.select('.bglayer .bg').node().getBoundingClientRect();
261+
var plotBB = d3.select('.plotclip > rect').node().getBoundingClientRect();
265262
var actualWidth = plotBB.width;
266263
var actualHeight = plotBB.height;
267264

test/jasmine/tests/cartesian_test.js

+70-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ describe('subplot creation / deletion:', function() {
520520
yaxis2: {domain: [0.5, 1], anchor: 'x2'},
521521
yaxis3: {overlaying: 'y'},
522522
// legend makes its own .bg rect - delete so we can ignore that here
523-
showlegend: false
523+
showlegend: false,
524+
plot_bgcolor: '#d3d3d3'
524525
})
525526
.then(function() {
526527
// touching but not overlapping: all backgrounds are in back
@@ -553,6 +554,74 @@ describe('subplot creation / deletion:', function() {
553554
.then(done);
554555
});
555556

557+
it('puts not have backgrounds nodes when plot and paper color match', function(done) {
558+
Plotly.plot(gd, [
559+
{y: [1, 2, 3]},
560+
{y: [2, 3, 1], xaxis: 'x2', yaxis: 'y2'},
561+
{y: [3, 1, 2], yaxis: 'y3'}
562+
], {
563+
xaxis: {domain: [0, 0.5]},
564+
xaxis2: {domain: [0.5, 1], anchor: 'y2'},
565+
yaxis: {domain: [0, 1]},
566+
yaxis2: {domain: [0.5, 1], anchor: 'x2'},
567+
yaxis3: {overlaying: 'y'},
568+
// legend makes its own .bg rect - delete so we can ignore that here
569+
showlegend: false,
570+
plot_bgcolor: 'white',
571+
paper_bgcolor: 'white'
572+
})
573+
.then(function() {
574+
// touching but not overlapping, matching colors -> no <rect.bg>
575+
checkBGLayers(0, 0, ['xy', 'x2y2', 'xy3']);
576+
577+
// now add a slight overlap: that's enough to put x2y2 in front
578+
return Plotly.relayout(gd, {'xaxis2.domain': [0.49, 1]});
579+
})
580+
.then(function() {
581+
// need to draw one backgroud <rect>
582+
checkBGLayers(0, 1, ['xy', 'x2y2', 'xy3']);
583+
584+
// x ranges overlap, but now y ranges are disjoint
585+
return Plotly.relayout(gd, {'xaxis2.domain': [0, 1], 'yaxis.domain': [0, 0.5]});
586+
})
587+
.then(function() {
588+
// disjoint, matching colors -> no <rect.bg>
589+
checkBGLayers(0, 0, ['xy', 'x2y2', 'xy3']);
590+
591+
// regular inset
592+
return Plotly.relayout(gd, {
593+
'xaxis.domain': [0, 1],
594+
'yaxis.domain': [0, 1],
595+
'xaxis2.domain': [0.6, 0.9],
596+
'yaxis2.domain': [0.6, 0.9]
597+
});
598+
})
599+
.then(function() {
600+
// need to draw one backgroud <rect>
601+
checkBGLayers(0, 1, ['xy', 'x2y2', 'xy3']);
602+
603+
// change paper color
604+
return Plotly.relayout(gd, 'paper_bgcolor', 'black');
605+
})
606+
.then(function() {
607+
// need a backgroud <rect> on main subplot to distinguish plot from
608+
// paper color
609+
checkBGLayers(1, 1, ['xy', 'x2y2', 'xy3']);
610+
611+
// change bg colors to same semi-transparent color
612+
return Plotly.relayout(gd, {
613+
'paper_bgcolor': 'rgba(255,0,0,0.2)',
614+
'plot_bgcolor': 'rgba(255,0,0,0.2)'
615+
});
616+
})
617+
.then(function() {
618+
// still need a <rect.bg> to get correct semi-transparent look
619+
checkBGLayers(1, 1, ['xy', 'x2y2', 'xy3']);
620+
})
621+
.catch(failTest)
622+
.then(done);
623+
});
624+
556625
it('should clear overlaid subplot trace layers on restyle', function(done) {
557626
var fig = Lib.extendDeep({}, require('@mocks/overlaying-axis-lines.json'));
558627

test/jasmine/tests/splom_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ describe('Test splom interactions:', function() {
588588
subplotCnt: 25,
589589
innerSubplotNodeCnt: 17,
590590
hasSplomGrid: false,
591-
bgCnt: 25
591+
bgCnt: 0
592592
});
593593

594594
// make sure 'new' subplot layers are in order

0 commit comments

Comments
 (0)