@@ -533,10 +533,12 @@ describe('config argument', function() {
533
533
534
534
describe ( 'responsive figure' , function ( ) {
535
535
var gd ;
536
+ var startWidth = 960 , startHeight = 400 ;
537
+ var newWidth = 400 , newHeight = 700 ;
536
538
var data = [ { x : [ 1 , 2 , 3 , 4 ] , y : [ 5 , 10 , 2 , 8 ] } ] ;
537
539
538
540
beforeEach ( function ( ) {
539
- viewport . reset ( ) ;
541
+ viewport . set ( startWidth , startHeight ) ;
540
542
gd = createGraphDiv ( ) ;
541
543
542
544
// Make the graph fill the parent
@@ -546,10 +548,27 @@ describe('config argument', function() {
546
548
547
549
afterEach ( function ( ) {
548
550
destroyGraphDiv ( ) ;
549
- // Reset window size
550
551
viewport . reset ( ) ;
551
552
} ) ;
552
553
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
+
553
572
function checkLayoutSize ( width , height ) {
554
573
expect ( gd . _fullLayout . width ) . toBe ( width ) ;
555
574
expect ( gd . _fullLayout . height ) . toBe ( height ) ;
@@ -560,17 +579,60 @@ describe('config argument', function() {
560
579
}
561
580
562
581
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
+ } )
565
628
// Resize viewport
566
629
. then ( function ( ) {
567
630
viewport . set ( newWidth , newHeight ) ;
568
631
} )
569
- // Wait for resize to happen (Plotly.resize has a 100ms timeout)
570
632
. then ( delay ( 200 ) )
571
- // Check final figure size
633
+ // Check final figure size hasn't changed
572
634
. then ( function ( ) {
573
- checkLayoutSize ( newWidth , newHeight ) ;
635
+ checkLayoutSize ( startWidth , startHeight ) ;
574
636
} )
575
637
. catch ( failTest )
576
638
. then ( done ) ;
0 commit comments