Skip to content

Commit 887cae6

Browse files
authored
Merge pull request #2662 from plotly/scattergl-two-not-three-contexts
Create two (not three) WebGL contexts for scattergl/splom graphs
2 parents dfb56d3 + a3dce12 commit 887cae6

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
lines changed

src/lib/prepare_regl.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ var createRegl = require('regl');
2323
* @param {array} extensions : list of extension to pass to createRegl
2424
*/
2525
module.exports = function prepareRegl(gd, extensions) {
26-
gd._fullLayout._glcanvas.each(function(d) {
26+
var fullLayout = gd._fullLayout;
27+
28+
fullLayout._glcanvas.each(function(d) {
2729
if(d.regl) return;
30+
// only parcoords needs pick layer
31+
if(d.pick && !fullLayout._has('parcoords')) return;
2832

2933
d.regl = createRegl({
3034
canvas: this,

test/jasmine/tests/gl2d_plot_interact_test.js

+34-20
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var ScatterGl = require('@src/traces/scattergl');
88

99
var createGraphDiv = require('../assets/create_graph_div');
1010
var destroyGraphDiv = require('../assets/destroy_graph_div');
11-
var fail = require('../assets/fail_test');
11+
var failTest = require('../assets/fail_test');
1212
var mouseEvent = require('../assets/mouse_event');
1313
var touchEvent = require('../assets/touch_event');
1414
var drag = require('../assets/drag');
@@ -202,7 +202,7 @@ describe('@gl Test gl plot side effects', function() {
202202
.then(function() {
203203
expect(gd.querySelector('.gl-canvas-context').width).toBe(300);
204204
})
205-
.catch(fail)
205+
.catch(failTest)
206206
.then(done);
207207
});
208208
});
@@ -350,7 +350,7 @@ describe('@gl Test gl2d plots', function() {
350350
'yaxis.range[1]': jasmine.any(Number)
351351
}));
352352
})
353-
.catch(fail)
353+
.catch(failTest)
354354
.then(done);
355355
});
356356

@@ -381,7 +381,7 @@ describe('@gl Test gl2d plots', function() {
381381
.then(function() {
382382
expect(readPixel(gd.querySelector('.gl-canvas-context'), 108, 100)[0]).not.toBe(0);
383383
})
384-
.catch(fail)
384+
.catch(failTest)
385385
.then(done);
386386
});
387387

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

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

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

@@ -514,7 +514,7 @@ describe('@gl Test gl2d plots', function() {
514514
expect(countCanvases()).toBe(0);
515515
expect(d3.selectAll('.scatterlayer > .trace').size()).toBe(1);
516516
})
517-
.catch(fail)
517+
.catch(failTest)
518518
.then(done);
519519
});
520520

@@ -567,7 +567,7 @@ describe('@gl Test gl2d plots', function() {
567567
expect(gd.layout.xaxis.range).toBeCloseToArray([6, 8], 3);
568568
expect(gd.layout.yaxis.range).toBeCloseToArray([5, 7], 3);
569569
})
570-
.catch(fail)
570+
.catch(failTest)
571571
.then(done);
572572
});
573573

@@ -634,7 +634,7 @@ describe('@gl Test gl2d plots', function() {
634634
expect(gd.layout.xaxis.range).toBeCloseToArray([-8.2, 24.2], 1);
635635
expect(gd.layout.yaxis.range).toBeCloseToArray([-0.12, 16.1], 1);
636636
})
637-
.catch(fail)
637+
.catch(failTest)
638638
.then(done);
639639
});
640640

@@ -690,7 +690,7 @@ describe('@gl Test gl2d plots', function() {
690690
.then(function() {
691691
assertAnnotation([327, 331]);
692692
})
693-
.catch(fail)
693+
.catch(failTest)
694694
.then(done);
695695
});
696696

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

746746
})
747-
.catch(fail)
747+
.catch(failTest)
748748
.then(done);
749749
});
750750

