diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index d3224a9dd12..dfc66dd9868 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -261,8 +261,8 @@ exports.plot = function(gd, data, layout, config) { if(regl) { // Unfortunately, this can happen when relayouting to large // width/height on some browsers. - if(fullLayout.width !== regl._gl.drawingBufferWidth || - fullLayout.height !== regl._gl.drawingBufferHeight + if(Math.floor(fullLayout.width) !== regl._gl.drawingBufferWidth || + Math.floor(fullLayout.height) !== regl._gl.drawingBufferHeight ) { var msg = 'WebGL context buffer and canvas dimensions do not match due to browser/WebGL bug.'; if(drawFrameworkCalls) { diff --git a/src/traces/scattergl/index.js b/src/traces/scattergl/index.js index c3068932a5b..a0826e655bf 100644 --- a/src/traces/scattergl/index.js +++ b/src/traces/scattergl/index.js @@ -295,13 +295,15 @@ function sceneUpdate(gd, subplot) { // remove scene resources scene.destroy = function destroy() { - if(scene.fill2d) scene.fill2d.destroy(); - if(scene.scatter2d) scene.scatter2d.destroy(); - if(scene.error2d) scene.error2d.destroy(); - if(scene.line2d) scene.line2d.destroy(); - if(scene.select2d) scene.select2d.destroy(); + if(scene.fill2d && scene.fill2d.destroy) scene.fill2d.destroy(); + if(scene.scatter2d && scene.scatter2d.destroy) scene.scatter2d.destroy(); + if(scene.error2d && scene.error2d.destroy) scene.error2d.destroy(); + if(scene.line2d && scene.line2d.destroy) scene.line2d.destroy(); + if(scene.select2d && scene.select2d.destroy) scene.select2d.destroy(); if(scene.glText) { - scene.glText.forEach(function(text) { text.destroy(); }); + scene.glText.forEach(function(text) { + if(text.destroy) text.destroy(); + }); } scene.lineOptions = null; diff --git a/test/jasmine/tests/gl2d_plot_interact_test.js b/test/jasmine/tests/gl2d_plot_interact_test.js index aa01c2a671a..e80d9606352 100644 --- a/test/jasmine/tests/gl2d_plot_interact_test.js +++ b/test/jasmine/tests/gl2d_plot_interact_test.js @@ -261,6 +261,57 @@ describe('Test gl plot side effects', function() { .catch(failTest) .then(done); }); + + it('@gl should not clear context when dimensions are not integers', function(done) { + spyOn(Plots, 'cleanPlot').and.callThrough(); + spyOn(Lib, 'log').and.callThrough(); + + var w = 500.5; + var h = 400.5; + var w0 = Math.floor(w); + var h0 = Math.floor(h); + + function assertDims(msg) { + var fullLayout = gd._fullLayout; + expect(fullLayout.width).toBe(w, msg); + expect(fullLayout.height).toBe(h, msg); + + var canvas = fullLayout._glcanvas; + expect(canvas.node().width).toBe(w0, msg); + expect(canvas.node().height).toBe(h0, msg); + + var gl = canvas.data()[0].regl._gl; + expect(gl.drawingBufferWidth).toBe(w0, msg); + expect(gl.drawingBufferHeight).toBe(h0, msg); + } + + Plotly.plot(gd, [{ + type: 'scattergl', + mode: 'lines', + y: [1, 2, 1] + }], { + width: w, + height: h + }) + .then(function() { + assertDims('base state'); + + // once from supplyDefaults + expect(Plots.cleanPlot).toHaveBeenCalledTimes(1); + expect(Lib.log).toHaveBeenCalledTimes(0); + + return Plotly.restyle(gd, 'mode', 'markers'); + }) + .then(function() { + assertDims('after restyle'); + + // one more supplyDefaults + expect(Plots.cleanPlot).toHaveBeenCalledTimes(2); + expect(Lib.log).toHaveBeenCalledTimes(0); + }) + .catch(failTest) + .then(done); + }); }); describe('Test gl2d plots', function() {