Skip to content

Commit 10acee0

Browse files
authored
Merge pull request #1555 from hy9be/perf-scatterlayersort
Optimize the performance of scatter trace sorting comparator with map
2 parents 9e9d756 + 00178a2 commit 10acee0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/traces/scatter/plot.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ module.exports = function plot(gd, plotinfo, cdscatter, transitionOpts, makeOnCo
5151
// Sort the traces, once created, so that the ordering is preserved even when traces
5252
// are shown and hidden. This is needed since we're not just wiping everything out
5353
// and recreating on every update.
54-
for(i = 0, uids = []; i < cdscatter.length; i++) {
55-
uids[i] = cdscatter[i][0].trace.uid;
54+
for(i = 0, uids = {}; i < cdscatter.length; i++) {
55+
uids[cdscatter[i][0].trace.uid] = i;
5656
}
5757

5858
scatterlayer.selectAll('g.trace').sort(function(a, b) {
59-
var idx1 = uids.indexOf(a[0].trace.uid);
60-
var idx2 = uids.indexOf(b[0].trace.uid);
59+
var idx1 = uids[a[0].trace.uid];
60+
var idx2 = uids[b[0].trace.uid];
6161
return idx1 > idx2 ? 1 : -1;
6262
});
6363

0 commit comments

Comments
 (0)