Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68cdfa9

Browse files
committed
Fix nbagg
1 parent 249f19e commit 68cdfa9

File tree

1 file changed

+13
-15
lines changed
  • lib/matplotlib/backends/web_backend

1 file changed

+13
-15
lines changed

lib/matplotlib/backends/web_backend/mpl.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) {
5050
$(parent_element).append(this.root);
5151

5252
this._init_header(this);
53-
ratio = this._init_canvas(this);
53+
this._init_canvas(this);
5454
this._init_toolbar(this);
5555

5656
var fig = this;
@@ -60,7 +60,7 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) {
6060
this.ws.onopen = function () {
6161
fig.send_message("supports_binary", {value: fig.supports_binary});
6262
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});
6464
fig.send_message("refresh", {});
6565
}
6666

@@ -130,6 +130,15 @@ mpl.figure.prototype._init_canvas = function() {
130130
this.canvas = canvas[0];
131131
this.context = canvas[0].getContext("2d");
132132

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+
133142
var rubberband = $('<canvas/>');
134143
rubberband.attr('style', "position: absolute; left: 0; top: 0; z-index: 1;")
135144

@@ -186,8 +195,8 @@ mpl.figure.prototype._init_canvas = function() {
186195
canvas_div.css('width', width)
187196
canvas_div.css('height', height)
188197

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);
191200
canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');
192201

193202
rubberband.attr('width', width);
@@ -209,17 +218,6 @@ mpl.figure.prototype._init_canvas = function() {
209218
}
210219

211220
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
223221
}
224222

225223
mpl.figure.prototype._init_toolbar = function() {

0 commit comments

Comments
 (0)