@@ -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,41 @@ describe('hovermode defaults to', function() {
25032518 . then ( done ) ;
25042519 } ) ;
25052520} ) ;
2521+
2522+
2523+ describe ( 'touch devices' , function ( ) {
2524+ [ 'pan' , 'zoom' ] . forEach ( function ( type ) {
2525+ describe ( 'dragmode:' + type , function ( ) {
2526+ var data = [ { x : [ 1 , 2 , 3 ] , y : [ 1 , 3 , 2 ] , type : 'bar' } ] ;
2527+ var layout = { width : 600 , height : 400 , dragmode : type } ;
2528+ var gd ;
2529+
2530+ beforeEach ( function ( done ) {
2531+ gd = createGraphDiv ( ) ;
2532+ Plotly . plot ( gd , data , layout ) . then ( done ) ;
2533+ } ) ;
2534+
2535+ it ( 'emits click events' , function ( done ) {
2536+ var hoverHandler = jasmine . createSpy ( 'hover' ) ;
2537+ var clickHandler = jasmine . createSpy ( 'click' ) ;
2538+ gd . on ( 'plotly_hover' , hoverHandler ) ;
2539+ gd . on ( 'plotly_click' , clickHandler ) ;
2540+
2541+ var gdBB = gd . getBoundingClientRect ( ) ;
2542+ var touchPoint = [ [ gdBB . left + 300 , gdBB . top + 200 ] ] ;
2543+
2544+ Promise . resolve ( )
2545+ . then ( function ( ) {
2546+ touch ( touchPoint ) ;
2547+ } )
2548+ . then ( delay ( HOVERMINTIME * 1.1 ) )
2549+ . then ( function ( ) {
2550+ expect ( clickHandler ) . toHaveBeenCalled ( ) ;
2551+ expect ( hoverHandler ) . not . toHaveBeenCalled ( ) ;
2552+ } )
2553+ . catch ( failTest )
2554+ . then ( done ) ;
2555+ } ) ;
2556+ } ) ;
2557+ } ) ;
2558+ } ) ;
0 commit comments