Skip to content

Commit 6ac722d

Browse files
committed
fill scattergl calcdata only when dragmode is set to select/lasso
- this brings back first render for 1e6 pts in close to 1500ms - add relayout logic so that updating into dragmode select/lasso triggers a recalc.
1 parent 07b4c7c commit 6ac722d

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

src/plot_api/plot_api.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -1939,15 +1939,16 @@ function _relayout(gd, aobj) {
19391939
// trunk nodes (everything except the leaf)
19401940
ptrunk = p.parts.slice(0, pend).join('.'),
19411941
parentIn = Lib.nestedProperty(gd.layout, ptrunk).get(),
1942-
parentFull = Lib.nestedProperty(fullLayout, ptrunk).get();
1942+
parentFull = Lib.nestedProperty(fullLayout, ptrunk).get(),
1943+
vOld = p.get();
19431944

19441945
if(vi === undefined) continue;
19451946

19461947
redoit[ai] = vi;
19471948

19481949
// axis reverse is special - it is its own inverse
19491950
// op and has no flag.
1950-
undoit[ai] = (pleaf === 'reverse') ? vi : p.get();
1951+
undoit[ai] = (pleaf === 'reverse') ? vi : vOld;
19511952

19521953
// Setting width or height to null must reset the graph's width / height
19531954
// back to its initial value as computed during the first pass in Plots.plotAutoSize.
@@ -2140,9 +2141,18 @@ function _relayout(gd, aobj) {
21402141
ai.match(/^(bar|box|font)/)) {
21412142
flags.docalc = true;
21422143
}
2143-
else if(fullLayout._has('gl2d') &&
2144-
(ai.indexOf('axis') !== -1 || ai === 'plot_bgcolor')
2145-
) flags.doplot = true;
2144+
else if(fullLayout._has('gl2d')) {
2145+
if(ai.indexOf('axis') !== -1 || ai === 'plot_bgcolor') {
2146+
flags.doplot = true;
2147+
}
2148+
2149+
if(ai === 'dragmode' &&
2150+
(vi === 'lasso' || vi === 'select') &&
2151+
!(vOld === 'lasso' || vOld === 'select')
2152+
) {
2153+
flags.docalc = true;
2154+
}
2155+
}
21462156
else if(ai === 'hiddenlabels') flags.docalc = true;
21472157
else if(proot.indexOf('legend') !== -1) flags.dolegend = true;
21482158
else if(ai.indexOf('title') !== -1) flags.doticks = true;

src/plot_api/subroutines.js

-5
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,6 @@ exports.doModeBar = function(gd) {
386386
scene.updateFx(fullLayout.dragmode, fullLayout.hovermode);
387387
}
388388

389-
subplotIds = Plots.getSubplotIds(fullLayout, 'gl2d');
390-
for(i = 0; i < subplotIds.length; i++) {
391-
fullLayout._plots[subplotIds[i]]._scene2d.updateFx();
392-
}
393-
394389
return Plots.previousPromises(gd);
395390
};
396391

src/plots/gl2d/scene2d.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ proto.makeFramework = function() {
154154
container.appendChild(canvas);
155155
container.appendChild(svgContainer);
156156
container.appendChild(mouseContainer);
157-
158-
this.updateFx();
159157
};
160158

161159
proto.toImage = function(format) {
@@ -374,6 +372,7 @@ proto.plot = function(fullData, calcData, fullLayout) {
374372

375373
this.updateRefs(fullLayout);
376374
this.updateTraces(fullData, calcData);
375+
this.updateFx();
377376

378377
var width = fullLayout.width,
379378
height = fullLayout.height;

src/traces/scattergl/calc.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,31 @@
1010
'use strict';
1111

1212
var Axes = require('../../plots/cartesian/axes');
13+
var arraysToCalcdata = require('../scatter/arrays_to_calcdata');
1314
var calcColorscales = require('../scatter/colorscale_calc');
1415

1516
module.exports = function calc(gd, trace) {
16-
var xa = Axes.getFromId(gd, trace.xaxis || 'x'),
17-
ya = Axes.getFromId(gd, trace.yaxis || 'y');
17+
var dragmode = gd._fullLayout.dragmode;
18+
var cd;
1819

19-
var x = xa.makeCalcdata(trace, 'x'),
20-
y = ya.makeCalcdata(trace, 'y');
20+
if(dragmode === 'lasso' || dragmode === 'select') {
21+
var xa = Axes.getFromId(gd, trace.xaxis || 'x');
22+
var ya = Axes.getFromId(gd, trace.yaxis || 'y');
2123

22-
var serieslen = Math.min(x.length, y.length), i;
24+
var x = xa.makeCalcdata(trace, 'x');
25+
var y = ya.makeCalcdata(trace, 'y');
2326

24-
// create the "calculated data" to plot
25-
var cd = new Array(serieslen);
26-
for(i = 0; i < serieslen; i++) {
27-
cd[i] = {x: x[i], y: y[i]};
27+
var serieslen = Math.min(x.length, y.length), i;
28+
29+
// create the "calculated data" to plot
30+
cd = new Array(serieslen);
31+
32+
for(i = 0; i < serieslen; i++) {
33+
cd[i] = {x: x[i], y: y[i]};
34+
}
35+
} else {
36+
cd = [{x: false, y: false, trace: trace, t: {}}];
37+
arraysToCalcdata(cd, trace);
2838
}
2939

3040
calcColorscales(trace);

0 commit comments

Comments
 (0)