@@ -129,19 +129,17 @@ proto.makeFramework = function() {
129129 }
130130
131131 // position the canvas
132- var canvas = this . canvas ,
133- pixelRatio = this . pixelRatio ,
134- fullLayout = this . fullLayout ;
132+ var canvas = this . canvas ;
135133
136- canvas . width = Math . ceil ( pixelRatio * fullLayout . width ) | 0 ;
137- canvas . height = Math . ceil ( pixelRatio * fullLayout . height ) | 0 ;
138134 canvas . style . width = '100%' ;
139135 canvas . style . height = '100%' ;
140136 canvas . style . position = 'absolute' ;
141137 canvas . style . top = '0px' ;
142138 canvas . style . left = '0px' ;
143139 canvas . style [ 'pointer-events' ] = 'none' ;
144140
141+ this . updateSize ( canvas ) ;
142+
145143 // disabling user select on the canvas
146144 // sanitizes double-clicks interactions
147145 // ref: https://github.com/plotly/plotly.js/issues/744
@@ -174,6 +172,9 @@ proto.toImage = function(format) {
174172 this . stopped = true ;
175173 if ( this . staticPlot ) this . container . appendChild ( STATIC_CANVAS ) ;
176174
175+ // update canvas size
176+ this . updateSize ( this . canvas ) ;
177+
177178 // force redraw
178179 this . glplot . setDirty ( ) ;
179180 this . glplot . draw ( ) ;
@@ -226,6 +227,26 @@ proto.toImage = function(format) {
226227 return dataURL ;
227228} ;
228229
230+ proto . updateSize = function ( canvas ) {
231+ if ( ! canvas ) canvas = this . canvas ;
232+
233+ var pixelRatio = this . pixelRatio ,
234+ fullLayout = this . fullLayout ;
235+
236+ var width = fullLayout . width ,
237+ height = fullLayout . height ,
238+ pixelWidth = Math . ceil ( pixelRatio * width ) | 0 ,
239+ pixelHeight = Math . ceil ( pixelRatio * height ) | 0 ;
240+
241+ // check for resize
242+ if ( canvas . width !== pixelWidth || canvas . height !== pixelHeight ) {
243+ canvas . width = pixelWidth ;
244+ canvas . height = pixelHeight ;
245+ }
246+
247+ return canvas ;
248+ } ;
249+
229250proto . computeTickMarks = function ( ) {
230251 this . xaxis . _length =
231252 this . glplot . viewBox [ 2 ] - this . glplot . viewBox [ 0 ] ;
@@ -344,24 +365,16 @@ proto.destroy = function() {
344365} ;
345366
346367proto . plot = function ( fullData , calcData , fullLayout ) {
347- var glplot = this . glplot ,
348- pixelRatio = this . pixelRatio ;
368+ var glplot = this . glplot ;
349369
350370 this . fullLayout = fullLayout ;
351371 this . updateAxes ( fullLayout ) ;
352372 this . updateTraces ( fullData , calcData ) ;
353373
354374 var width = fullLayout . width ,
355- height = fullLayout . height ,
356- pixelWidth = Math . ceil ( pixelRatio * width ) | 0 ,
357- pixelHeight = Math . ceil ( pixelRatio * height ) | 0 ;
375+ height = fullLayout . height ;
358376
359- // check for resize
360- var canvas = this . canvas ;
361- if ( canvas . width !== pixelWidth || canvas . height !== pixelHeight ) {
362- canvas . width = pixelWidth ;
363- canvas . height = pixelHeight ;
364- }
377+ this . updateSize ( this . canvas ) ;
365378
366379 var options = this . glplotOptions ;
367380 options . merge ( fullLayout ) ;
0 commit comments