@@ -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
// returns basic hover/click/unhover runner for one xy position
@@ -157,19 +152,19 @@ describe('Test hover and click interactions', function() {
157
152
makeUnhoverFn ( gd , pos [ 0 ] , pos [ 1 ] ) ;
158
153
159
154
return function ( ) {
160
- return wait ( )
155
+ return delay ( 100 ) ( )
161
156
. then ( _hover )
162
157
. then ( function ( eventData ) {
163
- assertEventData ( eventData , expected ) ;
164
- assertHoverLabelStyle ( d3 . select ( 'g.hovertext' ) , expected ) ;
158
+ assertEventData ( eventData , expected , opts . msg ) ;
159
+ assertHoverLabelStyle ( d3 . select ( 'g.hovertext' ) , expected , opts . msg ) ;
165
160
} )
166
161
. then ( _click )
167
162
. then ( function ( eventData ) {
168
- assertEventData ( eventData , expected ) ;
163
+ assertEventData ( eventData , expected , opts . msg ) ;
169
164
} )
170
165
. then ( _unhover )
171
166
. then ( function ( eventData ) {
172
- expect ( eventData ) . toEqual ( 'emitted plotly_unhover' ) ;
167
+ expect ( eventData ) . toBe ( 'emitted plotly_unhover' , opts . msg ) ;
173
168
} ) ;
174
169
} ;
175
170
}
@@ -211,6 +206,8 @@ describe('Test hover and click interactions', function() {
211
206
fontSize : 20 ,
212
207
fontFamily : 'Arial' ,
213
208
fontColor : 'rgb(255, 255, 0)'
209
+ } , {
210
+ msg : 'scattergl'
214
211
} ) ;
215
212
216
213
Plotly . plot ( gd , _mock )
@@ -229,6 +226,8 @@ describe('Test hover and click interactions', function() {
229
226
curveNumber : 0 ,
230
227
pointNumber : 33 ,
231
228
noHoverLabel : true
229
+ } , {
230
+ msg : 'scattergl with hoverinfo'
232
231
} ) ;
233
232
234
233
Plotly . plot ( gd , _mock )
@@ -255,6 +254,8 @@ describe('Test hover and click interactions', function() {
255
254
fontSize : 8 ,
256
255
fontFamily : 'Arial' ,
257
256
fontColor : 'rgb(255, 255, 255)'
257
+ } , {
258
+ msg : 'pointcloud'
258
259
} ) ;
259
260
260
261
Plotly . plot ( gd , _mock )
@@ -286,7 +287,8 @@ describe('Test hover and click interactions', function() {
286
287
fontFamily : 'Roboto' ,
287
288
fontColor : 'rgb(255, 255, 255)'
288
289
} , {
289
- noUnHover : true
290
+ noUnHover : true ,
291
+ msg : 'heatmapgl'
290
292
} ) ;
291
293
292
294
Plotly . plot ( gd , _mock )
@@ -308,6 +310,8 @@ describe('Test hover and click interactions', function() {
308
310
fontSize : 13 ,
309
311
fontFamily : 'Arial' ,
310
312
fontColor : 'rgb(255, 255, 255)'
313
+ } , {
314
+ msg : 'scattergl before visibility restyle'
311
315
} ) ;
312
316
313
317
// after the restyle, autorange changes the y range
@@ -321,6 +325,8 @@ describe('Test hover and click interactions', function() {
321
325
fontSize : 13 ,
322
326
fontFamily : 'Arial' ,
323
327
fontColor : 'rgb(68, 68, 68)'
328
+ } , {
329
+ msg : 'scattergl after visibility restyle'
324
330
} ) ;
325
331
326
332
Plotly . plot ( gd , _mock )
@@ -349,6 +355,8 @@ describe('Test hover and click interactions', function() {
349
355
fontSize : 13 ,
350
356
fontFamily : 'Arial' ,
351
357
fontColor : 'rgb(255, 255, 255)'
358
+ } , {
359
+ msg : 'scattergl fancy before visibility restyle'
352
360
} ) ;
353
361
354
362
// after the restyle, autorange changes the x AND y ranges
@@ -365,6 +373,8 @@ describe('Test hover and click interactions', function() {
365
373
fontSize : 13 ,
366
374
fontFamily : 'Arial' ,
367
375
fontColor : 'rgb(68, 68, 68)'
376
+ } , {
377
+ msg : 'scattergl fancy after visibility restyle'
368
378
} ) ;
369
379
370
380
Plotly . plot ( gd , _mock )
@@ -395,7 +405,8 @@ describe('Test hover and click interactions', function() {
395
405
fontFamily : 'Arial' ,
396
406
fontColor : 'rgb(255, 255, 255)'
397
407
} , {
398
- noUnHover : true
408
+ noUnHover : true ,
409
+ msg : 'contourgl'
399
410
} ) ;
400
411
401
412
Plotly . plot ( gd , _mock )
0 commit comments