@@ -5,11 +5,11 @@ var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;
5
5
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
6
6
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
7
7
var mouseEvent = require ( '../assets/mouse_event' ) ;
8
+ var customMatchers = require ( '../assets/custom_matchers' ) ;
8
9
9
10
10
11
describe ( 'click interactions' , function ( ) {
11
12
var mock = require ( '@mocks/14.json' ) ,
12
- mockCopy = Lib . extendDeep ( { } , mock ) ,
13
13
gd ;
14
14
15
15
var pointPos = [ 351 , 223 ] ,
@@ -34,17 +34,16 @@ describe('click interactions', function() {
34
34
} , DBLCLICKDELAY / 2 ) ;
35
35
}
36
36
37
- beforeEach ( function ( done ) {
38
- gd = createGraphDiv ( ) ;
39
-
40
- Plotly . plot ( gd , mockCopy . data , mockCopy . layout )
41
- . then ( done ) ;
42
- } ) ;
43
-
44
37
describe ( 'click events' , function ( ) {
45
38
var futureData ;
46
39
47
- beforeEach ( function ( ) {
40
+ beforeEach ( function ( done ) {
41
+ gd = createGraphDiv ( ) ;
42
+
43
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
44
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout )
45
+ . then ( done ) ;
46
+
48
47
gd . on ( 'plotly_click' , function ( data ) {
49
48
futureData = data ;
50
49
} ) ;
@@ -74,10 +73,17 @@ describe('click interactions', function() {
74
73
describe ( 'double click events' , function ( ) {
75
74
var futureData ;
76
75
77
- beforeEach ( function ( ) {
76
+ beforeEach ( function ( done ) {
77
+ gd = createGraphDiv ( ) ;
78
+
79
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
80
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout )
81
+ . then ( done ) ;
82
+
78
83
gd . on ( 'plotly_doubleclick' , function ( data ) {
79
84
futureData = data ;
80
85
} ) ;
86
+
81
87
} ) ;
82
88
83
89
it ( 'should return null' , function ( done ) {
@@ -87,4 +93,215 @@ describe('click interactions', function() {
87
93
} ) ;
88
94
} ) ;
89
95
} ) ;
96
+
97
+ describe ( 'double click interactions' , function ( ) {
98
+ var mockCopy ;
99
+
100
+ var autoRangeX = [ - 3.011967491973726 , 2.1561305597186564 ] ,
101
+ autoRangeY = [ - 0.9910086301469277 , 1.389382716298284 ] ;
102
+
103
+ var setRangeX = [ - 3 , 1 ] ,
104
+ setRangeY = [ - 0.5 , 1 ] ;
105
+
106
+ var zoomRangeX = [ - 2 , 0 ] ,
107
+ zoomRangeY = [ 0 , 0.5 ] ;
108
+
109
+ var update = {
110
+ 'xaxis.range[0]' : zoomRangeX [ 0 ] ,
111
+ 'xaxis.range[1]' : zoomRangeX [ 1 ] ,
112
+ 'yaxis.range[0]' : zoomRangeY [ 0 ] ,
113
+ 'yaxis.range[1]' : zoomRangeY [ 1 ]
114
+ } ;
115
+
116
+ beforeEach ( function ( ) {
117
+ jasmine . addMatchers ( customMatchers ) ;
118
+
119
+ gd = createGraphDiv ( ) ;
120
+ mockCopy = Lib . extendDeep ( { } , mock ) ;
121
+ } ) ;
122
+
123
+ function setRanges ( mockCopy ) {
124
+ mockCopy . layout . xaxis . autorange = false ;
125
+ mockCopy . layout . xaxis . range = setRangeX . slice ( ) ;
126
+
127
+ mockCopy . layout . yaxis . autorange = false ;
128
+ mockCopy . layout . yaxis . range = setRangeY . slice ( ) ;
129
+
130
+ return mockCopy ;
131
+ }
132
+
133
+ it ( 'when set to \'reset+autorange\' (the default) should work when \'autorange\' is on' , function ( done ) {
134
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
135
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( autoRangeX ) ;
136
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( autoRangeY ) ;
137
+
138
+ Plotly . relayout ( gd , update ) . then ( function ( ) {
139
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( zoomRangeX ) ;
140
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( zoomRangeY ) ;
141
+
142
+ doubleClick ( blankPos [ 0 ] , blankPos [ 1 ] , function ( ) {
143
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( autoRangeX ) ;
144
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( autoRangeY ) ;
145
+
146
+ done ( ) ;
147
+ } ) ;
148
+ } ) ;
149
+ } ) ;
150
+ } ) ;
151
+
152
+ it ( 'when set to \'reset+autorange\' (the default) should reset to set range on double click' , function ( done ) {
153
+ mockCopy = setRanges ( mockCopy ) ;
154
+
155
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
156
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( setRangeX ) ;
157
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( setRangeY ) ;
158
+
159
+ Plotly . relayout ( gd , update ) . then ( function ( ) {
160
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( zoomRangeX ) ;
161
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( zoomRangeY ) ;
162
+
163
+ doubleClick ( blankPos [ 0 ] , blankPos [ 1 ] , function ( ) {
164
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( setRangeX ) ;
165
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( setRangeY ) ;
166
+
167
+ done ( ) ;
168
+ } ) ;
169
+ } ) ;
170
+ } ) ;
171
+ } ) ;
172
+
173
+ it ( 'when set to \'reset+autorange\' (the default) should autosize on 1st double click and reset on 2nd' , function ( done ) {
174
+ mockCopy = setRanges ( mockCopy ) ;
175
+
176
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
177
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( setRangeX ) ;
178
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( setRangeY ) ;
179
+
180
+ doubleClick ( blankPos [ 0 ] , blankPos [ 1 ] , function ( ) {
181
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( autoRangeX ) ;
182
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( autoRangeY ) ;
183
+
184
+ doubleClick ( blankPos [ 0 ] , blankPos [ 1 ] , function ( ) {
185
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( setRangeX ) ;
186
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( setRangeY ) ;
187
+
188
+ done ( ) ;
189
+ } ) ;
190
+ } ) ;
191
+ } ) ;
192
+ } ) ;
193
+
194
+ it ( 'when set to \'reset\' should work when \'autorange\' is on' , function ( done ) {
195
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout , { doubleClick : 'reset' } ) . then ( function ( ) {
196
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( autoRangeX ) ;
197
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( autoRangeY ) ;
198
+
199
+ Plotly . relayout ( gd , update ) . then ( function ( ) {
200
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( zoomRangeX ) ;
201
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( zoomRangeY ) ;
202
+
203
+ doubleClick ( blankPos [ 0 ] , blankPos [ 1 ] , function ( ) {
204
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( autoRangeX ) ;
205
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( autoRangeY ) ;
206
+
207
+ done ( ) ;
208
+ } ) ;
209
+ } ) ;
210
+ } ) ;
211
+ } ) ;
212
+
213
+ it ( 'when set to \'reset\' should reset to set range on double click' , function ( done ) {
214
+ mockCopy = setRanges ( mockCopy ) ;
215
+
216
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout , { doubleClick : 'reset' } ) . then ( function ( ) {
217
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( setRangeX ) ;
218
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( setRangeY ) ;
219
+
220
+ Plotly . relayout ( gd , update ) . then ( function ( ) {
221
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( zoomRangeX ) ;
222
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( zoomRangeY ) ;
223
+
224
+ doubleClick ( blankPos [ 0 ] , blankPos [ 1 ] , function ( ) {
225
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( setRangeX ) ;
226
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( setRangeY ) ;
227
+
228
+ done ( ) ;
229
+ } ) ;
230
+ } ) ;
231
+ } ) ;
232
+ } ) ;
233
+
234
+ it ( 'when set to \'reset\' should reset on all double clicks' , function ( done ) {
235
+ mockCopy = setRanges ( mockCopy ) ;
236
+
237
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout , { doubleClick : 'reset' } ) . then ( function ( ) {
238
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( setRangeX ) ;
239
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( setRangeY ) ;
240
+
241
+ doubleClick ( blankPos [ 0 ] , blankPos [ 1 ] , function ( ) {
242
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( setRangeX ) ;
243
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( setRangeY ) ;
244
+
245
+ done ( ) ;
246
+ } ) ;
247
+ } ) ;
248
+ } ) ;
249
+
250
+ it ( 'when set to \'autosize\' should work when \'autorange\' is on' , function ( done ) {
251
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout , { doubleClick : 'autosize' } ) . then ( function ( ) {
252
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( autoRangeX ) ;
253
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( autoRangeY ) ;
254
+
255
+ Plotly . relayout ( gd , update ) . then ( function ( ) {
256
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( zoomRangeX ) ;
257
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( zoomRangeY ) ;
258
+
259
+ doubleClick ( blankPos [ 0 ] , blankPos [ 1 ] , function ( ) {
260
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( autoRangeX ) ;
261
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( autoRangeY ) ;
262
+
263
+ done ( ) ;
264
+ } ) ;
265
+ } ) ;
266
+ } ) ;
267
+ } ) ;
268
+
269
+ it ( 'when set to \'autosize\' should set to autorange on double click' , function ( done ) {
270
+ mockCopy = setRanges ( mockCopy ) ;
271
+
272
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout , { doubleClick : 'autosize' } ) . then ( function ( ) {
273
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( setRangeX ) ;
274
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( setRangeY ) ;
275
+
276
+ Plotly . relayout ( gd , update ) . then ( function ( ) {
277
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( zoomRangeX ) ;
278
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( zoomRangeY ) ;
279
+
280
+ doubleClick ( blankPos [ 0 ] , blankPos [ 1 ] , function ( ) {
281
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( autoRangeX ) ;
282
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( autoRangeY ) ;
283
+
284
+ done ( ) ;
285
+ } ) ;
286
+ } ) ;
287
+ } ) ;
288
+ } ) ;
289
+
290
+ it ( 'when set to \'autosize\' should reset on all double clicks' , function ( done ) {
291
+ mockCopy = setRanges ( mockCopy ) ;
292
+
293
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout , { doubleClick : 'autosize' } ) . then ( function ( ) {
294
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( setRangeX ) ;
295
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( setRangeY ) ;
296
+
297
+ doubleClick ( blankPos [ 0 ] , blankPos [ 1 ] , function ( ) {
298
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( autoRangeX ) ;
299
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( autoRangeY ) ;
300
+
301
+ done ( ) ;
302
+ } ) ;
303
+ } ) ;
304
+ } ) ;
305
+
306
+ } ) ;
90
307
} ) ;
0 commit comments