@@ -62,8 +62,8 @@ mpl.figure = function (figure_id, websocket, ondownload, parent_element) {
62
62
this . ws . onopen = function ( ) {
63
63
fig . send_message ( 'supports_binary' , { value : fig . supports_binary } ) ;
64
64
fig . send_message ( 'send_image_mode' , { } ) ;
65
- if ( mpl . ratio !== 1 ) {
66
- fig . send_message ( 'set_dpi_ratio' , { dpi_ratio : mpl . ratio } ) ;
65
+ if ( fig . ratio !== 1 ) {
66
+ fig . send_message ( 'set_dpi_ratio' , { dpi_ratio : fig . ratio } ) ;
67
67
}
68
68
fig . send_message ( 'refresh' , { } ) ;
69
69
} ;
@@ -156,7 +156,10 @@ mpl.figure.prototype._init_canvas = function () {
156
156
this . context . backingStorePixelRatio ||
157
157
1 ;
158
158
159
- mpl . ratio = ( window . devicePixelRatio || 1 ) / backingStore ;
159
+ this . ratio = ( window . devicePixelRatio || 1 ) / backingStore ;
160
+ if ( this . ratio !== 1 ) {
161
+ fig . send_message ( 'set_dpi_ratio' , { dpi_ratio : this . ratio } ) ;
162
+ }
160
163
161
164
var rubberband_canvas = ( this . rubberband_canvas = document . createElement (
162
165
'canvas'
@@ -200,8 +203,8 @@ mpl.figure.prototype._init_canvas = function () {
200
203
entry . devicePixelContentBoxSize [ 0 ] . blockSize
201
204
) ;
202
205
} else {
203
- canvas . setAttribute ( 'width' , width * mpl . ratio ) ;
204
- canvas . setAttribute ( 'height' , height * mpl . ratio ) ;
206
+ canvas . setAttribute ( 'width' , width * fig . ratio ) ;
207
+ canvas . setAttribute ( 'height' , height * fig . ratio ) ;
205
208
}
206
209
canvas . setAttribute (
207
210
'style' ,
@@ -399,10 +402,10 @@ mpl.figure.prototype.handle_resize = function (fig, msg) {
399
402
} ;
400
403
401
404
mpl . figure . prototype . handle_rubberband = function ( fig , msg ) {
402
- var x0 = msg [ 'x0' ] / mpl . ratio ;
403
- var y0 = ( fig . canvas . height - msg [ 'y0' ] ) / mpl . ratio ;
404
- var x1 = msg [ 'x1' ] / mpl . ratio ;
405
- var y1 = ( fig . canvas . height - msg [ 'y1' ] ) / mpl . ratio ;
405
+ var x0 = msg [ 'x0' ] / fig . ratio ;
406
+ var y0 = ( fig . canvas . height - msg [ 'y0' ] ) / fig . ratio ;
407
+ var x1 = msg [ 'x1' ] / fig . ratio ;
408
+ var y1 = ( fig . canvas . height - msg [ 'y1' ] ) / fig . ratio ;
406
409
x0 = Math . floor ( x0 ) + 0.5 ;
407
410
y0 = Math . floor ( y0 ) + 0.5 ;
408
411
x1 = Math . floor ( x1 ) + 0.5 ;
@@ -415,8 +418,8 @@ mpl.figure.prototype.handle_rubberband = function (fig, msg) {
415
418
fig . rubberband_context . clearRect (
416
419
0 ,
417
420
0 ,
418
- fig . canvas . width / mpl . ratio ,
419
- fig . canvas . height / mpl . ratio
421
+ fig . canvas . width / fig . ratio ,
422
+ fig . canvas . height / fig . ratio
420
423
) ;
421
424
422
425
fig . rubberband_context . strokeRect ( min_x , min_y , width , height ) ;
@@ -599,8 +602,8 @@ mpl.figure.prototype.mouse_event = function (event, name) {
599
602
this . canvas_div . focus ( ) ;
600
603
}
601
604
602
- var x = canvas_pos . x * mpl . ratio ;
603
- var y = canvas_pos . y * mpl . ratio ;
605
+ var x = canvas_pos . x * this . ratio ;
606
+ var y = canvas_pos . y * this . ratio ;
604
607
605
608
this . send_message ( name , {
606
609
x : x ,
0 commit comments