Skip to content

Replot when webgl buffer dims don't match canvas dims #2939

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

Merged
merged 4 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 22 additions & 0 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,28 @@ exports.plot = function(gd, data, layout, config) {
fullLayout._glcanvas
.attr('width', fullLayout.width)
.attr('height', fullLayout.height);

var regl = fullLayout._glcanvas.data()[0].regl;
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
) {
var msg = 'WebGL context buffer and canvas dimensions do not match due to browser/WebGL bug.';
if(fullLayout._redrawFromWrongGlDimensions) {
Lib.error(msg);
} else {
Lib.log(msg + ' Clearing graph and plotting again.');
Plots.cleanPlot([], {}, gd._fullData, fullLayout, gd.calcdata);
Plots.supplyDefaults(gd);
fullLayout = gd._fullLayout;
Plots.doCalcdata(gd);
fullLayout._redrawFromWrongGlDimensions = 1;
return drawFramework();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Still a substantial win as we don't need to redo all the drawing.

So, there's still recursion here - but it's just back into this function. So instead of a _redrawFromWrongGlDimensions flag on _fullLayout (that we'd probably have to handle more carefully in principle due to relinkPrivateKeys) could we use a local var in the outer scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done in 3879a41

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one less private key to worry about when we'll 🔪 relinkPrivateKeys.

}
}
}
}

return Plots.previousPromises(gd);
Expand Down
55 changes: 55 additions & 0 deletions test/jasmine/tests/splom_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,61 @@ describe('Test splom interactions:', function() {
.catch(failTest)
.then(done);
});

it('@gl should clear graph and replot when canvas and WebGL context dimensions do not match', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/splom_iris.json'));

function assertDims(msg, w, h) {
var canvas = gd._fullLayout._glcanvas;
expect(canvas.node().width).toBe(w, msg);
expect(canvas.node().height).toBe(h, msg);

var gl = canvas.data()[0].regl._gl;
expect(gl.drawingBufferWidth).toBe(w, msg);
expect(gl.drawingBufferHeight).toBe(h, msg);
}

var methods = ['cleanPlot', 'supplyDefaults', 'doCalcdata'];

methods.forEach(function(m) { spyOn(Plots, m).and.callThrough(); });

function assetsFnCall(msg, exp) {
methods.forEach(function(m) {
expect(Plots[m]).toHaveBeenCalledTimes(exp[m], msg);
Plots[m].calls.reset();
});
}

spyOn(Lib, 'log');

Plotly.plot(gd, fig).then(function() {
assetsFnCall('base', {
cleanPlot: 1, // called once from inside Plots.supplyDefaults
supplyDefaults: 1,
doCalcdata: 1
});
assertDims('base', 600, 500);
expect(Lib.log).toHaveBeenCalledTimes(0);
expect(gd._fullLayout._redrawFromWrongGlDimensions).toBeUndefined();

spyOn(gd._fullData[0]._module, 'plot').and.callThrough();

return Plotly.relayout(gd, {width: 4810, height: 3656});
})
.then(function() {
assetsFnCall('after', {
cleanPlot: 4, // 3 three from supplyDefaults, once in drawFramework
supplyDefaults: 3, // 1 from relayout, 1 from automargin, 1 in drawFramework
doCalcdata: 1 // once in drawFramework
});
assertDims('after', 4810, 3656);
expect(Lib.log)
.toHaveBeenCalledWith('WebGL context buffer and canvas dimensions do not match due to browser/WebGL bug. Clearing graph and plotting again.');
expect(gd._fullLayout._redrawFromWrongGlDimensions).toBe(1);
})
.catch(failTest)
.then(done);
});
});

describe('Test splom hover:', function() {
Expand Down