@@ -10,6 +10,8 @@ var Axes = PlotlyInternal.Axes;
1010
1111var createGraphDiv = require ( '../assets/create_graph_div' ) ;
1212var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
13+ var customMatchers = require ( '../assets/custom_matchers' ) ;
14+ var failTest = require ( '../assets/fail_test' ) ;
1315
1416
1517describe ( 'Test axes' , function ( ) {
@@ -570,6 +572,49 @@ describe('Test axes', function() {
570572 } ) ;
571573 } ) ;
572574
575+ describe ( 'constraints relayout' , function ( ) {
576+ var gd ;
577+
578+ beforeEach ( function ( ) {
579+ gd = createGraphDiv ( ) ;
580+ jasmine . addMatchers ( customMatchers ) ;
581+ } ) ;
582+
583+ afterEach ( destroyGraphDiv ) ;
584+
585+ it ( 'updates ranges when adding, removing, or changing a constraint' , function ( done ) {
586+ PlotlyInternal . plot ( gd ,
587+ [ { z : [ [ 0 , 1 ] , [ 2 , 3 ] ] , type : 'heatmap' } ] ,
588+ // plot area is 200x100 px
589+ { width : 400 , height : 300 , margin : { l : 100 , r : 100 , t : 100 , b : 100 } }
590+ )
591+ . then ( function ( ) {
592+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ - 0.5 , 1.5 ] , 5 ) ;
593+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ - 0.5 , 1.5 ] , 5 ) ;
594+
595+ return PlotlyInternal . relayout ( gd , { 'xaxis.scaleanchor' : 'y' } ) ;
596+ } )
597+ . then ( function ( ) {
598+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ - 1.5 , 2.5 ] , 5 ) ;
599+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ - 0.5 , 1.5 ] , 5 ) ;
600+
601+ return PlotlyInternal . relayout ( gd , { 'xaxis.scaleratio' : 10 } ) ;
602+ } )
603+ . then ( function ( ) {
604+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ - 0.5 , 1.5 ] , 5 ) ;
605+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ - 4.5 , 5.5 ] , 5 ) ;
606+
607+ return PlotlyInternal . relayout ( gd , { 'xaxis.scaleanchor' : null } ) ;
608+ } )
609+ . then ( function ( ) {
610+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ - 0.5 , 1.5 ] , 5 ) ;
611+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( [ - 0.5 , 1.5 ] , 5 ) ;
612+ } )
613+ . catch ( failTest )
614+ . then ( done ) ;
615+ } ) ;
616+ } ) ;
617+
573618 describe ( 'categoryorder' , function ( ) {
574619
575620 var gd ;
0 commit comments