Skip to content

Create two (not three) WebGL contexts for scattergl/splom graphs #2662

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 3 commits into from
May 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
6 changes: 5 additions & 1 deletion src/lib/prepare_regl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ var createRegl = require('regl');
* @param {array} extensions : list of extension to pass to createRegl
*/
module.exports = function prepareRegl(gd, extensions) {
gd._fullLayout._glcanvas.each(function(d) {
var fullLayout = gd._fullLayout;

fullLayout._glcanvas.each(function(d) {
if(d.regl) return;
// only parcoords needs pick layer
if(d.pick && !fullLayout._has('parcoords')) return;

d.regl = createRegl({
canvas: this,
Expand Down
54 changes: 34 additions & 20 deletions test/jasmine/tests/gl2d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var ScatterGl = require('@src/traces/scattergl');

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var fail = require('../assets/fail_test');
var failTest = require('../assets/fail_test');
var mouseEvent = require('../assets/mouse_event');
var touchEvent = require('../assets/touch_event');
var drag = require('../assets/drag');
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('@gl Test gl plot side effects', function() {
.then(function() {
expect(gd.querySelector('.gl-canvas-context').width).toBe(300);
})
.catch(fail)
.catch(failTest)
.then(done);
});
});
Expand Down Expand Up @@ -350,7 +350,7 @@ describe('@gl Test gl2d plots', function() {
'yaxis.range[1]': jasmine.any(Number)
}));
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -381,7 +381,7 @@ describe('@gl Test gl2d plots', function() {
.then(function() {
expect(readPixel(gd.querySelector('.gl-canvas-context'), 108, 100)[0]).not.toBe(0);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -423,7 +423,7 @@ describe('@gl Test gl2d plots', function() {
expect(scene.error2d.draw).toHaveBeenCalledTimes(2, 'twice for x AND y');
expect(scene.scatter2d.draw).toHaveBeenCalledTimes(3, 'both traces have markers');
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -451,7 +451,7 @@ describe('@gl Test gl2d plots', function() {
expect(readPixel(gd.querySelector('.gl-canvas-context'), 158, 100)[3]).not.toBe(0);
expect(readPixel(gd.querySelector('.gl-canvas-focus'), 168, 100)[3]).not.toBe(0);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -490,7 +490,7 @@ describe('@gl Test gl2d plots', function() {
expect(readPixel(gd.querySelector('.gl-canvas-context'), 158, 100)[3]).not.toBe(0);
expect(readPixel(gd.querySelector('.gl-canvas-focus'), 168, 100)[3]).not.toBe(0);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand All @@ -514,7 +514,7 @@ describe('@gl Test gl2d plots', function() {
expect(countCanvases()).toBe(0);
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(1);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -567,7 +567,7 @@ describe('@gl Test gl2d plots', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray([6, 8], 3);
expect(gd.layout.yaxis.range).toBeCloseToArray([5, 7], 3);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -634,7 +634,7 @@ describe('@gl Test gl2d plots', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray([-8.2, 24.2], 1);
expect(gd.layout.yaxis.range).toBeCloseToArray([-0.12, 16.1], 1);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -690,7 +690,7 @@ describe('@gl Test gl2d plots', function() {
.then(function() {
assertAnnotation([327, 331]);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -744,7 +744,7 @@ describe('@gl Test gl2d plots', function() {
expect(relayoutCallback).toHaveBeenCalledTimes(1);

})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand All @@ -768,7 +768,7 @@ describe('@gl Test gl2d plots', function() {
.then(function() {
expect(ScatterGl.calc).toHaveBeenCalledTimes(2);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -852,7 +852,7 @@ describe('@gl Test gl2d plots', function() {
expect(scene.selectBatch).toBe(null, msg);
expect(scene.unselectBatch).toBe(null, msg);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand All @@ -869,7 +869,7 @@ describe('@gl Test gl2d plots', function() {
.then(function() {
expect(readPixel(gd.querySelector('.gl-canvas-context'), 100, 80)[0]).toBe(0);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -914,7 +914,7 @@ describe('@gl Test gl2d plots', function() {
// and 105545275 after.
expect(total).toBeGreaterThan(4e6);
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand Down Expand Up @@ -945,7 +945,21 @@ describe('@gl Test gl2d plots', function() {
expect(opts.positions)
.toBeCloseToArray([1, 1, 2, 2, 3, 1]);
})
.catch(fail)
.catch(failTest)
.then(done);
});

it('should create two WebGL contexts per graph', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/gl2d_stacked_subplots.json'));

Plotly.plot(gd, fig).then(function() {
var cnt = 0;
d3.select(gd).selectAll('canvas').each(function(d) {
if(d.regl) cnt++;
});
expect(cnt).toBe(2);
})
.catch(failTest)
.then(done);
});
});
Expand Down Expand Up @@ -987,7 +1001,7 @@ describe('Test scattergl autorange:', function() {
expect(gd._fullLayout.xaxis.range).toBeCloseToArray(glRangeX, 'x range');
expect(gd._fullLayout.yaxis.range).toBeCloseToArray(glRangeY, 'y range');
})
.catch(fail)
.catch(failTest)
.then(done);
});
});
Expand Down Expand Up @@ -1026,7 +1040,7 @@ describe('Test scattergl autorange:', function() {
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.079, 1.079], 2, 'x range');
expect(gd._fullLayout.yaxis.range).toBeCloseToArray([-0.105, 1.105], 2, 'y range');
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand All @@ -1044,7 +1058,7 @@ describe('Test scattergl autorange:', function() {
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.119, 1.119], 2, 'x range');
expect(gd._fullLayout.yaxis.range).toBeCloseToArray([-0.199, 1.199], 2, 'y range');
})
.catch(fail)
.catch(failTest)
.then(done);
});
});
Expand Down
12 changes: 10 additions & 2 deletions test/jasmine/tests/parcoords_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,8 @@ describe('@gl parcoords Lifecycle methods', function() {
});

describe('@gl parcoords basic use', function() {
var mockCopy,
gd;
var mockCopy;
var gd;

beforeEach(function(done) {
mockCopy = Lib.extendDeep({}, mock);
Expand All @@ -789,6 +789,14 @@ describe('@gl parcoords basic use', function() {

afterAll(purgeGraphDiv);

it('should create three WebGL contexts per graph', function() {
var cnt = 0;
d3.select(gd).selectAll('canvas').each(function(d) {
if(d.regl) cnt++;
});
expect(cnt).toBe(3);
});

it('`Plotly.plot` should have proper fields on `gd.data` on initial rendering', function() {

expect(gd.data.length).toEqual(1);
Expand Down