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

Skip to content

Add Support for scroll_event in WebAgg and NbAgg [backport to 1.4.x] #3968

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 22 commits into from
Jan 11, 2015
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def handle_event(self, event):
elif e_type == 'draw':
self.draw()
elif e_type in ('button_press', 'button_release', 'motion_notify',
'figure_enter', 'figure_leave'):
'figure_enter', 'figure_leave', 'scroll'):
x = event['x']
y = event['y']
y = self.get_renderer().height - y
Expand All @@ -218,6 +218,8 @@ def handle_event(self, event):
self.enter_notify_event(xy=(x, y))
elif e_type == 'figure_leave':
self.leave_notify_event()
elif e_type == 'scroll':
self.scroll_event(x, y, event['step'])
elif e_type in ('key_press', 'key_release'):
key = event['key']

Expand Down
17 changes: 16 additions & 1 deletion lib/matplotlib/backends/web_backend/mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ mpl.figure.prototype._init_header = function() {
this.header = titletext[0];
}



mpl.figure.prototype._canvas_extra_style = function(canvas_div) {

}
Expand Down Expand Up @@ -143,6 +145,17 @@ mpl.figure.prototype._init_canvas = function() {
rubberband.mouseenter('figure_enter', mouse_event_fn);
rubberband.mouseleave('figure_leave', mouse_event_fn);

canvas_div.on("wheel", function (event) {
event = event.originalEvent;
event['data'] = 'scroll'
if (event.deltaY < 0) {
event.step = 1;
} else {
event.step = -1;
}
mouse_event_fn(event);
});

canvas_div.append(canvas);
canvas_div.append(rubberband);

Expand All @@ -168,6 +181,7 @@ mpl.figure.prototype._init_canvas = function() {
// upon first draw.
this._resize_canvas(600, 600);


function set_focus () {
canvas.focus();
canvas_div.focus();
Expand Down Expand Up @@ -425,7 +439,8 @@ mpl.figure.prototype.mouse_event = function(event, name) {
var x = canvas_pos.x;
var y = canvas_pos.y;

this.send_message(name, {x: x, y: y, button: event.button});
this.send_message(name, {x: x, y: y, button: event.button,
step: event.step});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what done js do if you have not set a value for event.step? I assume magically pass a null-like value...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JS assigns it to undefined which is translated to None AFAIK.


/* This prevents the web browser from automatically changing to
* the text insertion cursor when the button is pressed. We want
Expand Down
7 changes: 4 additions & 3 deletions lib/matplotlib/backends/web_backend/nbagg_uat.ipynb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
"signature": "sha256:43daeaae8ae9fd496fc33d7a64639194bc009b755d28c23cd6329f225628197c"
"signature": "sha256:7f7ec6a6e2a63837a45a88a501ba3c5b1eb88e744925456a9bfeb0d6faa896a5"
},
"nbformat": 3,
"nbformat_minor": 0,
Expand Down Expand Up @@ -400,9 +400,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### UAT 16 - key events\n",
"### UAT 16 - Events\n",
"\n",
"Pressing any keyboard key or mouse button should cycle the line line while the figure has focus. The figure should have focus by default when it is created and re-gain it by clicking on the canvas. Clicking anywhere outside of the figure should release focus, but moving the mouse out of the figure should not release focus."
"Pressing any keyboard key or mouse button (or scrolling) should cycle the line line while the figure has focus. The figure should have focus by default when it is created and re-gain it by clicking on the canvas. Clicking anywhere outside of the figure should release focus, but moving the mouse out of the figure should not release focus."
]
},
{
Expand All @@ -423,6 +423,7 @@
" fig.canvas.draw_idle()\n",
"fig.canvas.mpl_connect('button_press_event', on_event)\n",
"fig.canvas.mpl_connect('key_press_event', on_event)\n",
"fig.canvas.mpl_connect('scroll_event', on_event)\n",
"plt.show()"
],
"language": "python",
Expand Down