Skip to content

Commit 256c5c7

Browse files
committed
throttle just the selectPoints part of box/lasso selection
1 parent 753b2c9 commit 256c5c7

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

src/plots/cartesian/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ module.exports = {
4747
// delay before a redraw (relayout) after smooth panning and zooming
4848
REDRAWDELAY: 50,
4949

50+
// throttling limit (ms) for selectPoints calls
51+
SELECTDELAY: 100,
52+
53+
// cache ID suffix for throttle
54+
SELECTID: '-select',
55+
5056
// last resort axis ranges for x and y axes if we have no data
5157
DFLTRANGEX: [-1, 6],
5258
DFLTRANGEY: [-1, 4],

src/plots/cartesian/select.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
var polygon = require('../../lib/polygon');
13+
var throttle = require('../../lib/throttle');
1314
var color = require('../../components/color');
1415
var appendArrayPointValue = require('../../components/fx/helpers').appendArrayPointValue;
1516

@@ -64,14 +65,11 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
6465

6566

6667
// find the traces to search for selection points
67-
var searchTraces = [],
68-
gd = dragOptions.gd,
69-
i,
70-
cd,
71-
trace,
72-
searchInfo,
73-
selection = [],
74-
eventData;
68+
var searchTraces = [];
69+
var gd = dragOptions.gd;
70+
var throttleID = gd._fullLayout._uid + constants.SELECTID;
71+
var selection = [];
72+
var i, cd, trace, searchInfo, eventData;
7573

7674
for(i = 0; i < gd.calcdata.length; i++) {
7775
cd = gd.calcdata[i];
@@ -183,27 +181,35 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
183181
outlines.attr('d', 'M' + pts.filtered.join('L') + 'Z');
184182
}
185183

186-
selection = [];
187-
for(i = 0; i < searchTraces.length; i++) {
188-
searchInfo = searchTraces[i];
189-
var thisSelection = fillSelectionItem(
190-
searchInfo.selectPoints(searchInfo, poly), searchInfo
191-
);
192-
if(selection.length) {
193-
for(var j = 0; j < thisSelection.length; j++) {
194-
selection.push(thisSelection[j]);
184+
throttle.throttle(
185+
function() {
186+
selection = [];
187+
for(i = 0; i < searchTraces.length; i++) {
188+
searchInfo = searchTraces[i];
189+
var thisSelection = fillSelectionItem(
190+
searchInfo.selectPoints(searchInfo, poly), searchInfo
191+
);
192+
if(selection.length) {
193+
for(var j = 0; j < thisSelection.length; j++) {
194+
selection.push(thisSelection[j]);
195+
}
196+
}
197+
else selection = thisSelection;
195198
}
196-
}
197-
else selection = thisSelection;
198-
}
199199

200-
eventData = {points: selection};
201-
fillRangeItems(eventData, poly, pts);
202-
dragOptions.gd.emit('plotly_selecting', eventData);
200+
eventData = {points: selection};
201+
fillRangeItems(eventData, poly, pts);
202+
dragOptions.gd.emit('plotly_selecting', eventData);
203+
},
204+
constants.SELECTDELAY,
205+
throttleID
206+
);
203207
};
204208

205209
dragOptions.doneFn = function(dragged, numclicks) {
206210
corners.remove();
211+
throttle.clear(throttleID);
212+
207213
if(!dragged && numclicks === 2) {
208214
// clear selection on doubleclick
209215
outlines.remove();

0 commit comments

Comments
 (0)