Skip to content

Commit e3d947e

Browse files
committed
replot when webgl buffer dims don't match canvas dims
- this can happen when relayouting to large width/height on some browsers (e.g. Chrome 68)
1 parent b5f8b23 commit e3d947e

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/plot_api/plot_api.js

+18
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,24 @@ exports.plot = function(gd, data, layout, config) {
242242
fullLayout._glcanvas
243243
.attr('width', fullLayout.width)
244244
.attr('height', fullLayout.height);
245+
246+
247+
var regl = fullLayout._glcanvas.data()[0].regl;
248+
if(regl) {
249+
if(
250+
fullLayout.width !== regl._gl.drawingBufferWidth ||
251+
fullLayout.height !== regl._gl.drawingBufferHeight
252+
) {
253+
// Unfortunately, this can happen when relayouting to large
254+
// width/height on some browsers.
255+
Lib.log([
256+
'WebGL context buffer and canvas dimensions do not match,',
257+
'due to browser/WebGL bug.',
258+
'Clearing graph and plotting again.'
259+
].join(' '));
260+
exports.newPlot(gd, gd.data, gd.layout);
261+
}
262+
}
245263
}
246264

247265
return Plots.previousPromises(gd);

test/jasmine/tests/splom_test.js

+34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var Plotly = require('@lib');
22
var Lib = require('@src/lib');
33
var Plots = require('@src/plots/plots');
4+
var plotApi = require('@src/plot_api/plot_api');
45
var SUBPLOT_PATTERN = require('@src/plots/cartesian/constants').SUBPLOT_PATTERN;
56

67
var d3 = require('d3');
@@ -682,6 +683,39 @@ describe('Test splom interactions:', function() {
682683
.catch(failTest)
683684
.then(done);
684685
});
686+
687+
it('@gl should clear graph and replot when canvas and WebGL context dimensions do not match', function(done) {
688+
var fig = Lib.extendDeep({}, require('@mocks/splom_iris.json'));
689+
690+
function assertDims(msg, w, h) {
691+
var canvas = gd._fullLayout._glcanvas;
692+
expect(canvas.node().width).toBe(w, msg);
693+
expect(canvas.node().height).toBe(h, msg);
694+
695+
var gl = canvas.data()[0].regl._gl;
696+
expect(gl.drawingBufferWidth).toBe(w, msg);
697+
expect(gl.drawingBufferHeight).toBe(h, msg);
698+
}
699+
700+
spyOn(plotApi, 'newPlot').and.callThrough();
701+
spyOn(Lib, 'log');
702+
703+
Plotly.plot(gd, fig).then(function() {
704+
expect(plotApi.newPlot).toHaveBeenCalledTimes(0);
705+
expect(Lib.log).toHaveBeenCalledTimes(0);
706+
assertDims('base', 600, 500);
707+
708+
return Plotly.relayout(gd, {width: 4810, height: 3656});
709+
})
710+
.then(function() {
711+
expect(plotApi.newPlot).toHaveBeenCalledTimes(1);
712+
expect(Lib.log)
713+
.toHaveBeenCalledWith('WebGL context buffer and canvas dimensions do not match, due to browser/WebGL bug. Clearing graph and plotting again.');
714+
assertDims('base', 4810, 3656);
715+
})
716+
.catch(failTest)
717+
.then(done);
718+
});
685719
});
686720

687721
describe('Test splom hover:', function() {

0 commit comments

Comments
 (0)