Skip to content
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

FIX: resizing a figure in webagg #4035

Merged
merged 1 commit into from
Jan 26, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 19 additions & 20 deletions lib/matplotlib/backends/web_backend/mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ mpl.figure.prototype._init_canvas = function() {
var fig = this;

var canvas_div = $('<div/>');
canvas_div.resizable({ resize: mpl.debounce_resize(
function(event, ui) { fig.request_resize(ui.size.width, ui.size.height); }
, 50)});

canvas_div.attr('style', 'position: relative; clear: both; outline: 0');

Expand All @@ -134,9 +131,27 @@ mpl.figure.prototype._init_canvas = function() {

var rubberband = $('<canvas/>');
rubberband.attr('style', "position: absolute; left: 0; top: 0; z-index: 1;")

var pass_mouse_events = true;

canvas_div.resizable({
start: function(event, ui) {
pass_mouse_events = false;
},
resize: function(event, ui) {
fig.request_resize(ui.size.width, ui.size.height);
},
stop: function(event, ui) {
pass_mouse_events = true;
fig.request_resize(ui.size.width, ui.size.height);
},
});

function mouse_event_fn(event) {
return fig.mouse_event(event, event['data']);
if (pass_mouse_events)
return fig.mouse_event(event, event['data']);
}

rubberband.mousedown('button_press', mouse_event_fn);
rubberband.mouseup('button_release', mouse_event_fn);
// Throttle sequential mouse events to 1 every 20ms.
Expand Down Expand Up @@ -489,19 +504,3 @@ mpl.figure.prototype.toolbar_button_onclick = function(name) {
mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {
this.message.textContent = tooltip;
};

mpl.debounce_event = function(func, time) {
var timer;
return function(event) {
clearTimeout(timer);
timer = setTimeout(function() { func(event); }, time);
};
}

mpl.debounce_resize = function(func, time) {
var timer;
return function(event, ui) {
clearTimeout(timer);
timer = setTimeout(function() { func(event, ui); }, time);
};
}