@@ -13,6 +13,7 @@ var click = require('../assets/click');
1313var delay = require ( '../assets/delay' ) ;
1414var doubleClick = require ( '../assets/double_click' ) ;
1515var failTest = require ( '../assets/fail_test' ) ;
16+ var touchEvent = require ( '../assets/touch_event' ) ;
1617
1718var customAssertions = require ( '../assets/custom_assertions' ) ;
1819var assertHoverLabelStyle = customAssertions . assertHoverLabelStyle ;
@@ -21,6 +22,20 @@ var assertElemRightTo = customAssertions.assertElemRightTo;
2122var assertElemTopsAligned = customAssertions . assertElemTopsAligned ;
2223var assertElemInside = customAssertions . assertElemInside ;
2324
25+ function touch ( path , options ) {
26+ var len = path . length ;
27+ Lib . clearThrottle ( ) ;
28+ touchEvent ( 'touchstart' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] , options ) ;
29+
30+ path . slice ( 1 , len ) . forEach ( function ( pt ) {
31+ Lib . clearThrottle ( ) ;
32+ touchEvent ( 'touchmove' , pt [ 0 ] , pt [ 1 ] , options ) ;
33+ } ) ;
34+
35+ touchEvent ( 'touchend' , path [ len - 1 ] [ 0 ] , path [ len - 1 ] [ 1 ] , options ) ;
36+ return ;
37+ }
38+
2439describe ( 'hover info' , function ( ) {
2540 'use strict' ;
2641
@@ -2503,3 +2518,43 @@ describe('hovermode defaults to', function() {
25032518 . then ( done ) ;
25042519 } ) ;
25052520} ) ;
2521+
2522+
2523+ describe ( 'touch devices' , function ( ) {
2524+ afterEach ( destroyGraphDiv ) ;
2525+
2526+ [ 'pan' , 'zoom' ] . forEach ( function ( type ) {
2527+ describe ( 'dragmode:' + type , function ( ) {
2528+ var data = [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 3 , 2 ] , type : 'bar' } ] ;
2529+ var layout = { width : 600 , height : 400 , dragmode : type } ;
2530+ var gd ;
2531+
2532+ beforeEach ( function ( done ) {
2533+ gd = createGraphDiv ( ) ;
2534+ Plotly . plot ( gd , data , layout ) . then ( done ) ;
2535+ } ) ;
2536+
2537+ it ( 'emits click events' , function ( done ) {
2538+ var hoverHandler = jasmine . createSpy ( 'hover' ) ;
2539+ var clickHandler = jasmine . createSpy ( 'click' ) ;
2540+ gd . on ( 'plotly_hover' , hoverHandler ) ;
2541+ gd . on ( 'plotly_click' , clickHandler ) ;
2542+
2543+ var gdBB = gd . getBoundingClientRect ( ) ;
2544+ var touchPoint = [ [ gdBB . left + 300 , gdBB . top + 200 ] ] ;
2545+
2546+ Promise . resolve ( )
2547+ . then ( function ( ) {
2548+ touch ( touchPoint ) ;
2549+ } )
2550+ . then ( delay ( HOVERMINTIME * 1.1 ) )
2551+ . then ( function ( ) {
2552+ expect ( clickHandler ) . toHaveBeenCalled ( ) ;
2553+ expect ( hoverHandler ) . not . toHaveBeenCalled ( ) ;
2554+ } )
2555+ . catch ( failTest )
2556+ . then ( done ) ;
2557+ } ) ;
2558+ } ) ;
2559+ } ) ;
2560+ } ) ;
0 commit comments