Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to enable switching modes using plotly react method on scattergl traces #3132

Merged
merged 6 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 8 additions & 6 deletions src/traces/scattergl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 51 additions & 0 deletions test/jasmine/tests/gl2d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down