Skip to content

Commit 6abb2ff

Browse files
committed
introduce redrawReglTraces subroutine
- which (re)-draw scattergl, scatterpolargl, splom traces as well as splom regl grid line in one go, always in the correct order - packaging these gl draw calls in one subroutine is especially useful for drag and selections, where buffers of targeted traces/scene are updated, but *all* traces need to be redraw following clearGlCanvases
1 parent 478c669 commit 6abb2ff

File tree

5 files changed

+63
-9
lines changed

5 files changed

+63
-9
lines changed

src/plot_api/subroutines.js

+57
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ exports.drawData = function(gd) {
600600
basePlotModules[i].plot(gd);
601601
}
602602

603+
exports.redrawReglTraces(gd);
604+
603605
// styling separate from drawing
604606
Plots.style(gd);
605607

@@ -613,6 +615,61 @@ exports.drawData = function(gd) {
613615
return Plots.previousPromises(gd);
614616
};
615617

618+
// Draw (or redraw) all traces in one go,
619+
// useful during drag and selection where buffers of targeted traces are updated,
620+
// but all traces need to be redrawn following clearGlCanvases.
621+
//
622+
// Note that _module.plot for regl trace does NOT draw things
623+
// on the canvas, they only update the buffers.
624+
// Drawing is perform here.
625+
//
626+
// TODO try adding per-subplot option using gl.SCISSOR_TEST for
627+
// non-overlaying, disjoint subplots.
628+
//
629+
// TODO try to include parcoords in here.
630+
exports.redrawReglTraces = function(gd) {
631+
var fullLayout = gd._fullLayout;
632+
633+
if(fullLayout._has('regl')) {
634+
var fullData = gd._fullData;
635+
var cartesianIds = [];
636+
var polarIds = [];
637+
var i, sp;
638+
639+
if(fullLayout._hasOnlyLargeSploms) {
640+
fullLayout._splomGrid.draw();
641+
}
642+
643+
// N.B.
644+
// - Loop over fullData (not _splomScenes) to preserve splom trace-to-trace ordering
645+
// - Fill list if subplot ids (instead of fullLayout._subplots) to handle cases where all traces
646+
// of a given module are `visible !== true`
647+
for(i = 0; i < fullData.length; i++) {
648+
var trace = fullData[i];
649+
650+
if(trace.visible === true) {
651+
if(trace.type === 'splom') {
652+
fullLayout._splomScenes[trace.uid].draw();
653+
} else if(trace.type === 'scattergl') {
654+
Lib.pushUnique(cartesianIds, trace.xaxis + trace.yaxis);
655+
} else if(trace.type === 'scatterpolargl') {
656+
Lib.pushUnique(polarIds, trace.subplot);
657+
}
658+
}
659+
}
660+
661+
for(i = 0; i < cartesianIds.length; i++) {
662+
sp = fullLayout._plots[cartesianIds[i]];
663+
if(sp._scene) sp._scene.draw();
664+
}
665+
666+
for(i = 0; i < polarIds.length; i++) {
667+
sp = fullLayout[polarIds[i]]._subplot;
668+
if(sp._scene) sp._scene.draw();
669+
}
670+
}
671+
};
672+
616673
exports.doAutoRangeAndConstraints = function(gd) {
617674
var axList = Axes.list(gd, '', true);
618675

src/traces/scattergl/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,6 @@ function plot(gd, subplot, cdata) {
640640
if(scene.glText) {
641641
scene.glText.forEach(function(text) { text.update(vpRange0); });
642642
}
643-
644-
scene.draw();
645643
}
646644

647645

src/traces/splom/base_plot.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function plot(gd) {
2828
if(!success) return;
2929

3030
if(fullLayout._hasOnlyLargeSploms) {
31-
drawGrid(gd);
31+
updateGrid(gd);
3232
}
3333

3434
_module.plot(gd, {}, splomCalcData);
@@ -84,17 +84,15 @@ function dragOne(gd, trace, scene) {
8484
}
8585
}
8686

87-
function drawGrid(gd) {
87+
function updateGrid(gd) {
8888
var fullLayout = gd._fullLayout;
8989
var regl = fullLayout._glcanvas.data()[0].regl;
9090
var splomGrid = fullLayout._splomGrid;
9191

9292
if(!splomGrid) {
9393
splomGrid = fullLayout._splomGrid = createLine(regl);
9494
}
95-
9695
splomGrid.update(makeGridData(gd));
97-
splomGrid.draw();
9896
}
9997

10098
function makeGridData(gd) {

src/traces/splom/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,6 @@ function plotOne(gd, cd0) {
302302
scene.matrix.update(opts, null);
303303
stash.xpx = stash.ypx = null;
304304
}
305-
306-
scene.draw();
307305
}
308306

309307
function editStyle(gd, cd0) {

test/jasmine/tests/gl2d_plot_interact_test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,10 @@ describe('Test scattergl autorange:', function() {
11821182

11831183
describe('should return the approximative values for ~big~ data', function() {
11841184
beforeEach(function() {
1185-
spyOn(ScatterGl, 'plot');
1185+
// to avoid expansive draw calls (which could be problematic on CI)
1186+
spyOn(ScatterGl, 'plot').and.callFake(function(gd) {
1187+
gd._fullLayout._plots.xy._scene.scatter2d = {draw: function() {}};
1188+
});
11861189
});
11871190

11881191
// threshold for 'fast' axis expansion routine

0 commit comments

Comments
 (0)