@@ -12,6 +12,7 @@ var fail = require('../assets/fail_test.js');
12
12
// a click event on mouseup
13
13
var click = require ( '../assets/timed_click' ) ;
14
14
var hover = require ( '../assets/hover' ) ;
15
+ var delay = require ( '../assets/delay' ) ;
15
16
16
17
// contourgl is not part of the dist plotly.js bundle initially
17
18
Plotly . register ( [
@@ -62,13 +63,6 @@ var mock4 = {
62
63
describe ( 'Test hover and click interactions' , function ( ) {
63
64
var gd ;
64
65
65
- // need to wait a little bit before canvas can properly catch mouse events
66
- function wait ( ) {
67
- return new Promise ( function ( resolve ) {
68
- setTimeout ( resolve , 100 ) ;
69
- } ) ;
70
- }
71
-
72
66
function makeHoverFn ( gd , x , y ) {
73
67
return function ( ) {
74
68
return new Promise ( function ( resolve ) {
@@ -90,26 +84,27 @@ describe('Test hover and click interactions', function() {
90
84
function makeUnhoverFn ( gd , x0 , y0 ) {
91
85
return function ( ) {
92
86
return new Promise ( function ( resolve ) {
93
- var eventData = null ;
94
-
95
- gd . on ( 'plotly_unhover' , function ( ) {
96
- eventData = 'emitted plotly_unhover' ;
97
- } ) ;
98
-
99
87
// fairly realistic simulation of moving with the cursor
100
88
var canceler = setInterval ( function ( ) {
101
- hover ( x0 -- , y0 -- ) ;
89
+ x0 -= 2 ;
90
+ y0 -= 2 ;
91
+ hover ( x0 , y0 ) ;
102
92
} , 10 ) ;
103
93
94
+ gd . on ( 'plotly_unhover' , function ( ) {
95
+ clearInterval ( canceler ) ;
96
+ resolve ( 'emitted plotly_unhover' ) ;
97
+ } ) ;
98
+
104
99
setTimeout ( function ( ) {
105
100
clearInterval ( canceler ) ;
106
- resolve ( eventData ) ;
101
+ resolve ( null ) ;
107
102
} , 350 ) ;
108
103
} ) ;
109
104
} ;
110
105
}
111
106
112
- function assertEventData ( actual , expected ) {
107
+ function assertEventData ( actual , expected , msg ) {
113
108
expect ( actual . points . length ) . toEqual ( 1 , 'points length' ) ;
114
109
115
110
var pt = actual . points [ 0 ] ;
@@ -119,30 +114,30 @@ describe('Test hover and click interactions', function() {
119
114
'data' , 'fullData' , 'xaxis' , 'yaxis'
120
115
] , 'event data keys' ) ;
121
116
122
- expect ( typeof pt . data . uid ) . toEqual ( 'string' , ' uid') ;
123
- expect ( pt . xaxis . domain . length ) . toEqual ( 2 , ' xaxis') ;
124
- expect ( pt . yaxis . domain . length ) . toEqual ( 2 , ' yaxis') ;
117
+ expect ( typeof pt . data . uid ) . toBe ( 'string' , msg + ' - uid') ;
118
+ expect ( pt . xaxis . domain . length ) . toBe ( 2 , msg + ' - xaxis') ;
119
+ expect ( pt . yaxis . domain . length ) . toBe ( 2 , msg + ' - yaxis') ;
125
120
126
- expect ( pt . x ) . toEqual ( expected . x , ' x') ;
127
- expect ( pt . y ) . toEqual ( expected . y , ' y') ;
128
- expect ( pt . curveNumber ) . toEqual ( expected . curveNumber , ' curve number') ;
129
- expect ( pt . pointNumber ) . toEqual ( expected . pointNumber , ' point number') ;
121
+ expect ( pt . x ) . toBe ( expected . x , msg + ' - x') ;
122
+ expect ( pt . y ) . toBe ( expected . y , msg + ' - y') ;
123
+ expect ( pt . curveNumber ) . toBe ( expected . curveNumber , msg + ' - curve number') ;
124
+ expect ( String ( pt . pointNumber ) ) . toBe ( String ( expected . pointNumber ) , msg + ' - point number') ;
130
125
}
131
126
132
- function assertHoverLabelStyle ( sel , expected ) {
127
+ function assertHoverLabelStyle ( sel , expected , msg ) {
133
128
if ( sel . node ( ) === null ) {
134
129
expect ( expected . noHoverLabel ) . toBe ( true ) ;
135
130
return ;
136
131
}
137
132
138
133
var path = sel . select ( 'path' ) ;
139
- expect ( path . style ( 'fill' ) ) . toEqual ( expected . bgColor , ' bgcolor') ;
140
- expect ( path . style ( 'stroke' ) ) . toEqual ( expected . borderColor , ' bordercolor') ;
134
+ expect ( path . style ( 'fill' ) ) . toBe ( expected . bgColor , msg + ' - bgcolor') ;
135
+ expect ( path . style ( 'stroke' ) ) . toBe ( expected . borderColor , msg + ' - bordercolor') ;
141
136
142
137
var text = sel . select ( 'text.nums' ) ;
143
- expect ( parseInt ( text . style ( 'font-size' ) ) ) . toEqual ( expected . fontSize , ' font.size') ;
144
- expect ( text . style ( 'font-family' ) . split ( ',' ) [ 0 ] ) . toEqual ( expected . fontFamily , ' font.family') ;
145
- expect ( text . style ( 'fill' ) ) . toEqual ( expected . fontColor , ' font.color') ;
138
+ expect ( parseInt ( text . style ( 'font-size' ) ) ) . toBe ( expected . fontSize , msg + ' - font.size') ;
139
+ expect ( text . style ( 'font-family' ) . split ( ',' ) [ 0 ] ) . toBe ( expected . fontFamily , msg + ' - font.family') ;
140
+ expect ( text . style ( 'fill' ) ) . toBe ( expected . fontColor , msg + ' - font.color') ;
146
141
}
147
142
148
143
function assertHoveLabelContent ( expected ) {
@@ -176,20 +171,20 @@ describe('Test hover and click interactions', function() {
176
171
makeUnhoverFn ( gd , pos [ 0 ] , pos [ 1 ] ) ;
177
172
178
173
return function ( ) {
179
- return wait ( )
174
+ return delay ( 100 ) ( )
180
175
. then ( _hover )
181
176
. then ( function ( eventData ) {
182
177
assertEventData ( eventData , expected ) ;
183
- assertHoverLabelStyle ( d3 . select ( 'g.hovertext' ) , expected ) ;
178
+ assertHoverLabelStyle ( d3 . select ( 'g.hovertext' ) , expected , opts . msg ) ;
184
179
assertHoveLabelContent ( expected ) ;
185
180
} )
186
181
. then ( _click )
187
182
. then ( function ( eventData ) {
188
- assertEventData ( eventData , expected ) ;
183
+ assertEventData ( eventData , expected , opts . msg ) ;
189
184
} )
190
185
. then ( _unhover )
191
186
. then ( function ( eventData ) {
192
- expect ( eventData ) . toEqual ( 'emitted plotly_unhover' ) ;
187
+ expect ( eventData ) . toBe ( 'emitted plotly_unhover' , opts . msg ) ;
193
188
} ) ;
194
189
} ;
195
190
}
@@ -233,6 +228,8 @@ describe('Test hover and click interactions', function() {
233
228
fontSize : 20 ,
234
229
fontFamily : 'Arial' ,
235
230
fontColor : 'rgb(255, 255, 0)'
231
+ } , {
232
+ msg : 'scattergl'
236
233
} ) ;
237
234
238
235
Plotly . plot ( gd , _mock )
@@ -251,6 +248,8 @@ describe('Test hover and click interactions', function() {
251
248
curveNumber : 0 ,
252
249
pointNumber : 33 ,
253
250
noHoverLabel : true
251
+ } , {
252
+ msg : 'scattergl with hoverinfo'
254
253
} ) ;
255
254
256
255
Plotly . plot ( gd , _mock )
@@ -277,6 +276,8 @@ describe('Test hover and click interactions', function() {
277
276
fontSize : 8 ,
278
277
fontFamily : 'Arial' ,
279
278
fontColor : 'rgb(255, 255, 255)'
279
+ } , {
280
+ msg : 'pointcloud'
280
281
} ) ;
281
282
282
283
Plotly . plot ( gd , _mock )
@@ -308,7 +309,8 @@ describe('Test hover and click interactions', function() {
308
309
fontFamily : 'Roboto' ,
309
310
fontColor : 'rgb(255, 255, 255)'
310
311
} , {
311
- noUnHover : true
312
+ noUnHover : true ,
313
+ msg : 'heatmapgl'
312
314
} ) ;
313
315
314
316
Plotly . plot ( gd , _mock )
@@ -330,6 +332,8 @@ describe('Test hover and click interactions', function() {
330
332
fontSize : 13 ,
331
333
fontFamily : 'Arial' ,
332
334
fontColor : 'rgb(255, 255, 255)'
335
+ } , {
336
+ msg : 'scattergl before visibility restyle'
333
337
} ) ;
334
338
335
339
// after the restyle, autorange changes the y range
@@ -343,6 +347,8 @@ describe('Test hover and click interactions', function() {
343
347
fontSize : 13 ,
344
348
fontFamily : 'Arial' ,
345
349
fontColor : 'rgb(68, 68, 68)'
350
+ } , {
351
+ msg : 'scattergl after visibility restyle'
346
352
} ) ;
347
353
348
354
Plotly . plot ( gd , _mock )
@@ -371,6 +377,8 @@ describe('Test hover and click interactions', function() {
371
377
fontSize : 13 ,
372
378
fontFamily : 'Arial' ,
373
379
fontColor : 'rgb(255, 255, 255)'
380
+ } , {
381
+ msg : 'scattergl fancy before visibility restyle'
374
382
} ) ;
375
383
376
384
// after the restyle, autorange changes the x AND y ranges
@@ -387,6 +395,8 @@ describe('Test hover and click interactions', function() {
387
395
fontSize : 13 ,
388
396
fontFamily : 'Arial' ,
389
397
fontColor : 'rgb(68, 68, 68)'
398
+ } , {
399
+ msg : 'scattergl fancy after visibility restyle'
390
400
} ) ;
391
401
392
402
Plotly . plot ( gd , _mock )
@@ -417,7 +427,8 @@ describe('Test hover and click interactions', function() {
417
427
fontFamily : 'Arial' ,
418
428
fontColor : 'rgb(255, 255, 255)'
419
429
} , {
420
- noUnHover : true
430
+ noUnHover : true ,
431
+ msg : 'contourgl'
421
432
} ) ;
422
433
423
434
Plotly . plot ( gd , _mock )
0 commit comments