@@ -2,6 +2,7 @@ var Plotly = require('@lib/index');
2
2
var Lib = require ( '@src/lib' ) ;
3
3
4
4
var helpers = require ( '@src/snapshot/helpers' ) ;
5
+ var getImageSize = require ( '@src/traces/image/helpers' ) . getImageSize ;
5
6
6
7
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
7
8
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
@@ -164,6 +165,33 @@ describe('Plotly.downloadImage', function() {
164
165
. catch ( failTest )
165
166
. then ( done ) ;
166
167
} ) ;
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
+ } ) ;
167
195
} ) ;
168
196
169
197
function downloadTest ( gd , format ) {
0 commit comments