@@ -144,7 +144,22 @@ var BOXEVENTS = [1, 2, 1];
144144// assumes 5 points in the lasso path
145145var LASSOEVENTS = [ 4 , 2 , 1 ] ;
146146
147- describe ( 'Click-to-select' , function ( ) {
147+ var mockZindex = {
148+ data : [
149+ { x : [ 1 , 2 ] , y : [ 1 , 1 ] , type : 'scatter' , zindex : 10 , marker : { size : 50 } } ,
150+ { x : [ 1 , 2 ] , y : [ 1 , 2 ] , type : 'scatter' , marker : { size : 50 } } ,
151+ { x : [ 1 , 2 ] , y : [ 1 , 3 ] , type : 'scatter' , zindex : 5 , marker : { size : 50 } }
152+ ] ,
153+ layout : {
154+ width : 400 ,
155+ height : 400 ,
156+ clickmode : 'event+select' ,
157+ dragmode : 'select' ,
158+ hovermode : 'closest'
159+ }
160+ } ;
161+
162+ fdescribe ( 'Click-to-select' , function ( ) {
148163 var mock14Pts = {
149164 1 : { x : 134 , y : 116 } ,
150165 7 : { x : 270 , y : 160 } ,
@@ -264,6 +279,84 @@ describe('Click-to-select', function() {
264279 . then ( done , done . fail ) ;
265280 } ) ;
266281
282+ it ( 'selects a single data point when being clicked on trace with zindex' , function ( done ) {
283+ _newPlot ( gd , mockZindex . data , mockZindex . layout )
284+ . then ( function ( ) {
285+ return _immediateClickPt ( { x : 270 , y : 150 } ) ;
286+ } )
287+ . then ( function ( ) {
288+ assertSelectedPoints ( [ ] , [ ] , [ 1 ] ) ;
289+ return _clickPt ( { x : 270 , y : 200 } ) ;
290+ } )
291+ . then ( function ( ) {
292+ assertSelectedPoints ( [ ] , [ 1 ] , [ ] ) ;
293+ return _clickPt ( { x : 270 , y : 250 } ) ;
294+ } )
295+ . then ( done , done . fail ) ;
296+ } ) ;
297+
298+ it ( 'should only select top most zindex trace if overlapping position on single click' , function ( done ) {
299+ _newPlot ( gd , mockZindex . data , mockZindex . layout )
300+ . then ( function ( ) {
301+ return _immediateClickPt ( { x : 130 , y : 250 } ) ;
302+ } )
303+ . then ( function ( ) {
304+ assertSelectedPoints ( [ ] , [ 1 ] , [ ] ) ;
305+ } )
306+ . then ( done , done . fail ) ;
307+ } ) ;
308+
309+ it ( 'should lasso select all overlapping points regardless of zindex' , function ( done ) {
310+ mockZindex . layout . dragmode = 'lasso' ;
311+ _newPlot ( gd , mockZindex . data , mockZindex . layout )
312+ . then ( function ( ) {
313+ drag ( [ [ 200 , 200 ] , [ 200 , 300 ] , [ 100 , 300 ] , [ 100 , 200 ] , [ 200 , 200 ] ] ) ;
314+ } )
315+ . then ( function ( ) {
316+ expect ( gd . data [ 0 ] . selectedpoints ) . toEqual ( [ 0 ] ) ;
317+ expect ( gd . data [ 1 ] . selectedpoints ) . toEqual ( [ 0 ] ) ;
318+ expect ( gd . data [ 2 ] . selectedpoints ) . toEqual ( [ 0 ] ) ;
319+ } )
320+ . then ( function ( ) {
321+ return doubleClick ( 200 , 200 ) ; // Clear selection
322+ } )
323+ . then ( function ( ) {
324+ drag ( [ [ 200 , 100 ] , [ 200 , 300 ] , [ 300 , 300 ] , [ 300 , 100 ] , [ 200 , 100 ] ] ) ;
325+ } )
326+ . then ( function ( ) {
327+ expect ( gd . data [ 0 ] . selectedpoints ) . toEqual ( [ 1 ] ) ;
328+ expect ( gd . data [ 1 ] . selectedpoints ) . toEqual ( [ 1 ] ) ;
329+ expect ( gd . data [ 2 ] . selectedpoints ) . toEqual ( [ 1 ] ) ;
330+ } )
331+ . then ( done , done . fail ) ;
332+ } ) ;
333+
334+ fit ( 'should box select all overlapping points regardless of zindex' , function ( done ) {
335+ mockZindex . layout . dragmode = 'select' ;
336+ _newPlot ( gd , mockZindex . data , mockZindex . layout )
337+ . then ( function ( ) {
338+ drag ( [ [ 200 , 200 ] , [ 100 , 300 ] ] ) ;
339+ } )
340+ . then ( function ( ) {
341+ expect ( gd . data [ 0 ] . selectedpoints ) . toEqual ( [ 0 ] ) ;
342+ expect ( gd . data [ 1 ] . selectedpoints ) . toEqual ( [ 0 ] ) ;
343+ expect ( gd . data [ 2 ] . selectedpoints ) . toEqual ( [ 0 ] ) ;
344+ } )
345+ . then ( function ( ) {
346+ return doubleClick ( 200 , 200 ) ; // Clear selection
347+ } )
348+ . then ( function ( ) {
349+ drag ( [ [ 200 , 100 ] , [ 300 , 300 ] ] ) ;
350+ } )
351+ . then ( function ( ) {
352+ expect ( gd . data [ 0 ] . selectedpoints ) . toEqual ( [ 1 ] ) ;
353+ expect ( gd . data [ 1 ] . selectedpoints ) . toEqual ( [ 1 ] ) ;
354+ expect ( gd . data [ 2 ] . selectedpoints ) . toEqual ( [ 1 ] ) ;
355+ } )
356+ . then ( done , done . fail ) ;
357+ } ) ;
358+
359+
267360 it ( 'cleanly clears and starts selections although add/subtract mode on' , function ( done ) {
268361 plotMock14 ( )
269362 . then ( function ( ) {
0 commit comments