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

Skip to content

Commit a635ff3

Browse files
committed
Show pan/zoom toggle state in nbAgg/webagg toolbars.
This uses the 'active' Bootstrap style on nbagg, and colorizes the image to tab:blue on webagg.
1 parent 4db9aea commit a635ff3

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ def save_figure(self, *args):
398398
"""Save the current figure"""
399399
self.canvas.send_event('save')
400400

401+
def pan(self):
402+
super().pan()
403+
self.canvas.send_event('navigate_mode', mode=self.mode.name)
404+
405+
def zoom(self):
406+
super().zoom()
407+
self.canvas.send_event('navigate_mode', mode=self.mode.name)
408+
401409
def set_history_buttons(self):
402410
can_backward = self._nav_stack._pos > 0
403411
can_forward = self._nav_stack._pos < len(self._nav_stack._elements) - 1

lib/matplotlib/backends/web_backend/css/mpl.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
filter: contrast(0%);
3535
}
3636

37+
.mpl-widget.active img {
38+
/* Convert black to tab:blue, approximately */
39+
filter: invert(34%) sepia(97%) saturate(468%) hue-rotate(162deg) brightness(96%) contrast(91%);
40+
}
41+
3742
button.mpl-widget:focus,
3843
button.mpl-widget:hover {
3944
background-color: #ddd;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,19 @@ mpl.figure.prototype.handle_history_buttons = function (fig, msg) {
436436
}
437437
};
438438

439+
mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {
440+
if (msg['mode'] === 'PAN') {
441+
fig.buttons['Pan'].classList.add('active');
442+
fig.buttons['Zoom'].classList.remove('active');
443+
} else if (msg['mode'] === 'ZOOM') {
444+
fig.buttons['Pan'].classList.remove('active');
445+
fig.buttons['Zoom'].classList.add('active');
446+
} else {
447+
fig.buttons['Pan'].classList.remove('active');
448+
fig.buttons['Zoom'].classList.remove('active');
449+
}
450+
};
451+
439452
mpl.figure.prototype.updated_canvas_event = function () {
440453
// Called whenever the canvas gets updated.
441454
this.send_message('ack', {});

0 commit comments

Comments
 (0)