@@ -16,6 +16,7 @@ var Color = require('../../components/color');
1616var Fx = require ( '../../components/fx' ) ;
1717
1818var polygon = require ( '../../lib/polygon' ) ;
19+ var select = require ( '../../lib/select' ) ;
1920var throttle = require ( '../../lib/throttle' ) ;
2021var makeEventData = require ( '../../components/fx/helpers' ) . makeEventData ;
2122var getFromId = require ( './axis_ids' ) . getFromId ;
@@ -26,7 +27,8 @@ var MINSELECT = constants.MINSELECT;
2627
2728var filteredPolygon = polygon . filter ;
2829var polygonTester = polygon . tester ;
29- var multipolygonTester = polygon . multitester ;
30+ var pointSelectionDef = select . pointSelectionDef ;
31+ var multiTester = select . multiTester ;
3032
3133function getAxId ( ax ) { return ax . _id ; }
3234
@@ -50,7 +52,7 @@ function prepSelect(e, startX, startY, dragOptions, mode) {
5052 var allAxes = dragOptions . xaxes . concat ( dragOptions . yaxes ) ;
5153 var subtract = e . altKey ;
5254
53- var filterPoly , testPoly , mergedPolygons , currentPolygon ;
55+ var filterPoly , selectionTester , mergedPolygons , currentPolygon ;
5456 var i , searchInfo , eventData ;
5557
5658 coerceSelectionsCache ( e , gd , dragOptions ) ;
@@ -185,14 +187,14 @@ function prepSelect(e, startX, startY, dragOptions, mode) {
185187 }
186188
187189 // create outline & tester
188- if ( dragOptions . polygons && dragOptions . polygons . length ) {
190+ if ( dragOptions . selectionDefs && dragOptions . selectionDefs . length ) {
189191 mergedPolygons = mergePolygons ( dragOptions . mergedPolygons , currentPolygon , subtract ) ;
190192 currentPolygon . subtract = subtract ;
191- testPoly = multipolygonTester ( dragOptions . polygons . concat ( [ currentPolygon ] ) ) ;
193+ selectionTester = multiTester ( dragOptions . selectionDefs . concat ( [ currentPolygon ] ) ) ;
192194 }
193195 else {
194196 mergedPolygons = [ currentPolygon ] ;
195- testPoly = polygonTester ( currentPolygon ) ;
197+ selectionTester = polygonTester ( currentPolygon ) ;
196198 }
197199
198200 // draw selection
@@ -209,7 +211,7 @@ function prepSelect(e, startX, startY, dragOptions, mode) {
209211 for ( i = 0 ; i < searchTraces . length ; i ++ ) {
210212 searchInfo = searchTraces [ i ] ;
211213
212- traceSelection = searchInfo . _module . selectPoints ( searchInfo , testPoly ) ;
214+ traceSelection = searchInfo . _module . selectPoints ( searchInfo , selectionTester ) ;
213215 traceSelections . push ( traceSelection ) ;
214216
215217 thisSelection = fillSelectionItem ( traceSelection , searchInfo ) ;
@@ -276,10 +278,10 @@ function prepSelect(e, startX, startY, dragOptions, mode) {
276278 throttle . clear ( throttleID ) ;
277279 dragOptions . gd . emit ( 'plotly_selected' , eventData ) ;
278280
279- if ( currentPolygon && dragOptions . polygons ) {
281+ if ( currentPolygon && dragOptions . selectionDefs ) {
280282 // save last polygons
281283 currentPolygon . subtract = subtract ;
282- dragOptions . polygons . push ( currentPolygon ) ;
284+ dragOptions . selectionDefs . push ( currentPolygon ) ;
283285
284286 // we have to keep reference to arrays container
285287 dragOptions . mergedPolygons . length = 0 ;
@@ -296,8 +298,8 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli
296298 var selection = [ ] ;
297299 var searchTraces ;
298300 var searchInfo ;
299- var currentPolygon ;
300- var testPoly ;
301+ var currentSelectionDef ;
302+ var selectionTester ;
301303 var traceSelection ;
302304 var thisTracesSelection ;
303305 var pointOrBinSelected ;
@@ -338,13 +340,13 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli
338340 ( pointOrBinSelected !== undefined ?
339341 pointOrBinSelected :
340342 isPointOrBinSelected ( clickedPtInfo ) ) ;
341- currentPolygon = createPtNumTester ( clickedPtInfo . pointNumber , clickedPtInfo . searchInfo , subtract ) ;
343+ currentSelectionDef = pointSelectionDef ( clickedPtInfo . pointNumber , clickedPtInfo . searchInfo , subtract ) ;
342344
343- var concatenatedPolygons = dragOptions . polygons . concat ( [ currentPolygon ] ) ;
344- testPoly = multipolygonTester ( concatenatedPolygons ) ;
345+ var allSelectionDefs = dragOptions . selectionDefs . concat ( [ currentSelectionDef ] ) ;
346+ selectionTester = multiTester ( allSelectionDefs ) ;
345347
346348 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 ) ;
348350 thisTracesSelection = fillSelectionItem ( traceSelection , searchTraces [ i ] ) ;
349351
350352 if ( selection . length ) {
@@ -358,8 +360,8 @@ function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutli
358360 eventData = { points : selection } ;
359361 updateSelectedState ( gd , searchTraces , eventData ) ;
360362
361- if ( currentPolygon && dragOptions ) {
362- dragOptions . polygons . push ( currentPolygon ) ;
363+ if ( currentSelectionDef && dragOptions ) {
364+ dragOptions . selectionDefs . push ( currentSelectionDef ) ;
363365 }
364366
365367 if ( polygonOutlines ) drawSelection ( dragOptions . mergedPolygons , polygonOutlines ) ;
@@ -384,11 +386,11 @@ function coerceSelectionsCache(evt, gd, dragOptions) {
384386 if (
385387 selectingOnSameSubplot &&
386388 ( evt . shiftKey || evt . altKey ) &&
387- ( plotinfo . selection && plotinfo . selection . polygons ) &&
388- ! dragOptions . polygons
389+ ( plotinfo . selection && plotinfo . selection . selectionDefs ) &&
390+ ! dragOptions . selectionDefs
389391 ) {
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 ;
392394 dragOptions . mergedPolygons = plotinfo . selection . mergedPolygons ;
393395 } else if (
394396 ( ! evt . shiftKey && ! evt . altKey ) ||
@@ -408,7 +410,7 @@ function clearSelectionsCache(dragOptions) {
408410 var plotinfo = dragOptions . plotinfo ;
409411
410412 plotinfo . selection = { } ;
411- plotinfo . selection . polygons = dragOptions . polygons = [ ] ;
413+ plotinfo . selection . selectionDefs = dragOptions . selectionDefs = [ ] ;
412414 plotinfo . selection . mergedPolygons = dragOptions . mergedPolygons = [ ] ;
413415}
414416
@@ -515,24 +517,6 @@ function extractClickedPtInfo(hoverData, searchTraces) {
515517 } ;
516518}
517519
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-
536520function isPointOrBinSelected ( clickedPtInfo ) {
537521 var trace = clickedPtInfo . searchInfo . cd [ 0 ] . trace ;
538522 var ptNum = clickedPtInfo . pointNumber ;
0 commit comments