Skip to content

Commit

Permalink
Merge pull request #4035 from eyurtsev/fix_webagg_resize_02
Browse files Browse the repository at this point in the history
FIX : resizing a figure in webagg
  • Loading branch information
tacaswell committed Jan 26, 2015
2 parents d6e1577 + 0a245ac commit 61fd742
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions lib/matplotlib/backends/web_backend/mpl.js
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);
};
}

0 comments on commit 61fd742

Please sign in to comment.