@@ -6,6 +6,7 @@ var DBLCLICKDELAY = require('@src/constants/interactions').DBLCLICKDELAY;
66var d3 = require ( 'd3' ) ;
77var createGraphDiv = require ( '../assets/create_graph_div' ) ;
88var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
9+ var failTest = require ( '../assets/fail_test' ) ;
910var mouseEvent = require ( '../assets/mouse_event' ) ;
1011var getRectCenter = require ( '../assets/get_rect_center' ) ;
1112
@@ -900,6 +901,96 @@ describe('Test click interactions:', function() {
900901 } ) ;
901902 } ) ;
902903
904+ it ( 'should not try to autorange fixedrange:true axes when rangeInitial is not set' , function ( done ) {
905+ var fig = {
906+ data : [ {
907+ x : [ 1 , 2 , 3 , 4 ] ,
908+ y : [ 1 , 2 , 3 , 4 ]
909+ } , {
910+ x : [ 1 , 2 , 3 , 4 ] ,
911+ y : [ 0.2 , 999 , 0.3 , 0.4 ] ,
912+ yaxis : 'y2'
913+ } ] ,
914+ layout : {
915+ xaxis : {
916+ title : 'xaxis' ,
917+ range : [ 0 , 4 ]
918+ } ,
919+ yaxis : {
920+ titel : 'yaxis' ,
921+ range : [ - 1 , 5 ]
922+ } ,
923+ yaxis2 : {
924+ title : 'yaxis2' ,
925+ overlaying : 'y' ,
926+ side : 'right' ,
927+ showgrid : false ,
928+ zeroline : false ,
929+ range : [ - 1 , 1 ] ,
930+ fixedrange : true
931+ } ,
932+ width : 500 ,
933+ height : 500
934+ }
935+ } ;
936+
937+ function _assert ( msg , exp ) {
938+ var fullLayout = gd . _fullLayout ;
939+ var xa = fullLayout . xaxis ;
940+ var ya = fullLayout . yaxis ;
941+ var ya2 = fullLayout . yaxis2 ;
942+
943+ expect ( xa . _rangeInitial ) . toBe ( undefined ) ;
944+ expect ( ya . _rangeInitial ) . toBe ( undefined ) ;
945+ expect ( ya2 . _rangeInitial ) . toBe ( undefined ) ;
946+
947+ expect ( xa . range ) . toBeCloseToArray ( exp . xRng , 1 , msg ) ;
948+ expect ( ya . range ) . toBeCloseToArray ( exp . yRng , 1 , msg ) ;
949+ expect ( ya2 . range ) . toBeCloseToArray ( exp . y2Rng , 1 , msg ) ;
950+ }
951+
952+ Plotly . newPlot ( gd , [ ] , { } )
953+ . then ( function ( ) {
954+ expect ( gd . _fullLayout . xaxis . _rangeInitial ) . toBe ( undefined ) ;
955+ expect ( gd . _fullLayout . yaxis . _rangeInitial ) . toBe ( undefined ) ;
956+ expect ( gd . _fullLayout . yaxis2 ) . toBe ( undefined ) ;
957+ } )
958+ . then ( function ( ) { return Plotly . react ( gd , fig ) ; } )
959+ . then ( function ( ) {
960+ _assert ( 'after react into fig' , {
961+ xRng : [ 0 , 4 ] ,
962+ yRng : [ - 1 , 5 ] ,
963+ y2Rng : [ - 1 , 1 ]
964+ } ) ;
965+ } )
966+ . then ( function ( ) { return drag ( 200 , 200 , 250 , 250 ) ; } )
967+ . then ( function ( ) {
968+ _assert ( 'after zoom' , {
969+ xRng : [ 1.509 , 2.138 ] ,
970+ yRng : [ 2.187 , 3.125 ] ,
971+ y2Rng : [ - 1 , 1 ]
972+ } ) ;
973+ } )
974+ . then ( function ( ) { return doubleClick ( 250 , 250 ) ; } )
975+ . then ( function ( ) {
976+ _assert ( 'after double click autorange' , {
977+ xRng : [ 0.788 , 4.211 ] ,
978+ yRng : [ 0.788 , 4.211 ] ,
979+ y2Rng : [ - 1 , 1 ]
980+ } ) ;
981+ } )
982+ . then ( function ( ) { return doubleClick ( 250 , 250 ) ; } )
983+ . then ( function ( ) {
984+ // more info in: https://github.com/plotly/plotly.js/issues/2718
985+ _assert ( 'after 2nd double click autorange (does not reset as rangeInitial is not set)' , {
986+ xRng : [ 0.788 , 4.211 ] ,
987+ yRng : [ 0.788 , 4.211 ] ,
988+ y2Rng : [ - 1 , 1 ]
989+ } ) ;
990+ } )
991+ . catch ( failTest )
992+ . then ( done ) ;
993+ } ) ;
903994 } ) ;
904995
905996 describe ( 'zoom interactions' , function ( ) {
0 commit comments