@@ -6,6 +6,7 @@ var doubleClick = require('../assets/double_click');
6
6
7
7
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
8
8
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
9
+ var fail = require ( '../assets/fail_test' ) ;
9
10
var mouseEvent = require ( '../assets/mouse_event' ) ;
10
11
var customMatchers = require ( '../assets/custom_matchers' ) ;
11
12
@@ -16,7 +17,7 @@ describe('select box and lasso', function() {
16
17
var selectPath = [ [ 93 , 193 ] , [ 143 , 193 ] ] ;
17
18
var lassoPath = [ [ 316 , 171 ] , [ 318 , 239 ] , [ 335 , 243 ] , [ 328 , 169 ] ] ;
18
19
19
- beforeEach ( function ( ) {
20
+ beforeAll ( function ( ) {
20
21
jasmine . addMatchers ( customMatchers ) ;
21
22
} ) ;
22
23
@@ -59,6 +60,13 @@ describe('select box and lasso', function() {
59
60
} ) ;
60
61
}
61
62
63
+ function assertSelectionNodes ( cornerCnt , outlineCnt ) {
64
+ expect ( d3 . selectAll ( '.zoomlayer > .zoombox-corners' ) . size ( ) )
65
+ . toBe ( cornerCnt , 'selection corner count' ) ;
66
+ expect ( d3 . selectAll ( '.zoomlayer > .select-outline' ) . size ( ) )
67
+ . toBe ( outlineCnt , 'selection outline count' ) ;
68
+ }
69
+
62
70
describe ( 'select elements' , function ( ) {
63
71
var mockCopy = Lib . extendDeep ( { } , mock ) ;
64
72
mockCopy . layout . dragmode = 'select' ;
@@ -80,30 +88,21 @@ describe('select box and lasso', function() {
80
88
y2 = 50 ;
81
89
82
90
gd . once ( 'plotly_selecting' , function ( ) {
83
- expect ( d3 . selectAll ( '.zoomlayer > .zoombox-corners' ) . size ( ) )
84
- . toEqual ( 1 ) ;
85
- expect ( d3 . selectAll ( '.zoomlayer > .select-outline' ) . size ( ) )
86
- . toEqual ( 2 ) ;
91
+ assertSelectionNodes ( 1 , 2 ) ;
87
92
} ) ;
88
93
89
94
gd . once ( 'plotly_selected' , function ( ) {
90
- expect ( d3 . selectAll ( '.zoomlayer > .zoombox-corners' ) . size ( ) )
91
- . toEqual ( 0 ) ;
92
- expect ( d3 . selectAll ( '.zoomlayer > .select-outline' ) . size ( ) )
93
- . toEqual ( 2 ) ;
95
+ assertSelectionNodes ( 0 , 2 ) ;
94
96
} ) ;
95
97
96
98
gd . once ( 'plotly_deselect' , function ( ) {
97
- expect ( d3 . selectAll ( '.zoomlayer > .select-outline' ) . size ( ) )
98
- . toEqual ( 0 ) ;
99
+ assertSelectionNodes ( 0 , 0 ) ;
99
100
} ) ;
100
101
101
102
mouseEvent ( 'mousemove' , x0 , y0 ) ;
102
- expect ( d3 . selectAll ( '.zoomlayer > .zoombox-corners' ) . size ( ) )
103
- . toEqual ( 0 ) ;
103
+ assertSelectionNodes ( 0 , 0 ) ;
104
104
105
105
drag ( [ [ x0 , y0 ] , [ x1 , y1 ] ] ) ;
106
-
107
106
doubleClick ( x2 , y2 ) . then ( done ) ;
108
107
} ) ;
109
108
} ) ;
@@ -129,30 +128,21 @@ describe('select box and lasso', function() {
129
128
y2 = 50 ;
130
129
131
130
gd . once ( 'plotly_selecting' , function ( ) {
132
- expect ( d3 . selectAll ( '.zoomlayer > .zoombox-corners' ) . size ( ) )
133
- . toEqual ( 1 ) ;
134
- expect ( d3 . selectAll ( '.zoomlayer > .select-outline' ) . size ( ) )
135
- . toEqual ( 2 ) ;
131
+ assertSelectionNodes ( 1 , 2 ) ;
136
132
} ) ;
137
133
138
134
gd . once ( 'plotly_selected' , function ( ) {
139
- expect ( d3 . selectAll ( '.zoomlayer > .zoombox-corners' ) . size ( ) )
140
- . toEqual ( 0 ) ;
141
- expect ( d3 . selectAll ( '.zoomlayer > .select-outline' ) . size ( ) )
142
- . toEqual ( 2 ) ;
135
+ assertSelectionNodes ( 0 , 2 ) ;
143
136
} ) ;
144
137
145
138
gd . once ( 'plotly_deselect' , function ( ) {
146
- expect ( d3 . selectAll ( '.zoomlayer > .select-outline' ) . size ( ) )
147
- . toEqual ( 0 ) ;
139
+ assertSelectionNodes ( 0 , 0 ) ;
148
140
} ) ;
149
141
150
142
mouseEvent ( 'mousemove' , x0 , y0 ) ;
151
- expect ( d3 . selectAll ( '.zoomlayer > .zoombox-corners' ) . size ( ) )
152
- . toEqual ( 0 ) ;
143
+ assertSelectionNodes ( 0 , 0 ) ;
153
144
154
145
drag ( [ [ x0 , y0 ] , [ x1 , y1 ] ] ) ;
155
-
156
146
doubleClick ( x2 , y2 ) . then ( done ) ;
157
147
} ) ;
158
148
} ) ;
@@ -379,4 +369,95 @@ describe('select box and lasso', function() {
379
369
} )
380
370
. then ( done ) ;
381
371
} ) ;
372
+
373
+ it ( 'should work on scatterternary traces' , function ( done ) {
374
+ var fig = Lib . extendDeep ( { } , require ( '@mocks/ternary_simple' ) ) ;
375
+ var gd = createGraphDiv ( ) ;
376
+ var pts = [ ] ;
377
+
378
+ fig . layout . width = 800 ;
379
+ fig . layout . dragmode = 'select' ;
380
+
381
+ function assertPoints ( expected ) {
382
+ expect ( pts . length ) . toBe ( expected . length , 'selected points length' ) ;
383
+
384
+ pts . forEach ( function ( p , i ) {
385
+ var e = expected [ i ] ;
386
+ expect ( p . a ) . toBe ( e . a , 'selected pt a val' ) ;
387
+ expect ( p . b ) . toBe ( e . b , 'selected pt b val' ) ;
388
+ expect ( p . c ) . toBe ( e . c , 'selected pt c val' ) ;
389
+ } ) ;
390
+ pts = [ ] ;
391
+ }
392
+
393
+ Plotly . plot ( gd , fig ) . then ( function ( ) {
394
+ gd . on ( 'plotly_selected' , function ( data ) {
395
+ pts = data . points ;
396
+ } ) ;
397
+
398
+ assertSelectionNodes ( 0 , 0 ) ;
399
+ drag ( [ [ 400 , 200 ] , [ 445 , 235 ] ] ) ;
400
+ assertSelectionNodes ( 0 , 2 ) ;
401
+ assertPoints ( [ { a : 0.5 , b : 0.25 , c : 0.25 } ] ) ;
402
+
403
+ return Plotly . relayout ( gd , 'dragmode' , 'lasso' ) ;
404
+ } )
405
+ . then ( function ( ) {
406
+ assertSelectionNodes ( 0 , 0 ) ;
407
+ drag ( [ [ 400 , 200 ] , [ 445 , 200 ] , [ 445 , 235 ] , [ 400 , 235 ] , [ 400 , 200 ] ] ) ;
408
+ assertSelectionNodes ( 0 , 2 ) ;
409
+ assertPoints ( [ { a : 0.5 , b : 0.25 , c : 0.25 } ] ) ;
410
+
411
+ // should work after a relayout too
412
+ return Plotly . relayout ( gd , 'width' , 400 ) ;
413
+ } )
414
+ . then ( function ( ) {
415
+ assertSelectionNodes ( 0 , 0 ) ;
416
+ drag ( [ [ 200 , 200 ] , [ 230 , 200 ] , [ 230 , 230 ] , [ 200 , 230 ] , [ 200 , 200 ] ] ) ;
417
+ assertSelectionNodes ( 0 , 2 ) ;
418
+ assertPoints ( [ { a : 0.5 , b : 0.25 , c : 0.25 } ] ) ;
419
+ } )
420
+ . catch ( fail )
421
+ . then ( done ) ;
422
+ } ) ;
423
+
424
+ it ( 'should work on scattercarpet traces' , function ( done ) {
425
+ var fig = Lib . extendDeep ( { } , require ( '@mocks/scattercarpet' ) ) ;
426
+ var gd = createGraphDiv ( ) ;
427
+ var pts = [ ] ;
428
+
429
+ fig . layout . dragmode = 'select' ;
430
+
431
+ function assertPoints ( expected ) {
432
+ expect ( pts . length ) . toBe ( expected . length , 'selected points length' ) ;
433
+
434
+ pts . forEach ( function ( p , i ) {
435
+ var e = expected [ i ] ;
436
+ expect ( p . a ) . toBe ( e . a , 'selected pt a val' ) ;
437
+ expect ( p . b ) . toBe ( e . b , 'selected pt b val' ) ;
438
+ } ) ;
439
+ pts = [ ] ;
440
+ }
441
+
442
+ Plotly . plot ( gd , fig ) . then ( function ( ) {
443
+ gd . on ( 'plotly_selected' , function ( data ) {
444
+ pts = data . points ;
445
+ } ) ;
446
+
447
+ assertSelectionNodes ( 0 , 0 ) ;
448
+ drag ( [ [ 300 , 200 ] , [ 400 , 250 ] ] ) ;
449
+ assertSelectionNodes ( 0 , 2 ) ;
450
+ assertPoints ( [ { a : 0.2 , b : 1.5 } ] ) ;
451
+
452
+ return Plotly . relayout ( gd , 'dragmode' , 'lasso' ) ;
453
+ } )
454
+ . then ( function ( ) {
455
+ assertSelectionNodes ( 0 , 0 ) ;
456
+ drag ( [ [ 300 , 200 ] , [ 400 , 200 ] , [ 400 , 250 ] , [ 300 , 250 ] , [ 300 , 200 ] ] ) ;
457
+ assertSelectionNodes ( 0 , 2 ) ;
458
+ assertPoints ( [ { a : 0.2 , b : 1.5 } ] ) ;
459
+ } )
460
+ . catch ( fail )
461
+ . then ( done ) ;
462
+ } ) ;
382
463
} ) ;
0 commit comments