Skip to content

Commit 3945579

Browse files
committed
Add scroll event handling to javascript
Conflicts: lib/matplotlib/backends/web_backend/mpl.js
1 parent 9a4cc84 commit 3945579

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/matplotlib/backends/web_backend/mpl.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ mpl.findpos = function(e) {
425425
};
426426

427427
mpl.figure.prototype.mouse_event = function(event, name) {
428+
428429
var canvas_pos = mpl.findpos(event)
429430

430431
if (name === 'button_press')
@@ -436,6 +437,11 @@ mpl.figure.prototype.mouse_event = function(event, name) {
436437
var x = canvas_pos.x;
437438
var y = canvas_pos.y;
438439

440+
<<<<<<< HEAD
441+
=======
442+
console.log(name);
443+
444+
>>>>>>> b1331ff... Add scroll event handling to javascript
439445
this.send_message(name, {x: x, y: y, button: event.button,
440446
step: event.step});
441447

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import matplotlib
2+
import itertools
3+
import numpy as np
4+
matplotlib.use('webagg')
5+
import matplotlib.pyplot as plt
6+
plt.close('all')
7+
fig, ax = plt.subplots()
8+
x = np.linspace(0,10,100)
9+
y = np.sin(x)
10+
ln, = ax.plot(x,y, 'o', picker=5)
11+
evt = []
12+
colors = iter(itertools.cycle(['r', 'g', 'b', 'k', 'c']))
13+
def on_event(event):
14+
evt.append(event)
15+
ln.set_color(next(colors))
16+
fig.canvas.draw()
17+
fig.canvas.draw_idle()
18+
fig.canvas.mpl_connect('figure_enter_event', on_event)
19+
fig.canvas.mpl_connect('figure_leave_event', on_event)
20+
plt.show()
21+

0 commit comments

Comments
 (0)