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

Skip to content

Handle HiDPI displays in WebAgg/NbAgg backends #5383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 10, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix scale of mouse events when in HiDPI mode
  • Loading branch information
mdboom committed Nov 17, 2015
commit c08e2510f21b76a6936e8269b586009ef35a9f45
22 changes: 11 additions & 11 deletions lib/matplotlib/backends/web_backend/mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) {
this.ws.onopen = function () {
fig.send_message("supports_binary", {value: fig.supports_binary});
fig.send_message("send_image_mode", {});
if (fig.ratio != 1) {
fig.send_message("set_dpi_ratio", {'dpi_ratio': fig.ratio});
if (mpl.ratio != 1) {
fig.send_message("set_dpi_ratio", {'dpi_ratio': mpl.ratio});
}
fig.send_message("refresh", {});
}
Expand Down Expand Up @@ -139,7 +139,7 @@ mpl.figure.prototype._init_canvas = function() {
this.context.oBackingStorePixelRatio ||
this.context.backingStorePixelRatio || 1;

this.ratio = (window.devicePixelRatio || 1) / backingStore;
mpl.ratio = (window.devicePixelRatio || 1) / backingStore;

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

canvas.attr('width', width * this.ratio);
canvas.attr('height', height * this.ratio);
canvas.attr('width', width * mpl.ratio);
canvas.attr('height', height * mpl.ratio);
canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');

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

mpl.figure.prototype.handle_rubberband = function(fig, msg) {
var x0 = msg['x0'];
var y0 = fig.canvas.height - msg['y0'];
var x1 = msg['x1'];
var y1 = fig.canvas.height - msg['y1'];
var x0 = msg['x0'] / mpl.ratio;
var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;
var x1 = msg['x1'] / mpl.ratio;
var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;
x0 = Math.floor(x0) + 0.5;
y0 = Math.floor(y0) + 0.5;
x1 = Math.floor(x1) + 0.5;
Expand Down Expand Up @@ -491,8 +491,8 @@ mpl.figure.prototype.mouse_event = function(event, name) {
this.canvas_div.focus();
}

var x = canvas_pos.x;
var y = canvas_pos.y;
var x = canvas_pos.x * mpl.ratio;
var y = canvas_pos.y * mpl.ratio;

this.send_message(name, {x: x, y: y, button: event.button,
step: event.step,
Expand Down