@@ -62,8 +62,8 @@ mpl.figure = function (figure_id, websocket, ondownload, parent_element) {
6262 this . ws . onopen = function ( ) {
6363 fig . send_message ( 'supports_binary' , { value : fig . supports_binary } ) ;
6464 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 } ) ;
6767 }
6868 fig . send_message ( 'refresh' , { } ) ;
6969 } ;
@@ -156,7 +156,10 @@ mpl.figure.prototype._init_canvas = function () {
156156 this . context . backingStorePixelRatio ||
157157 1 ;
158158
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+ }
160163
161164 var rubberband_canvas = ( this . rubberband_canvas = document . createElement (
162165 'canvas'
@@ -200,8 +203,8 @@ mpl.figure.prototype._init_canvas = function () {
200203 entry . devicePixelContentBoxSize [ 0 ] . blockSize
201204 ) ;
202205 } 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 ) ;
205208 }
206209 canvas . setAttribute (
207210 'style' ,
@@ -399,10 +402,10 @@ mpl.figure.prototype.handle_resize = function (fig, msg) {
399402} ;
400403
401404mpl . 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 ;
406409 x0 = Math . floor ( x0 ) + 0.5 ;
407410 y0 = Math . floor ( y0 ) + 0.5 ;
408411 x1 = Math . floor ( x1 ) + 0.5 ;
@@ -415,8 +418,8 @@ mpl.figure.prototype.handle_rubberband = function (fig, msg) {
415418 fig . rubberband_context . clearRect (
416419 0 ,
417420 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
420423 ) ;
421424
422425 fig . rubberband_context . strokeRect ( min_x , min_y , width , height ) ;
@@ -599,8 +602,8 @@ mpl.figure.prototype.mouse_event = function (event, name) {
599602 this . canvas_div . focus ( ) ;
600603 }
601604
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 ;
604607
605608 this . send_message ( name , {
606609 x : x ,
0 commit comments