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

Skip to content

fix for figure resizing in webagg #3341

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
45 changes: 39 additions & 6 deletions lib/matplotlib/backends/web_backend/mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) {
this.rubberband_context = undefined;
this.format_dropdown = undefined;

this.focus_on_mousover = false;
this.focus_on_mouseover = false;

this.root = $('<div/>');
this.root.attr('style', 'display: inline-block');
Expand Down Expand Up @@ -89,9 +89,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;');
this.root.append(canvas_div);
Expand All @@ -109,8 +106,44 @@ mpl.figure.prototype._init_canvas = function() {

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

var ignore_mouse_events = false;

// The if statement below should just be implemented directly in CSS...
if (!$("head").hasClass("boxme"))
{
$("<style type='text/css'> .boxme { background-color: lightgray; border: 1px solid gray;} </style>").appendTo("head");
}

canvas_div.resizable({
start: function(event, ui) {
ignore_mouse_events = true;
ctx = fig.context;
var canvas = ctx.canvas;
canvas.blur(); // removes focus if focused (may need more work?)
canvas_div.addClass("boxme");

/// Clearing the canvas
// Store the current transformation matrix
ctx.save();
// Use the identity matrix while clearing the canvas
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Restore the transform
ctx.restore();
},
stop: function(event, ui) {
ignore_mouse_events = false;
fig.request_resize(ui.size.width, ui.size.height);
canvas_div.removeClass("boxme");
},
});

function mouse_event_fn(event) {
return fig.mouse_event(event, event['data']);
if (ignore_mouse_events == false)
{
return fig.mouse_event(event, event['data']);
}
}
rubberband.mousedown('button_press', mouse_event_fn);
rubberband.mouseup('button_release', mouse_event_fn);
Expand Down Expand Up @@ -379,7 +412,7 @@ mpl.findpos = function(e) {
};

mpl.figure.prototype.mouse_event = function(event, name) {
var canvas_pos = mpl.findpos(event)
var canvas_pos = mpl.findpos(event);

if (this.focus_on_mouseover && name === 'motion_notify')
{
Expand Down