@@ -124,19 +124,17 @@ proto.makeFramework = function() {
124124 }
125125
126126 // position the canvas
127- var canvas = this . canvas ,
128- pixelRatio = this . pixelRatio ,
129- fullLayout = this . fullLayout ;
127+ var canvas = this . canvas ;
130128
131- canvas . width = Math . ceil ( pixelRatio * fullLayout . width ) | 0 ;
132- canvas . height = Math . ceil ( pixelRatio * fullLayout . height ) | 0 ;
133129 canvas . style . width = '100%' ;
134130 canvas . style . height = '100%' ;
135131 canvas . style . position = 'absolute' ;
136132 canvas . style . top = '0px' ;
137133 canvas . style . left = '0px' ;
138134 canvas . style [ 'pointer-events' ] = 'none' ;
139135
136+ this . updateSize ( canvas ) ;
137+
140138 // disabling user select on the canvas
141139 // sanitizes double-clicks interactions
142140 // ref: https://github.com/plotly/plotly.js/issues/744
@@ -169,25 +167,8 @@ proto.toImage = function(format) {
169167 this . stopped = true ;
170168 if ( this . staticPlot ) this . container . appendChild ( STATIC_CANVAS ) ;
171169
172-
173-
174- var glplot = this . glplot ,
175- pixelRatio = this . pixelRatio ,
176- fullLayout = this . fullLayout ;
177-
178- var width = fullLayout . width ,
179- height = fullLayout . height ,
180- pixelWidth = Math . ceil ( pixelRatio * width ) | 0 ,
181- pixelHeight = Math . ceil ( pixelRatio * height ) | 0 ;
182-
183- // check for resize
184- var canvas = this . canvas ;
185- if ( canvas . width !== pixelWidth || canvas . height !== pixelHeight ) {
186- canvas . width = pixelWidth ;
187- canvas . height = pixelHeight ;
188- }
189-
190-
170+ //update canvas size
171+ this . updateSize ( this . canvas ) ;
191172
192173 // force redraw
193174 this . glplot . setDirty ( ) ;
@@ -241,6 +222,26 @@ proto.toImage = function(format) {
241222 return dataURL ;
242223} ;
243224
225+ proto . updateSize = function ( canvas ) {
226+ if ( ! canvas ) canvas = this . canvas ;
227+
228+ var pixelRatio = this . pixelRatio ,
229+ fullLayout = this . fullLayout ;
230+
231+ var width = fullLayout . width ,
232+ height = fullLayout . height ,
233+ pixelWidth = Math . ceil ( pixelRatio * width ) | 0 ,
234+ pixelHeight = Math . ceil ( pixelRatio * height ) | 0 ;
235+
236+ // check for resize
237+ if ( canvas . width !== pixelWidth || canvas . height !== pixelHeight ) {
238+ canvas . width = pixelWidth ;
239+ canvas . height = pixelHeight ;
240+ }
241+
242+ return canvas ;
243+ }
244+
244245proto . computeTickMarks = function ( ) {
245246 this . xaxis . _length =
246247 this . glplot . viewBox [ 2 ] - this . glplot . viewBox [ 0 ] ;
@@ -365,16 +366,9 @@ proto.plot = function(fullData, calcData, fullLayout) {
365366 this . updateTraces ( fullData , calcData ) ;
366367
367368 var width = fullLayout . width ,
368- height = fullLayout . height ,
369- pixelWidth = Math . ceil ( pixelRatio * width ) | 0 ,
370- pixelHeight = Math . ceil ( pixelRatio * height ) | 0 ;
369+ height = fullLayout . height ;
371370
372- // check for resize
373- var canvas = this . canvas ;
374- if ( canvas . width !== pixelWidth || canvas . height !== pixelHeight ) {
375- canvas . width = pixelWidth ;
376- canvas . height = pixelHeight ;
377- }
371+ this . updateSize ( this . canvas ) ;
378372
379373 var options = this . glplotOptions ;
380374 options . merge ( fullLayout ) ;
0 commit comments