@@ -1759,3 +1759,71 @@ describe('legend DOM', function() {
1759
1759
. then ( done ) ;
1760
1760
} ) ;
1761
1761
} ) ;
1762
+
1763
+ describe ( 'legend with custom doubleClickDelay' , function ( ) {
1764
+ var gd ;
1765
+
1766
+ beforeEach ( function ( ) {
1767
+ gd = createGraphDiv ( ) ;
1768
+ } ) ;
1769
+
1770
+ afterEach ( destroyGraphDiv ) ;
1771
+
1772
+ function click ( index ) {
1773
+ return function ( ) {
1774
+ var item = d3 . selectAll ( 'rect.legendtoggle' ) [ 0 ] [ index ] ;
1775
+ item . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
1776
+ item . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
1777
+ } ;
1778
+ }
1779
+
1780
+ it ( 'should differentiate clicks and double-clicks according *doubleClickDelay* config' , function ( done ) {
1781
+ var tLong = 1.5 * DBLCLICKDELAY ;
1782
+ var tShort = 0.75 * DBLCLICKDELAY ;
1783
+
1784
+ var clickCnt = 0 ;
1785
+ var dblClickCnt = 0 ;
1786
+
1787
+ function _assert ( msg , _clickCnt , _dblClickCnt ) {
1788
+ return function ( ) {
1789
+ expect ( clickCnt ) . toBe ( _clickCnt , msg + '| clickCnt' ) ;
1790
+ expect ( dblClickCnt ) . toBe ( _dblClickCnt , msg + '| dblClickCnt' ) ;
1791
+ clickCnt = 0 ;
1792
+ dblClickCnt = 0 ;
1793
+ } ;
1794
+ }
1795
+
1796
+ Plotly . plot ( gd , [
1797
+ { y : [ 1 , 2 , 1 ] } ,
1798
+ { y : [ 2 , 1 , 2 ] }
1799
+ ] , { } , {
1800
+ doubleClickDelay : tLong
1801
+ } )
1802
+ . then ( function ( ) {
1803
+ gd . on ( 'plotly_legendclick' , function ( ) { clickCnt ++ ; } ) ;
1804
+ gd . on ( 'plotly_legenddoubleclick' , function ( ) { dblClickCnt ++ ; } ) ;
1805
+ } )
1806
+ . then ( click ( 0 ) ) . then ( delay ( tLong / 2 ) )
1807
+ . then ( _assert ( '[long] after click + (t/2) delay' , 1 , 0 ) )
1808
+ . then ( delay ( tLong + 10 ) )
1809
+ . then ( click ( 0 ) ) . then ( delay ( DBLCLICKDELAY + 1 ) ) . then ( click ( 0 ) )
1810
+ . then ( _assert ( '[long] after click + (DBLCLICKDELAY+1) delay + click' , 2 , 1 ) )
1811
+ . then ( delay ( tLong + 10 ) )
1812
+ . then ( click ( 0 ) ) . then ( delay ( 1.1 * tLong ) ) . then ( click ( 0 ) )
1813
+ . then ( _assert ( '[long] after click + (1.1*t) delay + click' , 2 , 0 ) )
1814
+ . then ( delay ( tLong + 10 ) )
1815
+ . then ( function ( ) {
1816
+ return Plotly . plot ( gd , [ ] , { } , { doubleClickDelay : tShort } ) ;
1817
+ } )
1818
+ . then ( click ( 0 ) ) . then ( delay ( tShort / 2 ) )
1819
+ . then ( _assert ( '[short] after click + (t/2) delay' , 1 , 0 ) )
1820
+ . then ( delay ( tShort + 10 ) )
1821
+ . then ( click ( 0 ) ) . then ( delay ( DBLCLICKDELAY + 1 ) ) . then ( click ( 0 ) )
1822
+ . then ( _assert ( '[short] after click + (DBLCLICKDELAY+1) delay + click' , 2 , 0 ) )
1823
+ . then ( delay ( tShort + 10 ) )
1824
+ . then ( click ( 0 ) ) . then ( delay ( 1.1 * tShort ) ) . then ( click ( 0 ) )
1825
+ . then ( _assert ( '[short] after click + (1.1*t) delay + click' , 2 , 0 ) )
1826
+ . catch ( failTest )
1827
+ . then ( done ) ;
1828
+ } , 3 * jasmine . DEFAULT_TIMEOUT_INTERVAL ) ;
1829
+ } ) ;
0 commit comments