Skip to content

Commit bf78539

Browse files
committed
responsive handler: do not resize if gd is hidden
1 parent 795220f commit bf78539

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/plot_api/plot_api.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,15 @@ function plot(gd, data, layout, config) {
178178
gd.calcdata[i][0].trace = gd._fullData[i];
179179
}
180180

181+
function isHidden(gd) {
182+
var display = window.getComputedStyle(gd).display;
183+
return !display || display === 'none';
184+
}
181185
// make the figure responsive
182186
if(gd._context.responsive) {
183187
if(!gd._responsiveChartHandler) {
184188
// Keep a reference to the resize handler to purge it down the road
185-
gd._responsiveChartHandler = function() { Plots.resize(gd); };
189+
gd._responsiveChartHandler = function() { if(!isHidden(gd)) Plots.resize(gd).catch(Lib.noop); };
186190

187191
// Listen to window resize
188192
window.addEventListener('resize', gd._responsiveChartHandler);

test/jasmine/tests/config_test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,23 @@ describe('config argument', function() {
771771
.catch(failTest)
772772
.then(done);
773773
});
774+
775+
it('should not resize if gd is hidden', function(done) {
776+
spyOn(Plotly.Plots, 'resize').and.callThrough();
777+
778+
fillParent(1, 1);
779+
Plotly.plot(gd, data, {}, {responsive: true})
780+
.then(function() {
781+
gd.style.display = 'none';
782+
viewport.set(width / 2, height / 2);
783+
})
784+
.then(delay(RESIZE_DELAY))
785+
.then(function() {
786+
expect(Plotly.Plots.resize.calls.count()).toBe(0);
787+
})
788+
.catch(failTest)
789+
.then(done);
790+
});
774791
});
775792
});
776793

0 commit comments

Comments
 (0)