@@ -705,5 +705,50 @@ describe('config argument', function() {
705
705
. then ( testResponsive )
706
706
. then ( done ) ;
707
707
} ) ;
708
+
709
+ it ( 'should provide a fixed non-zero width/height when autosize/responsive: true and container\' size is zero' , function ( done ) {
710
+ fillParent ( 1 , 1 , function ( ) {
711
+ this . style . display = 'inline-block' ;
712
+ this . style . width = null ;
713
+ this . style . height = null ;
714
+ } ) ;
715
+ Plotly . plot ( gd , data , { autosize : true } , { responsive : true } )
716
+ . then ( function ( ) {
717
+ checkLayoutSize ( 700 , 450 ) ;
718
+ expect ( gd . clientWidth ) . toBe ( 700 ) ;
719
+ expect ( gd . clientHeight ) . toBe ( 450 ) ;
720
+ } )
721
+ . then ( function ( ) {
722
+ return Plotly . newPlot ( gd , data , { autosize : true } , { responsive : true } ) ;
723
+ } )
724
+ // It is important to test newPlot to make sure an initially zero size container
725
+ // is still considered to have zero size after a plot is drawn into it.
726
+ . then ( function ( ) {
727
+ checkLayoutSize ( 700 , 450 ) ;
728
+ expect ( gd . clientWidth ) . toBe ( 700 ) ;
729
+ expect ( gd . clientHeight ) . toBe ( 450 ) ;
730
+ } )
731
+ . catch ( failTest )
732
+ . then ( done ) ;
733
+ } ) ;
734
+
735
+ // The following test is to guarantee we're not breaking the existing (although maybe not ideal) behaviour.
736
+ // In a future version, one may prefer responsive/autosize:true winning over an explicit width/height when embedded in a webpage.
737
+ it ( 'should use the explicitly provided width/height even if autosize/responsive:true' , function ( done ) {
738
+ fillParent ( 1 , 1 , function ( ) {
739
+ this . style . width = '1000px' ;
740
+ this . style . height = '500px' ;
741
+ } ) ;
742
+
743
+ Plotly . plot ( gd , data , { autosize : true , width : 1200 , height : 700 } , { responsive : true } )
744
+ . then ( function ( ) {
745
+ expect ( gd . clientWidth ) . toBe ( 1000 ) ;
746
+ expect ( gd . clientHeight ) . toBe ( 500 ) ;
747
+ // The plot should overflow the container!
748
+ checkLayoutSize ( 1200 , 700 ) ;
749
+ } )
750
+ . catch ( failTest )
751
+ . then ( done ) ;
752
+ } ) ;
708
753
} ) ;
709
754
} ) ;
0 commit comments