@@ -16,6 +16,7 @@ var Color = require('../../components/color');
16
16
var Fx = require ( '../../components/fx' ) ;
17
17
18
18
var polygon = require ( '../../lib/polygon' ) ;
19
+ var select = require ( '../../lib/select' ) ;
19
20
var throttle = require ( '../../lib/throttle' ) ;
20
21
var makeEventData = require ( '../../components/fx/helpers' ) . makeEventData ;
21
22
var getFromId = require ( './axis_ids' ) . getFromId ;
@@ -26,7 +27,8 @@ var MINSELECT = constants.MINSELECT;
26
27
27
28
var filteredPolygon = polygon . filter ;
28
29
var polygonTester = polygon . tester ;
29
- var multipolygonTester = polygon . multitester ;
30
+ var pointSelectionDef = select . pointSelectionDef ;
31
+ var multiTester = select . multiTester ;
30
32
31
33
function getAxId ( ax ) { return ax . _id ; }
32
34
@@ -50,7 +52,7 @@ function prepSelect(e, startX, startY, dragOptions, mode) {
50
52
var allAxes = dragOptions . xaxes . concat ( dragOptions . yaxes ) ;
51
53
var subtract = e . altKey ;
52
54
53
- var filterPoly , testPoly , mergedPolygons , currentPolygon ;
55
+ var filterPoly , selectionTester , mergedPolygons , currentPolygon ;
54
56
var i , searchInfo , eventData ;
55
57
56
58
coerceSelectionsCache ( e , gd , dragOptions ) ;
@@ -185,14 +187,14 @@ function prepSelect(e, startX, startY, dragOptions, mode) {
185
187
}
186
188
187
189
// create outline & tester
188
- if ( dragOptions . polygons && dragOptions . polygons . length ) {
190
+ if ( dragOptions . selectionDefs && dragOptions . selectionDefs . length ) {
189
191
mergedPolygons = mergePolygons ( dragOptions . mergedPolygons , currentPolygon , subtract ) ;
190
192
currentPolygon . subtract = subtract ;
191
- testPoly = multipolygonTester ( dragOptions . polygons . concat ( [ currentPolygon ] ) ) ;
193
+ selectionTester = multiTester ( dragOptions . selectionDefs . concat ( [ currentPolygon ] ) ) ;
192
194
}
193
195
else {
194
196
mergedPolygons = [ currentPolygon ] ;
195
- testPoly = polygonTester ( currentPolygon ) ;
197
+ selectionTester = polygonTester ( currentPolygon ) ;
196
198
}
197
199
198
200
// draw selection
@@ -209,7 +211,7 @@ function prepSelect(e, startX, startY, dragOptions, mode) {
209
211
for ( i = 0 ; i < searchTraces . length ; i ++ ) {
210
212
searchInfo = searchTraces [ i ] ;
211
213
212
- traceSelection = searchInfo . _module . selectPoints ( searchInfo , testPoly ) ;
214
+ traceSelection = searchInfo . _module . selectPoints ( searchInfo , selectionTester ) ;
213
215
traceSelections . push ( traceSelection ) ;
214
216
215
217
thisSelection = fillSelectionItem ( traceSelection , searchInfo ) ;
@@ -276,10 +278,10 @@ function prepSelect(e, startX, startY, dragOptions, mode) {
276
278
throttle . clear ( throttleID ) ;
277
279
dragOptions . gd . emit ( 'plotly_selected' , eventData ) ;
278
280
279
- if ( currentPolygon && dragOptions . polygons ) {
281
+ if ( currentPolygon && dragOptions . selectionDefs ) {
280
282
// save last polygons
281
283
currentPolygon . subtract = subtract ;
282
- dragOptions . polygons . push ( currentPolygon ) ;
284
+ dragOptions . selectionDefs . push ( currentPolygon ) ;
283
285
284
286
// we have to keep reference to arrays container
285
287
dragOptions . mergedPolygons . length = 0 ;
@@ -296,8 +298,8 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli
296
298
var selection = [ ] ;
297
299
var searchTraces ;
298
300
var searchInfo ;
299
- var currentPolygon ;
300
- var testPoly ;
301
+ var currentSelectionDef ;
302
+ var selectionTester ;
301
303
var traceSelection ;
302
304
var thisTracesSelection ;
303
305
var pointOrBinSelected ;
@@ -338,13 +340,13 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli
338
340
( pointOrBinSelected !== undefined ?
339
341
pointOrBinSelected :
340
342
isPointOrBinSelected ( clickedPtInfo ) ) ;
341
- currentPolygon = createPtNumTester ( clickedPtInfo . pointNumber , clickedPtInfo . searchInfo , subtract ) ;
343
+ currentSelectionDef = pointSelectionDef ( clickedPtInfo . pointNumber , clickedPtInfo . searchInfo , subtract ) ;
342
344
343
- var concatenatedPolygons = dragOptions . polygons . concat ( [ currentPolygon ] ) ;
344
- testPoly = multipolygonTester ( concatenatedPolygons ) ;
345
+ var allSelectionDefs = dragOptions . selectionDefs . concat ( [ currentSelectionDef ] ) ;
346
+ selectionTester = multiTester ( allSelectionDefs ) ;
345
347
346
348
for ( i = 0 ; i < searchTraces . length ; i ++ ) {
347
- traceSelection = searchTraces [ i ] . _module . selectPoints ( searchTraces [ i ] , testPoly ) ;
349
+ traceSelection = searchTraces [ i ] . _module . selectPoints ( searchTraces [ i ] , selectionTester ) ;
348
350
thisTracesSelection = fillSelectionItem ( traceSelection , searchTraces [ i ] ) ;
349
351
350
352
if ( selection . length ) {
@@ -358,8 +360,8 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli
358
360
eventData = { points : selection } ;
359
361
updateSelectedState ( gd , searchTraces , eventData ) ;
360
362
361
- if ( currentPolygon && dragOptions ) {
362
- dragOptions . polygons . push ( currentPolygon ) ;
363
+ if ( currentSelectionDef && dragOptions ) {
364
+ dragOptions . selectionDefs . push ( currentSelectionDef ) ;
363
365
}
364
366
365
367
if ( polygonOutlines ) drawSelection ( dragOptions . mergedPolygons , polygonOutlines ) ;
@@ -384,11 +386,11 @@ function coerceSelectionsCache(evt, gd, dragOptions) {
384
386
if (
385
387
selectingOnSameSubplot &&
386
388
( evt . shiftKey || evt . altKey ) &&
387
- ( plotinfo . selection && plotinfo . selection . polygons ) &&
388
- ! dragOptions . polygons
389
+ ( plotinfo . selection && plotinfo . selection . selectionDefs ) &&
390
+ ! dragOptions . selectionDefs
389
391
) {
390
- // take over selection polygons from prev mode, if any
391
- dragOptions . polygons = plotinfo . selection . polygons ;
392
+ // take over selection definitions from prev mode, if any
393
+ dragOptions . selectionDefs = plotinfo . selection . selectionDefs ;
392
394
dragOptions . mergedPolygons = plotinfo . selection . mergedPolygons ;
393
395
} else if (
394
396
( ! evt . shiftKey && ! evt . altKey ) ||
@@ -408,7 +410,7 @@ function clearSelectionsCache(dragOptions) {
408
410
var plotinfo = dragOptions . plotinfo ;
409
411
410
412
plotinfo . selection = { } ;
411
- plotinfo . selection . polygons = dragOptions . polygons = [ ] ;
413
+ plotinfo . selection . selectionDefs = dragOptions . selectionDefs = [ ] ;
412
414
plotinfo . selection . mergedPolygons = dragOptions . mergedPolygons = [ ] ;
413
415
}
414
416
@@ -515,24 +517,6 @@ function extractClickedPtInfo(hoverData, searchTraces) {
515
517
} ;
516
518
}
517
519
518
- function createPtNumTester ( wantedPointNumber , wantedSearchInfo , subtract ) {
519
- return {
520
- xmin : 0 ,
521
- xmax : 0 ,
522
- ymin : 0 ,
523
- ymax : 0 ,
524
- pts : [ ] ,
525
- // TODO Consider making signature of contains more lean
526
- contains : function ( pt , omitFirstEdge , pointNumber , searchInfo ) {
527
- return searchInfo . cd [ 0 ] . trace . _expandedIndex === wantedSearchInfo . cd [ 0 ] . trace . _expandedIndex &&
528
- pointNumber === wantedPointNumber ;
529
- } ,
530
- isRect : false ,
531
- degenerate : false ,
532
- subtract : subtract
533
- } ;
534
- }
535
-
536
520
function isPointOrBinSelected ( clickedPtInfo ) {
537
521
var trace = clickedPtInfo . searchInfo . cd [ 0 ] . trace ;
538
522
var ptNum = clickedPtInfo . pointNumber ;
0 commit comments