@@ -124,19 +124,17 @@ proto.makeFramework = function() {
124
124
}
125
125
126
126
// position the canvas
127
- var canvas = this . canvas ,
128
- pixelRatio = this . pixelRatio ,
129
- fullLayout = this . fullLayout ;
127
+ var canvas = this . canvas ;
130
128
131
- canvas . width = Math . ceil ( pixelRatio * fullLayout . width ) | 0 ;
132
- canvas . height = Math . ceil ( pixelRatio * fullLayout . height ) | 0 ;
133
129
canvas . style . width = '100%' ;
134
130
canvas . style . height = '100%' ;
135
131
canvas . style . position = 'absolute' ;
136
132
canvas . style . top = '0px' ;
137
133
canvas . style . left = '0px' ;
138
134
canvas . style [ 'pointer-events' ] = 'none' ;
139
135
136
+ this . updateSize ( canvas ) ;
137
+
140
138
// disabling user select on the canvas
141
139
// sanitizes double-clicks interactions
142
140
// ref: https://github.com/plotly/plotly.js/issues/744
@@ -169,25 +167,8 @@ proto.toImage = function(format) {
169
167
this . stopped = true ;
170
168
if ( this . staticPlot ) this . container . appendChild ( STATIC_CANVAS ) ;
171
169
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 ) ;
191
172
192
173
// force redraw
193
174
this . glplot . setDirty ( ) ;
@@ -241,6 +222,26 @@ proto.toImage = function(format) {
241
222
return dataURL ;
242
223
} ;
243
224
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
+
244
245
proto . computeTickMarks = function ( ) {
245
246
this . xaxis . _length =
246
247
this . glplot . viewBox [ 2 ] - this . glplot . viewBox [ 0 ] ;
@@ -365,16 +366,9 @@ proto.plot = function(fullData, calcData, fullLayout) {
365
366
this . updateTraces ( fullData , calcData ) ;
366
367
367
368
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 ;
371
370
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 ) ;
378
372
379
373
var options = this . glplotOptions ;
380
374
options . merge ( fullLayout ) ;
0 commit comments