@@ -533,10 +533,12 @@ describe('config argument', function() {
533533
534534 describe ( 'responsive figure' , function ( ) {
535535 var gd ;
536+ var startWidth = 960 , startHeight = 400 ;
537+ var newWidth = 400 , newHeight = 700 ;
536538 var data = [ { x : [ 1 , 2 , 3 , 4 ] , y : [ 5 , 10 , 2 , 8 ] } ] ;
537539
538540 beforeEach ( function ( ) {
539- viewport . reset ( ) ;
541+ viewport . set ( startWidth , startHeight ) ;
540542 gd = createGraphDiv ( ) ;
541543
542544 // Make the graph fill the parent
@@ -546,10 +548,27 @@ describe('config argument', function() {
546548
547549 afterEach ( function ( ) {
548550 destroyGraphDiv ( ) ;
549- // Reset window size
550551 viewport . reset ( ) ;
551552 } ) ;
552553
554+ function testResponsive ( promise ) {
555+ return promise
556+ . then ( function ( ) {
557+ checkLayoutSize ( startWidth , startHeight ) ;
558+ } )
559+ // Resize viewport
560+ . then ( function ( ) {
561+ viewport . set ( newWidth , newHeight ) ;
562+ } )
563+ // Wait for resize to happen (Plotly.resize has a 100ms timeout)
564+ . then ( delay ( 200 ) )
565+ // Check final figure size
566+ . then ( function ( ) {
567+ checkLayoutSize ( newWidth , newHeight ) ;
568+ } )
569+ . catch ( failTest ) ;
570+ }
571+
553572 function checkLayoutSize ( width , height ) {
554573 expect ( gd . _fullLayout . width ) . toBe ( width ) ;
555574 expect ( gd . _fullLayout . height ) . toBe ( height ) ;
@@ -560,17 +579,60 @@ describe('config argument', function() {
560579 }
561580
562581 it ( 'should resize when the viewport width/height changes' , function ( done ) {
563- var newWidth = 400 , newHeight = 700 ;
564- Plotly . newPlot ( gd , data , { } , { responsive : true } )
582+ var promise = Plotly . plot ( gd , data , { } , { responsive : true } ) ;
583+
584+ testResponsive ( promise )
585+ . then ( done ) ;
586+ } ) ;
587+
588+ it ( 'should still be responsive if the plot is redrawn' , function ( done ) {
589+ var promise = Plotly . plot ( gd , data , { } , { responsive : true } )
590+ . then ( function ( ) {
591+ Plotly . restyle ( gd , 'y[0]' , data [ 0 ] . y [ 0 ] * 2 ) ;
592+ } ) ;
593+
594+ testResponsive ( promise )
595+ . then ( done ) ;
596+ } ) ;
597+
598+ it ( 'should still be responsive if the plot is purged and replotted' , function ( done ) {
599+ var promise = Plotly . plot ( gd , data , { } , { responsive : true } )
600+ . then ( function ( ) {
601+ Plotly . newPlot ( gd , data , { } , { responsive : true } ) ;
602+ } ) ;
603+
604+ testResponsive ( promise )
605+ . then ( done ) ;
606+ } ) ;
607+
608+ it ( 'should become responsive if configured to be so by Plotly.react' , function ( done ) {
609+ var promise = Plotly . plot ( gd , data , { } , { responsive : false } )
610+ . then ( function ( ) {
611+ Plotly . react ( gd , data , { } , { responsive : true } ) ;
612+ } ) ;
613+
614+ testResponsive ( promise )
615+ . then ( done ) ;
616+ } ) ;
617+
618+ it ( 'should stop being responsive if configured to be so by Plotly.react' , function ( done ) {
619+ Plotly . plot ( gd , data , { } , { responsive : true } )
620+ // Check initial size
621+ . then ( function ( ) {
622+ checkLayoutSize ( startWidth , startHeight ) ;
623+ } )
624+ // Turn off responsiveness
625+ . then ( function ( ) {
626+ Plotly . react ( gd , data , { } , { responsive : false } ) ;
627+ } )
565628 // Resize viewport
566629 . then ( function ( ) {
567630 viewport . set ( newWidth , newHeight ) ;
568631 } )
569- // Wait for resize to happen (Plotly.resize has a 100ms timeout)
570632 . then ( delay ( 200 ) )
571- // Check final figure size
633+ // Check final figure size hasn't changed
572634 . then ( function ( ) {
573- checkLayoutSize ( newWidth , newHeight ) ;
635+ checkLayoutSize ( startWidth , startHeight ) ;
574636 } )
575637 . catch ( failTest )
576638 . then ( done ) ;
0 commit comments