@@ -50,7 +50,7 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) {
50
50
$ ( parent_element ) . append ( this . root ) ;
51
51
52
52
this . _init_header ( this ) ;
53
- ratio = this . _init_canvas ( this ) ;
53
+ this . _init_canvas ( this ) ;
54
54
this . _init_toolbar ( this ) ;
55
55
56
56
var fig = this ;
@@ -60,7 +60,7 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) {
60
60
this . ws . onopen = function ( ) {
61
61
fig . send_message ( "supports_binary" , { value : fig . supports_binary } ) ;
62
62
fig . send_message ( "send_image_mode" , { } ) ;
63
- fig . send_message ( "set_dpi_ratio" , { 'dpi_ratio' : ratio } ) ;
63
+ fig . send_message ( "set_dpi_ratio" , { 'dpi_ratio' : fig . ratio } ) ;
64
64
fig . send_message ( "refresh" , { } ) ;
65
65
}
66
66
@@ -130,6 +130,15 @@ mpl.figure.prototype._init_canvas = function() {
130
130
this . canvas = canvas [ 0 ] ;
131
131
this . context = canvas [ 0 ] . getContext ( "2d" ) ;
132
132
133
+ var backingStore = this . context . backingStorePixelRatio ||
134
+ this . context . webkitBackingStorePixelRatio ||
135
+ this . context . mozBackingStorePixelRatio ||
136
+ this . context . msBackingStorePixelRatio ||
137
+ this . context . oBackingStorePixelRatio ||
138
+ this . context . backingStorePixelRatio || 1 ;
139
+
140
+ this . ratio = ( window . devicePixelRatio || 1 ) / backingStore ;
141
+
133
142
var rubberband = $ ( '<canvas/>' ) ;
134
143
rubberband . attr ( 'style' , "position: absolute; left: 0; top: 0; z-index: 1;" )
135
144
@@ -186,8 +195,8 @@ mpl.figure.prototype._init_canvas = function() {
186
195
canvas_div . css ( 'width' , width )
187
196
canvas_div . css ( 'height' , height )
188
197
189
- canvas . attr ( 'width' , width * ratio ) ;
190
- canvas . attr ( 'height' , height * ratio ) ;
198
+ canvas . attr ( 'width' , width * this . ratio ) ;
199
+ canvas . attr ( 'height' , height * this . ratio ) ;
191
200
canvas . attr ( 'style' , 'width: ' + width + 'px; height: ' + height + 'px;' ) ;
192
201
193
202
rubberband . attr ( 'width' , width ) ;
@@ -209,17 +218,6 @@ mpl.figure.prototype._init_canvas = function() {
209
218
}
210
219
211
220
window . setTimeout ( set_focus , 100 ) ;
212
-
213
- var backingStore = this . context . backingStorePixelRatio ||
214
- this . context . webkitBackingStorePixelRatio ||
215
- this . context . mozBackingStorePixelRatio ||
216
- this . context . msBackingStorePixelRatio ||
217
- this . context . oBackingStorePixelRatio ||
218
- this . context . backingStorePixelRatio || 1 ;
219
-
220
- var ratio = ( window . devicePixelRatio || 1 ) / backingStore ;
221
-
222
- return ratio
223
221
}
224
222
225
223
mpl . figure . prototype . _init_toolbar = function ( ) {
0 commit comments