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

Skip to content

Commit 1e3f7f3

Browse files
committed
Translate cursors to webagg/nbagg on the Python side.
The JavaScript side is just strings and not some special type, so it's nicer to translate on the Python side. This way, we don't have to remember what the Python Enum is on the JS side.
1 parent 8c764dc commit 1e3f7f3

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from PIL import Image
2222
import tornado
2323

24-
from matplotlib import _api, backend_bases
24+
from matplotlib import _api, backend_bases, backend_tools
2525
from matplotlib.backends import backend_agg
2626
from matplotlib.backend_bases import _Backend
2727

@@ -364,7 +364,7 @@ class NavigationToolbar2WebAgg(backend_bases.NavigationToolbar2):
364364

365365
def __init__(self, canvas):
366366
self.message = ''
367-
self.cursor = 0
367+
self.cursor = None
368368
super().__init__(canvas)
369369

370370
def set_message(self, message):
@@ -374,6 +374,13 @@ def set_message(self, message):
374374

375375
def set_cursor(self, cursor):
376376
if cursor != self.cursor:
377+
cursor = {
378+
backend_tools.Cursors.HAND: 'pointer',
379+
backend_tools.Cursors.POINTER: 'default',
380+
backend_tools.Cursors.SELECT_REGION: 'crosshair',
381+
backend_tools.Cursors.MOVE: 'move',
382+
backend_tools.Cursors.WAIT: 'wait',
383+
}[cursor]
377384
self.canvas.send_event("cursor", cursor=cursor)
378385
self.cursor = cursor
379386

lib/matplotlib/backends/web_backend/js/mpl.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -444,22 +444,7 @@ mpl.figure.prototype.handle_figure_label = function (fig, msg) {
444444
};
445445

446446
mpl.figure.prototype.handle_cursor = function (fig, msg) {
447-
var cursor = msg['cursor'];
448-
switch (cursor) {
449-
case 0:
450-
cursor = 'pointer';
451-
break;
452-
case 1:
453-
cursor = 'default';
454-
break;
455-
case 2:
456-
cursor = 'crosshair';
457-
break;
458-
case 3:
459-
cursor = 'move';
460-
break;
461-
}
462-
fig.rubberband_canvas.style.cursor = cursor;
447+
fig.rubberband_canvas.style.cursor = msg['cursor'];
463448
};
464449

465450
mpl.figure.prototype.handle_message = function (fig, msg) {

0 commit comments

Comments
 (0)