Skip to content

Commit 06ae47d

Browse files
authored
Merge pull request #3132 from plotly/issue-2999
Fix to enable switching modes using plotly react method on scattergl traces
2 parents c10eb6f + 81e2dce commit 06ae47d

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

Diff for: src/plot_api/plot_api.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ exports.plot = function(gd, data, layout, config) {
261261
if(regl) {
262262
// Unfortunately, this can happen when relayouting to large
263263
// width/height on some browsers.
264-
if(fullLayout.width !== regl._gl.drawingBufferWidth ||
265-
fullLayout.height !== regl._gl.drawingBufferHeight
264+
if(Math.floor(fullLayout.width) !== regl._gl.drawingBufferWidth ||
265+
Math.floor(fullLayout.height) !== regl._gl.drawingBufferHeight
266266
) {
267267
var msg = 'WebGL context buffer and canvas dimensions do not match due to browser/WebGL bug.';
268268
if(drawFrameworkCalls) {

Diff for: src/traces/scattergl/index.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,15 @@ function sceneUpdate(gd, subplot) {
290290

291291
// remove scene resources
292292
scene.destroy = function destroy() {
293-
if(scene.fill2d) scene.fill2d.destroy();
294-
if(scene.scatter2d) scene.scatter2d.destroy();
295-
if(scene.error2d) scene.error2d.destroy();
296-
if(scene.line2d) scene.line2d.destroy();
297-
if(scene.select2d) scene.select2d.destroy();
293+
if(scene.fill2d && scene.fill2d.destroy) scene.fill2d.destroy();
294+
if(scene.scatter2d && scene.scatter2d.destroy) scene.scatter2d.destroy();
295+
if(scene.error2d && scene.error2d.destroy) scene.error2d.destroy();
296+
if(scene.line2d && scene.line2d.destroy) scene.line2d.destroy();
297+
if(scene.select2d && scene.select2d.destroy) scene.select2d.destroy();
298298
if(scene.glText) {
299-
scene.glText.forEach(function(text) { text.destroy(); });
299+
scene.glText.forEach(function(text) {
300+
if(text.destroy) text.destroy();
301+
});
300302
}
301303

302304
scene.lineOptions = null;

Diff for: test/jasmine/tests/gl2d_plot_interact_test.js

+51
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,57 @@ describe('Test gl plot side effects', function() {
261261
.catch(failTest)
262262
.then(done);
263263
});
264+
265+
it('@gl should not clear context when dimensions are not integers', function(done) {
266+
spyOn(Plots, 'cleanPlot').and.callThrough();
267+
spyOn(Lib, 'log').and.callThrough();
268+
269+
var w = 500.5;
270+
var h = 400.5;
271+
var w0 = Math.floor(w);
272+
var h0 = Math.floor(h);
273+
274+
function assertDims(msg) {
275+
var fullLayout = gd._fullLayout;
276+
expect(fullLayout.width).toBe(w, msg);
277+
expect(fullLayout.height).toBe(h, msg);
278+
279+
var canvas = fullLayout._glcanvas;
280+
expect(canvas.node().width).toBe(w0, msg);
281+
expect(canvas.node().height).toBe(h0, msg);
282+
283+
var gl = canvas.data()[0].regl._gl;
284+
expect(gl.drawingBufferWidth).toBe(w0, msg);
285+
expect(gl.drawingBufferHeight).toBe(h0, msg);
286+
}
287+
288+
Plotly.plot(gd, [{
289+
type: 'scattergl',
290+
mode: 'lines',
291+
y: [1, 2, 1]
292+
}], {
293+
width: w,
294+
height: h
295+
})
296+
.then(function() {
297+
assertDims('base state');
298+
299+
// once from supplyDefaults
300+
expect(Plots.cleanPlot).toHaveBeenCalledTimes(1);
301+
expect(Lib.log).toHaveBeenCalledTimes(0);
302+
303+
return Plotly.restyle(gd, 'mode', 'markers');
304+
})
305+
.then(function() {
306+
assertDims('after restyle');
307+
308+
// one more supplyDefaults
309+
expect(Plots.cleanPlot).toHaveBeenCalledTimes(2);
310+
expect(Lib.log).toHaveBeenCalledTimes(0);
311+
})
312+
.catch(failTest)
313+
.then(done);
314+
});
264315
});
265316

266317
describe('Test gl2d plots', function() {

0 commit comments

Comments
 (0)