@@ -6,6 +6,7 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
66var click = require ( '../assets/click' ) ;
77var mouseEvent = require ( '../assets/mouse_event' ) ;
88var failTest = require ( '../assets/fail_test' ) ;
9+ var delay = require ( '../assets/delay' ) ;
910
1011describe ( 'config argument' , function ( ) {
1112
@@ -529,4 +530,50 @@ describe('config argument', function() {
529530 } ) ;
530531 } ) ;
531532 } ) ;
533+
534+ describe ( 'responsive figure' , function ( ) {
535+ var gd ;
536+ var data = [ { x : [ 1 , 2 , 3 , 4 ] , y : [ 5 , 10 , 2 , 8 ] } ] ;
537+
538+ beforeEach ( function ( ) {
539+ viewport . reset ( ) ;
540+ gd = createGraphDiv ( ) ;
541+
542+ // Make the graph fill the parent
543+ gd . style . width = '100%' ;
544+ gd . style . height = '100%' ;
545+ } ) ;
546+
547+ afterEach ( function ( ) {
548+ destroyGraphDiv ( ) ;
549+ // Reset window size
550+ viewport . reset ( ) ;
551+ } ) ;
552+
553+ function checkLayoutSize ( width , height ) {
554+ expect ( gd . _fullLayout . width ) . toBe ( width ) ;
555+ expect ( gd . _fullLayout . height ) . toBe ( height ) ;
556+
557+ var svg = document . getElementsByClassName ( 'main-svg' ) [ 0 ] ;
558+ expect ( + svg . getAttribute ( 'width' ) ) . toBe ( width ) ;
559+ expect ( + svg . getAttribute ( 'height' ) ) . toBe ( height ) ;
560+ }
561+
562+ it ( 'should resize when the viewport width/height changes' , function ( done ) {
563+ var newWidth = 400 , newHeight = 700 ;
564+ Plotly . newPlot ( gd , data , { } , { responsive : true } )
565+ // Resize viewport
566+ . then ( function ( ) {
567+ viewport . set ( newWidth , newHeight ) ;
568+ } )
569+ // Wait for resize to happen (Plotly.resize has a 100ms timeout)
570+ . then ( delay ( 200 ) )
571+ // Check final figure size
572+ . then ( function ( ) {
573+ checkLayoutSize ( newWidth , newHeight ) ;
574+ } )
575+ . catch ( failTest )
576+ . then ( done ) ;
577+ } ) ;
578+ } ) ;
532579} ) ;
0 commit comments