|
10 | 10 | 'use strict';
|
11 | 11 |
|
12 | 12 | var polygon = require('../../lib/polygon');
|
| 13 | +var throttle = require('../../lib/throttle'); |
13 | 14 | var color = require('../../components/color');
|
14 | 15 | var appendArrayPointValue = require('../../components/fx/helpers').appendArrayPointValue;
|
15 | 16 |
|
@@ -64,14 +65,11 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
|
64 | 65 |
|
65 | 66 |
|
66 | 67 | // 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; |
75 | 73 |
|
76 | 74 | for(i = 0; i < gd.calcdata.length; i++) {
|
77 | 75 | cd = gd.calcdata[i];
|
@@ -183,27 +181,35 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
|
183 | 181 | outlines.attr('d', 'M' + pts.filtered.join('L') + 'Z');
|
184 | 182 | }
|
185 | 183 |
|
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; |
195 | 198 | }
|
196 |
| - } |
197 |
| - else selection = thisSelection; |
198 |
| - } |
199 | 199 |
|
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 | + ); |
203 | 207 | };
|
204 | 208 |
|
205 | 209 | dragOptions.doneFn = function(dragged, numclicks) {
|
206 | 210 | corners.remove();
|
| 211 | + throttle.clear(throttleID); |
| 212 | + |
207 | 213 | if(!dragged && numclicks === 2) {
|
208 | 214 | // clear selection on doubleclick
|
209 | 215 | outlines.remove();
|
|
0 commit comments