@@ -115,6 +115,8 @@ mpl.figure.prototype._init_canvas = function () {
115
115
'border: 1px solid #ddd;' +
116
116
'box-sizing: content-box;' +
117
117
'clear: both;' +
118
+ 'min-height: 1px;' +
119
+ 'min-width: 1px;' +
118
120
'outline: 0;' +
119
121
'overflow: hidden;' +
120
122
'position: relative;' +
@@ -168,16 +170,32 @@ mpl.figure.prototype._init_canvas = function () {
168
170
var nentries = entries . length ;
169
171
for ( var i = 0 ; i < nentries ; i ++ ) {
170
172
var entry = entries [ i ] ;
173
+ var width , height ;
171
174
if ( entry . contentBoxSize ) {
172
- fig . request_resize (
173
- entry . contentBoxSize . inlineSize ,
174
- entry . contentBoxSize . blockSize
175
- ) ;
175
+ width = entry . contentBoxSize . inlineSize ;
176
+ height = entry . contentBoxSize . blockSize ;
176
177
} else {
177
- fig . request_resize (
178
- entry . contentRect . width ,
179
- entry . contentRect . height
180
- ) ;
178
+ width = entry . contentRect . width ;
179
+ height = entry . contentRect . height ;
180
+ }
181
+
182
+ // Keep the size of the canvas and rubber band canvas in sync with
183
+ // the canvas container.
184
+ canvas . setAttribute ( 'width' , width * mpl . ratio ) ;
185
+ canvas . setAttribute ( 'height' , height * mpl . ratio ) ;
186
+ canvas . setAttribute (
187
+ 'style' ,
188
+ 'width: ' + width + 'px; height: ' + height + 'px;'
189
+ ) ;
190
+
191
+ rubberband_canvas . setAttribute ( 'width' , width ) ;
192
+ rubberband_canvas . setAttribute ( 'height' , height ) ;
193
+
194
+ // And update the size in Python. We ignore the initial 0/0 size
195
+ // that occurs as the element is placed into the DOM, which should
196
+ // otherwise not happen due to the minimum size styling.
197
+ if ( width != 0 && height != 0 ) {
198
+ fig . request_resize ( width , height ) ;
181
199
}
182
200
}
183
201
} ) ;
@@ -228,28 +246,12 @@ mpl.figure.prototype._init_canvas = function () {
228
246
this . rubberband_context . strokeStyle = '#000000' ;
229
247
230
248
this . _resize_canvas = function ( width , height , forward ) {
231
- // Keep the size of the canvas and rubber band canvas in sync with the
232
- // canvas container.
233
249
if ( forward ) {
234
250
canvas_div . style . width = width + 'px' ;
235
251
canvas_div . style . height = height + 'px' ;
236
252
}
237
-
238
- canvas . setAttribute ( 'width' , width * mpl . ratio ) ;
239
- canvas . setAttribute ( 'height' , height * mpl . ratio ) ;
240
- canvas . setAttribute (
241
- 'style' ,
242
- 'width: ' + width + 'px; height: ' + height + 'px;'
243
- ) ;
244
-
245
- rubberband_canvas . setAttribute ( 'width' , width ) ;
246
- rubberband_canvas . setAttribute ( 'height' , height ) ;
247
253
} ;
248
254
249
- // Set the figure to an initial 600x600px, this will subsequently be updated
250
- // upon first draw.
251
- this . _resize_canvas ( 600 , 600 , true ) ;
252
-
253
255
// Disable right mouse context menu.
254
256
this . rubberband_canvas . addEventListener ( 'contextmenu' , function ( _e ) {
255
257
return false ;
0 commit comments