@@ -6,76 +6,49 @@ var createGraphDiv = require('../assets/create_graph_div');
6
6
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
7
7
var failTest = require ( '../assets/fail_test.js' ) ;
8
8
9
- // cartesian click events events use the hover data
10
- // from the mousemove events and then simulate
11
- // a click event on mouseup
12
9
var doubleClick = require ( '../assets/double_click' ) ;
13
10
var delay = require ( '../assets/delay' ) ;
14
11
var mouseEvent = require ( '../assets/mouse_event' ) ;
15
12
var readPixel = require ( '../assets/read_pixel' ) ;
16
13
17
- // contourgl is not part of the dist plotly.js bundle initially
18
- Plotly . register ( [
19
- require ( '@lib/contourgl' )
20
- ] ) ;
14
+ function drag ( gd , path ) {
15
+ var len = path . length ;
16
+ var el = d3 . select ( gd ) . select ( 'rect.nsewdrag' ) . node ( ) ;
17
+ var opts = { element : el } ;
21
18
22
- describe ( 'Test gl2d lasso/select:' , function ( ) {
23
- var mockFancy = require ( '@mocks/gl2d_14.json' ) ;
24
- delete mockFancy . layout . xaxis . autorange ;
25
- delete mockFancy . layout . yaxis . autorange ;
26
- mockFancy . layout . xaxis . range = [ - 2.951309064136961 , 2.0954721318818916 ] ;
27
- mockFancy . layout . yaxis . range = [ - 0.9248866483012275 , 1.3232607344525835 ] ;
19
+ Lib . clearThrottle ( ) ;
20
+ mouseEvent ( 'mousemove' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] , opts ) ;
21
+ mouseEvent ( 'mousedown' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] , opts ) ;
28
22
29
- var mockFast = Lib . extendDeep ( { } , mockFancy , {
30
- data : [ { mode : 'markers' } ] ,
31
- layout : {
32
- xaxis : {
33
- type : 'linear' ,
34
- range : [ - 3.869222222222223 , 73.55522222222223 ]
35
- } ,
36
- yaxis : {
37
- type : 'linear' ,
38
- range : [ - 0.7402222222222222 , 17.144222222222222 ]
39
- }
40
- }
23
+ path . slice ( 1 , len ) . forEach ( function ( pt ) {
24
+ Lib . clearThrottle ( ) ;
25
+ mouseEvent ( 'mousemove' , pt [ 0 ] , pt [ 1 ] , opts ) ;
41
26
} ) ;
42
27
28
+ mouseEvent ( 'mouseup' , path [ len - 1 ] [ 0 ] , path [ len - 1 ] [ 1 ] , opts ) ;
29
+ }
30
+
31
+ function select ( gd , path ) {
32
+ return new Promise ( function ( resolve , reject ) {
33
+ gd . once ( 'plotly_selected' , resolve ) ;
34
+ setTimeout ( function ( ) { reject ( 'did not trigger *plotly_selected*' ) ; } , 200 ) ;
35
+ drag ( gd , path ) ;
36
+ } ) ;
37
+ }
38
+
39
+ describe ( 'Test gl2d lasso/select:' , function ( ) {
43
40
var gd ;
44
41
var selectPath = [ [ 98 , 193 ] , [ 108 , 193 ] ] ;
45
42
var selectPath2 = [ [ 118 , 193 ] , [ 128 , 193 ] ] ;
46
43
var lassoPath = [ [ 316 , 171 ] , [ 318 , 239 ] , [ 335 , 243 ] , [ 328 , 169 ] ] ;
47
44
var lassoPath2 = [ [ 98 , 193 ] , [ 108 , 193 ] , [ 108 , 500 ] , [ 98 , 500 ] , [ 98 , 193 ] ] ;
48
45
49
- afterEach ( function ( ) {
46
+ afterEach ( function ( done ) {
50
47
Plotly . purge ( gd ) ;
51
48
destroyGraphDiv ( ) ;
49
+ setTimeout ( done , 500 ) ;
52
50
} ) ;
53
51
54
- function drag ( path ) {
55
- var len = path . length ;
56
- var el = d3 . select ( gd ) . select ( 'rect.nsewdrag' ) . node ( ) ;
57
- var opts = { element : el } ;
58
-
59
- Lib . clearThrottle ( ) ;
60
- mouseEvent ( 'mousemove' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] , opts ) ;
61
- mouseEvent ( 'mousedown' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] , opts ) ;
62
-
63
- path . slice ( 1 , len ) . forEach ( function ( pt ) {
64
- Lib . clearThrottle ( ) ;
65
- mouseEvent ( 'mousemove' , pt [ 0 ] , pt [ 1 ] , opts ) ;
66
- } ) ;
67
-
68
- mouseEvent ( 'mouseup' , path [ len - 1 ] [ 0 ] , path [ len - 1 ] [ 1 ] , opts ) ;
69
- }
70
-
71
- function select ( path ) {
72
- return new Promise ( function ( resolve , reject ) {
73
- gd . once ( 'plotly_selected' , resolve ) ;
74
- setTimeout ( function ( ) { reject ( 'did not trigger *plotly_selected*' ) ; } , 200 ) ;
75
- drag ( path ) ;
76
- } ) ;
77
- }
78
-
79
52
function assertEventData ( actual , expected ) {
80
53
expect ( actual . points . length ) . toBe ( expected . points . length ) ;
81
54
@@ -88,6 +61,27 @@ describe('Test gl2d lasso/select:', function() {
88
61
} ) ;
89
62
}
90
63
64
+ var mockFancy = require ( '@mocks/gl2d_14.json' ) ;
65
+ delete mockFancy . layout . xaxis . autorange ;
66
+ delete mockFancy . layout . yaxis . autorange ;
67
+ mockFancy . layout . xaxis . range = [ - 2.951309064136961 , 2.0954721318818916 ] ;
68
+ mockFancy . layout . yaxis . range = [ - 0.9248866483012275 , 1.3232607344525835 ] ;
69
+
70
+ var mockFast = Lib . extendDeep ( { } , mockFancy , {
71
+ data : [ { mode : 'markers' } ] ,
72
+ layout : {
73
+ xaxis : {
74
+ type : 'linear' ,
75
+ range : [ - 3.869222222222223 , 73.55522222222223 ]
76
+ } ,
77
+ yaxis : {
78
+ type : 'linear' ,
79
+ range : [ - 0.7402222222222222 , 17.144222222222222 ]
80
+ }
81
+ }
82
+ } ) ;
83
+
84
+
91
85
it ( '@gl should work under fast mode with *select* dragmode' , function ( done ) {
92
86
var _mock = Lib . extendDeep ( { } , mockFast ) ;
93
87
_mock . layout . dragmode = 'select' ;
@@ -98,7 +92,7 @@ describe('Test gl2d lasso/select:', function() {
98
92
. then ( function ( ) {
99
93
expect ( gd . _fullLayout . _plots . xy . _scene . select2d ) . not . toBe ( undefined , 'scatter2d renderer' ) ;
100
94
101
- return select ( selectPath ) ;
95
+ return select ( gd , selectPath ) ;
102
96
} )
103
97
. then ( delay ( 20 ) )
104
98
. then ( function ( eventData ) {
@@ -122,7 +116,7 @@ describe('Test gl2d lasso/select:', function() {
122
116
Plotly . plot ( gd , _mock )
123
117
. then ( delay ( 20 ) )
124
118
. then ( function ( ) {
125
- return select ( lassoPath2 ) ;
119
+ return select ( gd , lassoPath2 ) ;
126
120
} )
127
121
. then ( delay ( 20 ) )
128
122
. then ( function ( eventData ) {
@@ -146,7 +140,7 @@ describe('Test gl2d lasso/select:', function() {
146
140
Plotly . plot ( gd , _mock )
147
141
. then ( delay ( 20 ) )
148
142
. then ( function ( ) {
149
- return select ( selectPath2 ) ;
143
+ return select ( gd , selectPath2 ) ;
150
144
} )
151
145
. then ( delay ( 20 ) )
152
146
. then ( function ( eventData ) {
@@ -166,7 +160,7 @@ describe('Test gl2d lasso/select:', function() {
166
160
Plotly . plot ( gd , _mock )
167
161
. then ( delay ( 20 ) )
168
162
. then ( function ( ) {
169
- return select ( lassoPath ) ;
163
+ return select ( gd , lassoPath ) ;
170
164
} )
171
165
. then ( function ( eventData ) {
172
166
assertEventData ( eventData , {
@@ -187,7 +181,7 @@ describe('Test gl2d lasso/select:', function() {
187
181
188
182
Plotly . plot ( gd , fig )
189
183
. then ( delay ( 20 ) )
190
- . then ( function ( ) { return select ( [ [ 100 , 100 ] , [ 250 , 250 ] ] ) ; } )
184
+ . then ( function ( ) { return select ( gd , [ [ 100 , 100 ] , [ 250 , 250 ] ] ) ; } )
191
185
. then ( function ( eventData ) {
192
186
assertEventData ( eventData , {
193
187
points : [
@@ -227,7 +221,7 @@ describe('Test gl2d lasso/select:', function() {
227
221
]
228
222
} ) ;
229
223
} )
230
- . then ( function ( ) { return select ( [ [ 100 , 100 ] , [ 250 , 250 ] ] ) ; } )
224
+ . then ( function ( ) { return select ( gd , [ [ 100 , 100 ] , [ 250 , 250 ] ] ) ; } )
231
225
. then ( function ( eventData ) {
232
226
assertEventData ( eventData , {
233
227
points : [ { x : 1 , y : 2 } ]
@@ -256,7 +250,7 @@ describe('Test gl2d lasso/select:', function() {
256
250
. then ( function ( ) {
257
251
return Plotly . restyle ( gd , 'selected.textfont.color' , 'red' ) ;
258
252
} )
259
- . then ( function ( ) { return select ( [ [ 100 , 100 ] , [ 250 , 250 ] ] ) ; } )
253
+ . then ( function ( ) { return select ( gd , [ [ 100 , 100 ] , [ 250 , 250 ] ] ) ; } )
260
254
. then ( function ( ) {
261
255
_assertGlTextOpts ( 'after selection - with set selected.textfont.color' , {
262
256
rgba : [
@@ -317,7 +311,7 @@ describe('Test gl2d lasso/select:', function() {
317
311
]
318
312
} ) ;
319
313
} )
320
- . then ( function ( ) { return select ( [ [ 100 , 10 ] , [ 250 , 100 ] ] ) ; } )
314
+ . then ( function ( ) { return select ( gd , [ [ 100 , 10 ] , [ 250 , 100 ] ] ) ; } )
321
315
. then ( function ( eventData ) {
322
316
assertEventData ( eventData , {
323
317
points : [ { x : 1 , y : 2 } ]
@@ -341,7 +335,7 @@ describe('Test gl2d lasso/select:', function() {
341
335
. then ( function ( ) {
342
336
return Plotly . restyle ( gd , 'selected.textfont.color' , 'red' ) ;
343
337
} )
344
- . then ( function ( ) { return select ( [ [ 100 , 10 ] , [ 250 , 100 ] ] ) ; } )
338
+ . then ( function ( ) { return select ( gd , [ [ 100 , 10 ] , [ 250 , 100 ] ] ) ; } )
345
339
. then ( function ( ) {
346
340
_assertGlTextOpts ( 'after selection - with set selected.textfont.color' , {
347
341
rgba : [
@@ -362,10 +356,22 @@ describe('Test gl2d lasso/select:', function() {
362
356
. catch ( failTest )
363
357
. then ( done ) ;
364
358
} ) ;
359
+ } ) ;
365
360
366
- it ( '@gl should work after a width/height relayout' , function ( done ) {
361
+ describe ( 'Test displayed selections:' , function ( ) {
362
+ var gd ;
363
+
364
+ beforeEach ( function ( ) {
367
365
gd = createGraphDiv ( ) ;
366
+ } ) ;
367
+
368
+ afterEach ( function ( done ) {
369
+ Plotly . purge ( gd ) ;
370
+ destroyGraphDiv ( ) ;
371
+ setTimeout ( done , 500 ) ;
372
+ } ) ;
368
373
374
+ it ( '@gl should work after a width/height relayout' , function ( done ) {
369
375
var w = 500 ;
370
376
var h = 500 ;
371
377
var w2 = 800 ;
@@ -396,7 +402,7 @@ describe('Test gl2d lasso/select:', function() {
396
402
expect ( readContext ( ) ) . toBeGreaterThan ( 1e4 , 'base context' ) ;
397
403
expect ( readFocus ( ) ) . toBe ( 0 , 'base focus' ) ;
398
404
} )
399
- . then ( function ( ) { return select ( [ [ pad , pad ] , [ w - pad , h - pad ] ] ) ; } )
405
+ . then ( function ( ) { return select ( gd , [ [ pad , pad ] , [ w - pad , h - pad ] ] ) ; } )
400
406
. then ( function ( ) {
401
407
expect ( readContext ( ) ) . toBe ( 0 , 'select context' ) ;
402
408
expect ( readFocus ( ) ) . toBeGreaterThan ( 1e4 , 'select focus' ) ;
@@ -411,7 +417,7 @@ describe('Test gl2d lasso/select:', function() {
411
417
expect ( readContext ( ) ) . toBeGreaterThan ( 1e4 , 'update context' ) ;
412
418
expect ( readFocus ( ) ) . toBe ( 0 , 'update focus' ) ;
413
419
} )
414
- . then ( function ( ) { return select ( [ [ pad , pad ] , [ w2 - pad , h2 - pad ] ] ) ; } )
420
+ . then ( function ( ) { return select ( gd , [ [ pad , pad ] , [ w2 - pad , h2 - pad ] ] ) ; } )
415
421
. then ( function ( ) {
416
422
// make sure full w2/h2 context canvas is cleared!
417
423
// from https://github.com/plotly/plotly.js/issues/2731<Paste>
@@ -422,6 +428,92 @@ describe('Test gl2d lasso/select:', function() {
422
428
. then ( done ) ;
423
429
} ) ;
424
430
431
+ it ( '@gl should display selection of big number of regular points' , function ( done ) {
432
+ // generate large number of points
433
+ var x = [ ] ;
434
+ var y = [ ] ;
435
+ var n = 2e2 ;
436
+ var N = n * n ;
437
+ for ( var i = 0 ; i < N ; i ++ ) {
438
+ x . push ( ( i % n ) / n ) ;
439
+ y . push ( i / N ) ;
440
+ }
441
+
442
+ var mock = {
443
+ data : [ {
444
+ x : x , y : y , type : 'scattergl' , mode : 'markers'
445
+ } ] ,
446
+ layout : {
447
+ dragmode : 'select'
448
+ }
449
+ } ;
450
+
451
+ Plotly . plot ( gd , mock )
452
+ . then ( select ( gd , [ [ 160 , 100 ] , [ 180 , 100 ] ] ) )
453
+ . then ( function ( ) {
454
+ expect ( readPixel ( gd . querySelector ( '.gl-canvas-context' ) , 168 , 100 ) [ 3 ] ) . toBe ( 0 ) ;
455
+ expect ( readPixel ( gd . querySelector ( '.gl-canvas-context' ) , 158 , 100 ) [ 3 ] ) . not . toBe ( 0 ) ;
456
+ expect ( readPixel ( gd . querySelector ( '.gl-canvas-focus' ) , 168 , 100 ) [ 3 ] ) . not . toBe ( 0 ) ;
457
+ } )
458
+ . catch ( failTest )
459
+ . then ( done ) ;
460
+ } ) ;
461
+
462
+ it ( '@gl should display selection of big number of miscellaneous points' , function ( done ) {
463
+ var colorList = [
464
+ '#006385' , '#F06E75' , '#90ed7d' , '#f7a35c' , '#8085e9' ,
465
+ '#f15c80' , '#e4d354' , '#2b908f' , '#f45b5b' , '#91e8e1' ,
466
+ '#5DA5DA' , '#F06E75' , '#F15854' , '#B2912F' , '#B276B2' ,
467
+ '#DECF3F' , '#FAA43A' , '#4D4D4D' , '#F17CB0' , '#60BD68'
468
+ ] ;
469
+
470
+ // generate large number of points
471
+ var x = [ ] ;
472
+ var y = [ ] ;
473
+ var n = 2e2 ;
474
+ var N = n * n ;
475
+ var color = [ ] ;
476
+ var symbol = [ ] ;
477
+ var size = [ ] ;
478
+ for ( var i = 0 ; i < N ; i ++ ) {
479
+ x . push ( ( i % n ) / n ) ;
480
+ y . push ( i / N ) ;
481
+ color . push ( colorList [ i % colorList . length ] ) ;
482
+ symbol . push ( 'x' ) ;
483
+ size . push ( 6 ) ;
484
+ }
485
+
486
+ var mock = {
487
+ data : [ {
488
+ x : x , y : y , type : 'scattergl' , mode : 'markers' ,
489
+ marker : { symbol : symbol , size : size , color : color }
490
+ } ] ,
491
+ layout : {
492
+ dragmode : 'select'
493
+ }
494
+ } ;
495
+
496
+ Plotly . plot ( gd , mock )
497
+ . then ( select ( gd , [ [ 160 , 100 ] , [ 180 , 100 ] ] ) )
498
+ . then ( function ( ) {
499
+ expect ( readPixel ( gd . querySelector ( '.gl-canvas-context' ) , 168 , 100 ) [ 3 ] ) . toBe ( 0 ) ;
500
+ expect ( readPixel ( gd . querySelector ( '.gl-canvas-context' ) , 158 , 100 ) [ 3 ] ) . not . toBe ( 0 ) ;
501
+ expect ( readPixel ( gd . querySelector ( '.gl-canvas-focus' ) , 168 , 100 ) [ 3 ] ) . not . toBe ( 0 ) ;
502
+ } )
503
+ . catch ( failTest )
504
+ . then ( done ) ;
505
+ } ) ;
506
+ } ) ;
507
+
508
+ describe ( 'Test selections during funky scenarios' , function ( ) {
509
+ var gd ;
510
+
511
+ afterEach ( function ( done ) {
512
+ Plotly . purge ( gd ) ;
513
+ destroyGraphDiv ( ) ;
514
+ setTimeout ( done , 500 ) ;
515
+ } ) ;
516
+
425
517
function grabScene ( ) {
426
518
return gd . calcdata [ 0 ] [ 0 ] . t . _scene ;
427
519
}
@@ -514,7 +606,7 @@ describe('Test gl2d lasso/select:', function() {
514
606
drawArgs : [ ]
515
607
} ) ;
516
608
} )
517
- . then ( function ( ) { return select ( [ [ 20 , 20 ] , [ 480 , 250 ] ] ) ; } )
609
+ . then ( function ( ) { return select ( gd , [ [ 20 , 20 ] , [ 480 , 250 ] ] ) ; } )
518
610
. then ( function ( ) {
519
611
var scene = grabScene ( ) ;
520
612
_assert ( 'after select' , {
@@ -556,7 +648,7 @@ describe('Test gl2d lasso/select:', function() {
556
648
drawArgs : [ ]
557
649
} ) ;
558
650
} )
559
- . then ( function ( ) { return drag ( [ [ 200 , 200 ] , [ 250 , 250 ] ] ) ; } )
651
+ . then ( function ( ) { return drag ( gd , [ [ 200 , 200 ] , [ 250 , 250 ] ] ) ; } )
560
652
. then ( function ( ) {
561
653
var scene = grabScene ( ) ;
562
654
_assert ( 'after pan' , {
@@ -652,7 +744,7 @@ describe('Test gl2d lasso/select:', function() {
652
744
drawArgs : [ ]
653
745
} ) ;
654
746
} )
655
- . then ( function ( ) { return select ( [ [ 20 , 20 ] , [ 480 , 250 ] ] ) ; } )
747
+ . then ( function ( ) { return select ( gd , [ [ 20 , 20 ] , [ 480 , 250 ] ] ) ; } )
656
748
. then ( function ( ) { return doubleClick ( 250 , 250 ) ; } )
657
749
. then ( function ( ) { return Plotly . relayout ( gd , 'dragmode' , 'pan' ) ; } )
658
750
. then ( function ( ) { return Plotly . relayout ( gd , 'dragmode' , 'select' ) ; } )
@@ -738,7 +830,7 @@ describe('Test gl2d lasso/select:', function() {
738
830
[ 'select2d' , [ [ [ ] , [ ] ] ] ]
739
831
] ) ;
740
832
} )
741
- . then ( function ( ) { return select ( [ [ 20 , 20 ] , [ 480 , 250 ] ] ) ; } )
833
+ . then ( function ( ) { return select ( gd , [ [ 20 , 20 ] , [ 480 , 250 ] ] ) ; } )
742
834
. then ( function ( ) {
743
835
_assert ( 'on selection' , [
744
836
[ 'scatter2d' , [ [ [ 0 , 2 ] , [ ] ] ] ] ,
@@ -791,7 +883,7 @@ describe('Test gl2d lasso/select:', function() {
791
883
spyOn ( scene . scatter2d , 'draw' ) ;
792
884
spyOn ( scene2 . scatter2d , 'draw' ) ;
793
885
} )
794
- . then ( function ( ) { return select ( [ [ 20 , 20 ] , [ 380 , 250 ] ] ) ; } )
886
+ . then ( function ( ) { return select ( gd , [ [ 20 , 20 ] , [ 380 , 250 ] ] ) ; } )
795
887
. then ( function ( ) {
796
888
expect ( scene . scatter2d . draw ) . toHaveBeenCalledTimes ( 1 ) ;
797
889
expect ( scene2 . scatter2d . draw ) . toHaveBeenCalledTimes ( 1 ) ;
0 commit comments