@@ -16,6 +16,30 @@ var customMatchers = require('../assets/custom_matchers');
16
16
var click = require ( '../assets/click' ) ;
17
17
var doubleClickRaw = require ( '../assets/double_click' ) ;
18
18
19
+ function move ( fromX , fromY , toX , toY , delay ) {
20
+ return new Promise ( function ( resolve ) {
21
+ mouseEvent ( 'mousemove' , fromX , fromY ) ;
22
+
23
+ setTimeout ( function ( ) {
24
+ mouseEvent ( 'mousemove' , toX , toY ) ;
25
+ resolve ( ) ;
26
+ } , delay || DBLCLICKDELAY / 4 ) ;
27
+ } ) ;
28
+ }
29
+
30
+ function drag ( fromX , fromY , toX , toY , delay ) {
31
+ return new Promise ( function ( resolve ) {
32
+ mouseEvent ( 'mousemove' , fromX , fromY ) ;
33
+ mouseEvent ( 'mousedown' , fromX , fromY ) ;
34
+ mouseEvent ( 'mousemove' , toX , toY ) ;
35
+
36
+ setTimeout ( function ( ) {
37
+ mouseEvent ( 'mouseup' , toX , toY ) ;
38
+ resolve ( ) ;
39
+ } , delay || DBLCLICKDELAY / 4 ) ;
40
+ } ) ;
41
+ }
42
+
19
43
20
44
describe ( 'Test click interactions:' , function ( ) {
21
45
var mock = require ( '@mocks/14.json' ) ;
@@ -39,19 +63,6 @@ describe('Test click interactions:', function() {
39
63
40
64
afterEach ( destroyGraphDiv ) ;
41
65
42
- function drag ( fromX , fromY , toX , toY , delay ) {
43
- return new Promise ( function ( resolve ) {
44
- mouseEvent ( 'mousemove' , fromX , fromY ) ;
45
- mouseEvent ( 'mousedown' , fromX , fromY ) ;
46
- mouseEvent ( 'mousemove' , toX , toY ) ;
47
-
48
- setTimeout ( function ( ) {
49
- mouseEvent ( 'mouseup' , toX , toY ) ;
50
- resolve ( ) ;
51
- } , delay || DBLCLICKDELAY / 4 ) ;
52
- } ) ;
53
- }
54
-
55
66
function doubleClick ( x , y ) {
56
67
return doubleClickRaw ( x , y ) . then ( function ( ) {
57
68
return Plotly . Plots . previousPromises ( gd ) ;
@@ -87,6 +98,55 @@ describe('Test click interactions:', function() {
87
98
expect ( pt . pointNumber ) . toEqual ( 11 ) ;
88
99
expect ( pt . x ) . toEqual ( 0.125 ) ;
89
100
expect ( pt . y ) . toEqual ( 2.125 ) ;
101
+
102
+ var evt = futureData . event ;
103
+ expect ( evt . clientX ) . toEqual ( pointPos [ 0 ] ) ;
104
+ expect ( evt . clientY ) . toEqual ( pointPos [ 1 ] ) ;
105
+ } ) ;
106
+ } ) ;
107
+
108
+ describe ( 'modified click events' , function ( ) {
109
+ var clickOpts = {
110
+ altKey : true ,
111
+ ctrlKey : true ,
112
+ metaKey : true ,
113
+ shiftKey : true
114
+ } ,
115
+ futureData ;
116
+
117
+ beforeEach ( function ( done ) {
118
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( done ) ;
119
+
120
+ gd . on ( 'plotly_click' , function ( data ) {
121
+ futureData = data ;
122
+ } ) ;
123
+ } ) ;
124
+
125
+ it ( 'should not be trigged when not on data points' , function ( ) {
126
+ click ( blankPos [ 0 ] , blankPos [ 1 ] , clickOpts ) ;
127
+ expect ( futureData ) . toBe ( undefined ) ;
128
+ } ) ;
129
+
130
+ it ( 'should contain the correct fields' , function ( ) {
131
+ click ( pointPos [ 0 ] , pointPos [ 1 ] , clickOpts ) ;
132
+ expect ( futureData . points . length ) . toEqual ( 1 ) ;
133
+
134
+ var pt = futureData . points [ 0 ] ;
135
+ expect ( Object . keys ( pt ) ) . toEqual ( [
136
+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber' ,
137
+ 'x' , 'y' , 'xaxis' , 'yaxis'
138
+ ] ) ;
139
+ expect ( pt . curveNumber ) . toEqual ( 0 ) ;
140
+ expect ( pt . pointNumber ) . toEqual ( 11 ) ;
141
+ expect ( pt . x ) . toEqual ( 0.125 ) ;
142
+ expect ( pt . y ) . toEqual ( 2.125 ) ;
143
+
144
+ var evt = futureData . event ;
145
+ expect ( evt . clientX ) . toEqual ( pointPos [ 0 ] ) ;
146
+ expect ( evt . clientY ) . toEqual ( pointPos [ 1 ] ) ;
147
+ Object . getOwnPropertyNames ( clickOpts ) . forEach ( function ( opt ) {
148
+ expect ( evt [ opt ] ) . toEqual ( clickOpts [ opt ] , opt ) ;
149
+ } ) ;
90
150
} ) ;
91
151
} ) ;
92
152
@@ -191,6 +251,46 @@ describe('Test click interactions:', function() {
191
251
expect ( pt . pointNumber ) . toEqual ( 11 ) ;
192
252
expect ( pt . x ) . toEqual ( 0.125 ) ;
193
253
expect ( pt . y ) . toEqual ( 2.125 ) ;
254
+
255
+ var evt = futureData . event ;
256
+ expect ( evt . clientX ) . toEqual ( pointPos [ 0 ] ) ;
257
+ expect ( evt . clientY ) . toEqual ( pointPos [ 1 ] ) ;
258
+ } ) ;
259
+ } ) ;
260
+
261
+ describe ( 'plotly_unhover event with hoverinfo set to none' , function ( ) {
262
+ var futureData ;
263
+
264
+ beforeEach ( function ( done ) {
265
+
266
+ var modifiedMockCopy = Lib . extendDeep ( { } , mockCopy ) ;
267
+ modifiedMockCopy . data [ 0 ] . hoverinfo = 'none' ;
268
+ Plotly . plot ( gd , modifiedMockCopy . data , modifiedMockCopy . layout )
269
+ . then ( done ) ;
270
+
271
+ gd . on ( 'plotly_unhover' , function ( data ) {
272
+ futureData = data ;
273
+ } ) ;
274
+ } ) ;
275
+
276
+ it ( 'should contain the correct fields despite hoverinfo: "none"' , function ( done ) {
277
+ move ( pointPos [ 0 ] , pointPos [ 1 ] , blankPos [ 0 ] , blankPos [ 1 ] ) . then ( function ( ) {
278
+ expect ( futureData . points . length ) . toEqual ( 1 ) ;
279
+
280
+ var pt = futureData . points [ 0 ] ;
281
+ expect ( Object . keys ( pt ) ) . toEqual ( [
282
+ 'data' , 'fullData' , 'curveNumber' , 'pointNumber' ,
283
+ 'x' , 'y' , 'xaxis' , 'yaxis'
284
+ ] ) ;
285
+ expect ( pt . curveNumber ) . toEqual ( 0 ) ;
286
+ expect ( pt . pointNumber ) . toEqual ( 11 ) ;
287
+ expect ( pt . x ) . toEqual ( 0.125 ) ;
288
+ expect ( pt . y ) . toEqual ( 2.125 ) ;
289
+
290
+ var evt = futureData . event ;
291
+ expect ( evt . clientX ) . toEqual ( blankPos [ 0 ] ) ;
292
+ expect ( evt . clientY ) . toEqual ( blankPos [ 1 ] ) ;
293
+ } ) . then ( done ) ;
194
294
} ) ;
195
295
} ) ;
196
296
@@ -817,6 +917,7 @@ describe('Test click interactions:', function() {
817
917
} ) ;
818
918
} ) ;
819
919
920
+
820
921
describe ( 'dragbox' , function ( ) {
821
922
822
923
afterEach ( destroyGraphDiv ) ;
0 commit comments