Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc08e251

Browse files
committed
Fix scale of mouse events when in HiDPI mode
1 parent17c7259 commitc08e251

File tree

1 file changed

+11
-11
lines changed
  • lib/matplotlib/backends/web_backend

1 file changed

+11
-11
lines changed

‎lib/matplotlib/backends/web_backend/mpl.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ 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-
if(fig.ratio!=1){
64-
fig.send_message("set_dpi_ratio",{'dpi_ratio':fig.ratio});
63+
if(mpl.ratio!=1){
64+
fig.send_message("set_dpi_ratio",{'dpi_ratio':mpl.ratio});
6565
}
6666
fig.send_message("refresh",{});
6767
}
@@ -139,7 +139,7 @@ mpl.figure.prototype._init_canvas = function() {
139139
this.context.oBackingStorePixelRatio||
140140
this.context.backingStorePixelRatio||1;
141141

142-
this.ratio=(window.devicePixelRatio||1)/backingStore;
142+
mpl.ratio=(window.devicePixelRatio||1)/backingStore;
143143

144144
varrubberband=$('<canvas/>');
145145
rubberband.attr('style',"position: absolute; left: 0; top: 0; z-index: 1;")
@@ -197,8 +197,8 @@ mpl.figure.prototype._init_canvas = function() {
197197
canvas_div.css('width',width)
198198
canvas_div.css('height',height)
199199

200-
canvas.attr('width',width*this.ratio);
201-
canvas.attr('height',height*this.ratio);
200+
canvas.attr('width',width*mpl.ratio);
201+
canvas.attr('height',height*mpl.ratio);
202202
canvas.attr('style','width: '+width+'px; height: '+height+'px;');
203203

204204
rubberband.attr('width',width);
@@ -332,10 +332,10 @@ mpl.figure.prototype.handle_resize = function(fig, msg) {
332332
}
333333

334334
mpl.figure.prototype.handle_rubberband=function(fig,msg){
335-
varx0=msg['x0'];
336-
vary0=fig.canvas.height-msg['y0'];
337-
varx1=msg['x1'];
338-
vary1=fig.canvas.height-msg['y1'];
335+
varx0=msg['x0']/mpl.ratio;
336+
vary0=(fig.canvas.height-msg['y0'])/mpl.ratio;
337+
varx1=msg['x1']/mpl.ratio;
338+
vary1=(fig.canvas.height-msg['y1'])/mpl.ratio;
339339
x0=Math.floor(x0)+0.5;
340340
y0=Math.floor(y0)+0.5;
341341
x1=Math.floor(x1)+0.5;
@@ -491,8 +491,8 @@ mpl.figure.prototype.mouse_event = function(event, name) {
491491
this.canvas_div.focus();
492492
}
493493

494-
varx=canvas_pos.x;
495-
vary=canvas_pos.y;
494+
varx=canvas_pos.x*mpl.ratio;
495+
vary=canvas_pos.y*mpl.ratio;
496496

497497
this.send_message(name,{x:x,y:y,button:event.button,
498498
step:event.step,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp