@@ -65,7 +65,6 @@ describe('zoom box element', function() {
65
65
} ) ;
66
66
} ) ;
67
67
68
-
69
68
describe ( 'main plot pan' , function ( ) {
70
69
var gd , modeBar , relayoutCallback ;
71
70
@@ -893,7 +892,7 @@ describe('axis zoom/pan and main plot zoom', function() {
893
892
cnt ++ ;
894
893
// called twice as many times on drag:
895
894
// - once per axis during mousemouve
896
- // - once per raxis on mouseup
895
+ // - once per axis on mouseup
897
896
if ( opts . dragged ) cnt ++ ;
898
897
}
899
898
} ) ;
@@ -1726,7 +1725,7 @@ describe('axis zoom/pan and main plot zoom', function() {
1726
1725
1727
1726
Plotly . plot ( gd , [ { type : 'heatmap' , z : z ( ) } ] , { dragmode : 'pan' } )
1728
1727
. then ( function ( ) {
1729
- // inspired by https://github.com/plotly/plotly.js/issues/2687<Paste>
1728
+ // inspired by https://github.com/plotly/plotly.js/issues/2687
1730
1729
gd . on ( 'plotly_relayout' , function ( d ) {
1731
1730
relayoutTracker . unshift ( d ) ;
1732
1731
setTimeout ( function ( ) {
@@ -1915,6 +1914,66 @@ describe('axis zoom/pan and main plot zoom', function() {
1915
1914
. then ( done ) ;
1916
1915
} ) ;
1917
1916
} ) ;
1917
+
1918
+ it ( 'zoomboxes during small drag motions' , function ( done ) {
1919
+ var MINDRAG = constants . MINDRAG ;
1920
+ var eventData = { } ;
1921
+
1922
+ function _run ( msg , dpos , exp ) {
1923
+ return function ( ) {
1924
+ var node = getDragger ( 'xy' , 'nsew' ) ;
1925
+ var fns = drag . makeFns ( { node : node , pos0 : [ 200 , 200 ] , dpos : dpos } ) ;
1926
+
1927
+ return fns . start ( ) . then ( function ( ) {
1928
+ var zl = d3 . select ( gd ) . select ( 'g.zoomlayer' ) ;
1929
+ var d = zl . select ( '.zoombox-corners' ) . attr ( 'd' ) ;
1930
+ if ( exp === 'nozoom' ) {
1931
+ expect ( d ) . toBe ( 'M0,0Z' , 'blank path | ' + msg ) ;
1932
+ } else {
1933
+ var actual = ( d . match ( / Z / g) || [ ] ) . length ;
1934
+ if ( exp === 'x-zoom' || exp === 'y-zoom' ) {
1935
+ expect ( actual ) . toBe ( 2 , 'two corners | ' + msg ) ;
1936
+ } else if ( exp === 'xy-zoom' ) {
1937
+ expect ( actual ) . toBe ( 4 , 'four corners | ' + msg ) ;
1938
+ } else {
1939
+ fail ( 'wrong expectation str.' ) ;
1940
+ }
1941
+ }
1942
+ } )
1943
+ . then ( fns . end )
1944
+ . then ( function ( ) {
1945
+ var keys = Object . keys ( eventData ) ;
1946
+ if ( exp === 'nozoom' ) {
1947
+ expect ( keys . length ) . toBe ( 0 , 'no event data | ' + msg ) ;
1948
+ } else if ( exp === 'x-zoom' ) {
1949
+ expect ( keys ) . withContext ( 'relayout xaxis rng | ' + msg )
1950
+ . toEqual ( [ 'xaxis.range[0]' , 'xaxis.range[1]' ] ) ;
1951
+ } else if ( exp === 'y-zoom' ) {
1952
+ expect ( keys ) . withContext ( 'relayout yaxis rng | ' + msg )
1953
+ . toEqual ( [ 'yaxis.range[0]' , 'yaxis.range[1]' ] ) ;
1954
+ } else if ( exp === 'xy-zoom' ) {
1955
+ expect ( keys . length ) . toBe ( 4 , 'x and y relayout | ' + msg ) ;
1956
+ } else {
1957
+ fail ( 'wrong expectation str.' ) ;
1958
+ }
1959
+ eventData = { } ;
1960
+ } ) ;
1961
+ } ;
1962
+ }
1963
+
1964
+ Plotly . plot ( gd , [ { y : [ 1 , 2 , 1 ] } ] , { width : 400 , height : 400 } )
1965
+ . then ( function ( ) {
1966
+ gd . on ( 'plotly_relayout' , function ( d ) { eventData = d ; } ) ;
1967
+ } )
1968
+ . then ( _run ( 'dx < MINDRAG' , [ MINDRAG - 2 , 0 ] , 'nozoom' ) )
1969
+ . then ( _run ( 'dx > MINDRAG' , [ MINDRAG + 2 , 0 ] , 'x-zoom' ) )
1970
+ . then ( _run ( 'dy < MINDRAG' , [ 0 , MINDRAG - 2 ] , 'nozoom' ) )
1971
+ . then ( _run ( 'dy > MINDRAG' , [ 0 , MINDRAG + 2 ] , 'y-zoom' ) )
1972
+ . then ( _run ( '(dx,dy) < MINDRAG' , [ MINDRAG - 2 , MINDRAG - 2 ] , 'nozoom' ) )
1973
+ . then ( _run ( '(dx,dy) > MINDRAG' , [ MINDRAG + 2 , MINDRAG + 2 ] , 'xy-zoom' ) )
1974
+ . catch ( failTest )
1975
+ . then ( done ) ;
1976
+ } ) ;
1918
1977
} ) ;
1919
1978
1920
1979
describe ( 'Event data:' , function ( ) {
0 commit comments