@@ -9,6 +9,7 @@ var createGraphDiv = require('../assets/create_graph_div');
99var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
1010var failTest = require ( '../assets/fail_test' ) ;
1111var delay = require ( '../assets/delay' ) ;
12+ var mouseEvent = require ( '../assets/mouse_event' ) ;
1213var readPixel = require ( '../assets/read_pixel' ) ;
1314
1415var multipleScatter2dMock = require ( '@mocks/gl2d_scatter2d-multiple-colors.json' ) ;
@@ -158,16 +159,15 @@ describe('pointcloud traces', function() {
158159 } ) ;
159160
160161 it ( '@gl renders without raising an error' , function ( done ) {
161- Plotly . plot ( gd , plotData )
162+ Plotly . plot ( gd , Lib . extendDeep ( { } , plotData ) )
162163 . catch ( failTest )
163164 . then ( done ) ;
164165 } ) ;
165166
166167 it ( '@gl should update properly' , function ( done ) {
167- var mock = plotData ;
168168 var scene2d ;
169169
170- Plotly . plot ( gd , mock )
170+ Plotly . plot ( gd , Lib . extendDeep ( { } , plotData ) )
171171 . then ( function ( ) {
172172 scene2d = gd . _fullLayout . _plots . xy . _scene2d ;
173173 expect ( scene2d . traces [ gd . _fullData [ 0 ] . uid ] . type ) . toBe ( 'pointcloud' ) ;
@@ -210,4 +210,49 @@ describe('pointcloud traces', function() {
210210 . catch ( failTest )
211211 . then ( done ) ;
212212 } ) ;
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 ( 400 ) )
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+ } ) ;
213258} ) ;
0 commit comments