@@ -768,7 +768,7 @@ describe('@gl Test gl2d plots', function() {
768768
.then(function() {
769769
expect(ScatterGl.calc).toHaveBeenCalledTimes(2);
770770
})
771-
.catch(fail)
771+
.catch(failTest)
772772
.then(done);
773773
});
774774

@@ -852,7 +852,7 @@ describe('@gl Test gl2d plots', function() {
852852
expect(scene.selectBatch).toBe(null, msg);
853853
expect(scene.unselectBatch).toBe(null, msg);
854854
})
855-
.catch(fail)
855+
.catch(failTest)
856856
.then(done);
857857
});
858858

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

@@ -914,7 +914,7 @@ describe('@gl Test gl2d plots', function() {
914914
// and 105545275 after.
915915
expect(total).toBeGreaterThan(4e6);
916916
})
917-
.catch(fail)
917+
.catch(failTest)
918918
.then(done);
919919
});
920920

@@ -945,7 +945,21 @@ describe('@gl Test gl2d plots', function() {
945945
expect(opts.positions)
946946
.toBeCloseToArray([1, 1, 2, 2, 3, 1]);
947947
})
948-
.catch(fail)
948+
.catch(failTest)
949+
.then(done);
950+
});
951+
952+
it('should create two WebGL contexts per graph', function(done) {
953+
var fig = Lib.extendDeep({}, require('@mocks/gl2d_stacked_subplots.json'));
954+
955+
Plotly.plot(gd, fig).then(function() {
956+
var cnt = 0;
957+
d3.select(gd).selectAll('canvas').each(function(d) {
958+
if(d.regl) cnt++;
959+
});
960+
expect(cnt).toBe(2);
961+
})
962+
.catch(failTest)
949963
.then(done);
950964
});
951965
});
@@ -987,7 +1001,7 @@ describe('Test scattergl autorange:', function() {
9871001
expect(gd._fullLayout.xaxis.range).toBeCloseToArray(glRangeX, 'x range');
9881002
expect(gd._fullLayout.yaxis.range).toBeCloseToArray(glRangeY, 'y range');
9891003
})
990-
.catch(fail)
1004+
.catch(failTest)
9911005
.then(done);
9921006
});
9931007
});
@@ -1026,7 +1040,7 @@ describe('Test scattergl autorange:', function() {
10261040
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.079, 1.079], 2, 'x range');
10271041
expect(gd._fullLayout.yaxis.range).toBeCloseToArray([-0.105, 1.105], 2, 'y range');
10281042
})
1029-
.catch(fail)
1043+
.catch(failTest)
10301044
.then(done);
10311045
});
10321046

@@ -1044,7 +1058,7 @@ describe('Test scattergl autorange:', function() {
10441058
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.119, 1.119], 2, 'x range');
10451059
expect(gd._fullLayout.yaxis.range).toBeCloseToArray([-0.199, 1.199], 2, 'y range');
10461060
})
1047-
.catch(fail)
1061+
.catch(failTest)
10481062
.then(done);
10491063
});
10501064
});

test/jasmine/tests/parcoords_test.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,8 @@ describe('@gl parcoords Lifecycle methods', function() {
770770
});
771771

772772
describe('@gl parcoords basic use', function() {
773-
var mockCopy,
774-
gd;
773+
var mockCopy;
774+
var gd;
775775

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

790790
afterAll(purgeGraphDiv);
791791

792+
it('should create three WebGL contexts per graph', function() {
793+
var cnt = 0;
794+
d3.select(gd).selectAll('canvas').each(function(d) {
795+
if(d.regl) cnt++;
796+
});
797+
expect(cnt).toBe(3);
798+
});
799+
792800
it('`Plotly.plot` should have proper fields on `gd.data` on initial rendering', function() {
793801

794802
expect(gd.data.length).toEqual(1);

0 commit comments

Comments
 (0)