@@ -9,6 +9,7 @@ var createGraphDiv = require('../assets/create_graph_div');
9
9
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
10
10
var failTest = require ( '../assets/fail_test' ) ;
11
11
var delay = require ( '../assets/delay' ) ;
12
+ var mouseEvent = require ( '../assets/mouse_event' ) ;
12
13
var readPixel = require ( '../assets/read_pixel' ) ;
13
14
14
15
var multipleScatter2dMock = require ( '@mocks/gl2d_scatter2d-multiple-colors.json' ) ;
@@ -158,16 +159,15 @@ describe('pointcloud traces', function() {
158
159
} ) ;
159
160
160
161
it ( '@gl renders without raising an error' , function ( done ) {
161
- Plotly . plot ( gd , plotData )
162
+ Plotly . plot ( gd , Lib . extendDeep ( { } , plotData ) )
162
163
. catch ( failTest )
163
164
. then ( done ) ;
164
165
} ) ;
165
166
166
167
it ( '@gl should update properly' , function ( done ) {
167
- var mock = plotData ;
168
168
var scene2d ;
169
169
170
- Plotly . plot ( gd , mock )
170
+ Plotly . plot ( gd , Lib . extendDeep ( { } , plotData ) )
171
171
. then ( function ( ) {
172
172
scene2d = gd . _fullLayout . _plots . xy . _scene2d ;
173
173
expect ( scene2d . traces [ gd . _fullData [ 0 ] . uid ] . type ) . toBe ( 'pointcloud' ) ;
@@ -210,4 +210,49 @@ describe('pointcloud traces', function() {
210
210
. catch ( failTest )
211
211
. then ( done ) ;
212
212
} ) ;
213
+
214
+ it ( '@gl should respond to drag' , function ( done ) {
215
+ function _drag ( p0 , p1 ) {
216
+ mouseEvent ( 'mousemove' , p0 [ 0 ] , p0 [ 1 ] , { buttons : 1 } ) ;
217
+ mouseEvent ( 'mousedown' , p0 [ 0 ] , p0 [ 1 ] , { buttons : 1 } ) ;
218
+ mouseEvent ( 'mousemove' , ( p0 [ 0 ] + p1 [ 0 ] ) / 2 , ( p0 [ 1 ] + p1 [ 1 ] ) / 2 , { buttons : 1 } ) ;
219
+ mouseEvent ( 'mousemove' , p1 [ 0 ] , p1 [ 1 ] , { buttons : 0 } ) ;
220
+ mouseEvent ( 'mouseup' , p1 [ 0 ] , p1 [ 1 ] , { buttons : 0 } ) ;
221
+ }
222
+
223
+ function _assertRange ( msg , xrng , yrng ) {
224
+ expect ( gd . _fullLayout . xaxis . range ) . toBeCloseToArray ( xrng , 2 , msg ) ;
225
+ expect ( gd . _fullLayout . yaxis . range ) . toBeCloseToArray ( yrng , 2 , msg ) ;
226
+ }
227
+
228
+ Plotly . plot ( gd , Lib . extendDeep ( { } , plotData ) )
229
+ . then ( delay ( 40 ) )
230
+ . then ( function ( ) {
231
+ _assertRange ( 'base' , [ - 0.548 , 9.548 ] , [ - 1.415 , 10.415 ] ) ;
232
+ } )
233
+ . then ( function ( ) { _drag ( [ 200 , 200 ] , [ 350 , 350 ] ) ; } )
234
+ . then ( delay ( 40 ) )
235
+ . then ( function ( ) {
236
+ _assertRange ( 'after zoombox drag' , [ 0.768 , 1.591 ] , [ 5.462 , 7.584 ] ) ;
237
+ } )
238
+ . then ( function ( ) {
239
+ return Plotly . relayout ( gd , {
240
+ 'xaxis.autorange' : true ,
241
+ 'yaxis.autorange' : true
242
+ } ) ;
243
+ } )
244
+ . then ( function ( ) {
245
+ _assertRange ( 'back to base' , [ - 0.548 , 9.548 ] , [ - 1.415 , 10.415 ] ) ;
246
+ } )
247
+ . then ( function ( ) {
248
+ return Plotly . relayout ( gd , 'dragmode' , 'pan' ) ;
249
+ } )
250
+ . then ( function ( ) { _drag ( [ 200 , 200 ] , [ 350 , 350 ] ) ; } )
251
+ . then ( delay ( 40 ) )
252
+ . then ( function ( ) {
253
+ _assertRange ( 'after pan drag' , [ 0.2743 , 10.3719 ] , [ - 3.537 , 8.292 ] ) ;
254
+ } )
255
+ . catch ( failTest )
256
+ . then ( done ) ;
257
+ } ) ;
213
258
} ) ;
0 commit comments