@@ -2,6 +2,7 @@ var Plotly = require('@lib/index');
22var Lib = require ( '@src/lib' ) ;
33
44var helpers = require ( '@src/snapshot/helpers' ) ;
5+ var getImageSize = require ( '@src/traces/image/helpers' ) . getImageSize ;
56
67var createGraphDiv = require ( '../assets/create_graph_div' ) ;
78var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
@@ -164,6 +165,33 @@ describe('Plotly.downloadImage', function() {
164165 . catch ( failTest )
165166 . then ( done ) ;
166167 } ) ;
168+
169+ it ( 'should default width & height for downloadImage to match with the live graph' , function ( done ) {
170+ spyOn ( Lib , 'isSafari' ) . and . callFake ( function ( ) { return true ; } ) ;
171+ spyOn ( helpers , 'octetStream' ) ;
172+
173+ var fig = {
174+ data : [ { y : [ 0 , 1 ] } ]
175+ } ;
176+
177+ gd . style . width = '500px' ;
178+ gd . style . height = '300px' ;
179+
180+ Plotly . plot ( gd , fig )
181+ . then ( function ( ) { return Plotly . downloadImage ( gd , { format : 'png' } ) ; } )
182+ . then ( function ( ) {
183+ var args = helpers . octetStream . calls . allArgs ( ) ;
184+ var blob = args [ 0 ] [ 0 ] ;
185+ expect ( blob . slice ( 0 , 8 ) ) . toBe ( ';base64,' , 'format:png' ) ;
186+ var size = getImageSize ( 'data:image/png' + blob ) ;
187+ expect ( size . width ) . toBe ( gd . _fullLayout . width , 'fullLayout width' ) ;
188+ expect ( size . height ) . toBe ( gd . _fullLayout . height , 'fullLayout height' ) ;
189+ expect ( size . width ) . toBe ( 500 , 'div width' ) ;
190+ expect ( size . height ) . toBe ( 300 , 'div height' ) ;
191+ } )
192+ . catch ( failTest )
193+ . then ( done ) ;
194+ } ) ;
167195} ) ;
168196
169197function downloadTest ( gd , format ) {
0 commit comments