Skip to content

Commit 8cccacc

Browse files
authored
Merge pull request #5632 from Seranicio/master
Address scattergl performance issue with TypeArrays
2 parents 8ab0260 + f8d552e commit 8cccacc

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/components/color/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var tinycolor = require('tinycolor2');
44
var isNumeric = require('fast-isnumeric');
5+
var isTypedArray = require('../../lib/array').isTypedArray;
56

67
var color = module.exports = {};
78

@@ -116,7 +117,7 @@ color.clean = function(container) {
116117
if(!Array.isArray(el0) && el0 && typeof el0 === 'object') {
117118
for(j = 0; j < val.length; j++) color.clean(val[j]);
118119
}
119-
} else if(val && typeof val === 'object') color.clean(val);
120+
} else if(val && typeof val === 'object' && !isTypedArray(val)) color.clean(val);
120121
}
121122
};
122123

src/traces/scattergl/calc.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = function calc(gd, trace) {
2727
var hasTooManyPoints = len >= TOO_MANY_POINTS;
2828
var len2 = len * 2;
2929
var stash = {};
30-
var i, xx, yy;
30+
var i;
3131

3232
var origX = xa.makeCalcdata(trace, 'x');
3333
var origY = ya.makeCalcdata(trace, 'y');
@@ -42,11 +42,12 @@ module.exports = function calc(gd, trace) {
4242
// we need hi-precision for scatter2d,
4343
// regl-scatter2d uses NaNs for bad/missing values
4444
var positions = new Array(len2);
45+
var _ids = new Array(len);
4546
for(i = 0; i < len; i++) {
46-
xx = x[i];
47-
yy = y[i];
48-
positions[i * 2] = xx === BADNUM ? NaN : xx;
49-
positions[i * 2 + 1] = yy === BADNUM ? NaN : yy;
47+
positions[i * 2] = x[i] === BADNUM ? NaN : x[i];
48+
positions[i * 2 + 1] = y[i] === BADNUM ? NaN : y[i];
49+
// Pre-compute ids.
50+
_ids[i] = i;
5051
}
5152

5253
if(xa.type === 'log') {
@@ -66,10 +67,7 @@ module.exports = function calc(gd, trace) {
6667
// FIXME: delegate this to webworker
6768
stash.tree = cluster(positions);
6869
} else {
69-
var ids = stash.ids = new Array(len);
70-
for(i = 0; i < len; i++) {
71-
ids[i] = i;
72-
}
70+
stash.ids = _ids;
7371
}
7472

7573
// create scene options and scene

0 commit comments

Comments
 (0)