Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4db9aea

Browse filesBrowse files
committed
Implement set_history_buttons for nbAgg/WebAgg.
1 parent c942935 commit 4db9aea
Copy full SHA for 4db9aea

File tree

Expand file treeCollapse file tree

4 files changed

+45
-6
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+45
-6
lines changed

‎lib/matplotlib/backends/backend_webagg_core.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_webagg_core.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ def handle_refresh(self, event):
308308
figure_label = "Figure {0}".format(self.manager.num)
309309
self.send_event('figure_label', label=figure_label)
310310
self._force_full = True
311+
if self.toolbar:
312+
# Normal toolbar init would refresh this, but it happens before the
313+
# browser canvas is set up.
314+
self.toolbar.set_history_buttons()
311315
self.draw_idle()
312316

313317
def handle_resize(self, event):
@@ -394,6 +398,12 @@ def save_figure(self, *args):
394398
"""Save the current figure"""
395399
self.canvas.send_event('save')
396400

401+
def set_history_buttons(self):
402+
can_backward = self._nav_stack._pos > 0
403+
can_forward = self._nav_stack._pos < len(self._nav_stack._elements) - 1
404+
self.canvas.send_event('history_buttons',
405+
Back=can_backward, Forward=can_forward)
406+
397407

398408
class FigureManagerWebAgg(backend_bases.FigureManagerBase):
399409
ToolbarCls = NavigationToolbar2WebAgg

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

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/web_backend/css/mpl.css
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@
2121
vertical-align: middle;
2222
}
2323

24+
.mpl-widget:disabled,
25+
.mpl-widget[disabled] {
26+
background-color: #ddd;
27+
border-color: #ddd !important;
28+
cursor: not-allowed;
29+
}
30+
31+
.mpl-widget:disabled img,
32+
.mpl-widget[disabled] img {
33+
/* Convert black to grey */
34+
filter: contrast(0%);
35+
}
36+
2437
button.mpl-widget:focus,
2538
button.mpl-widget:hover {
2639
background-color: #ddd;

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

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/web_backend/js/mpl.js
+16-3Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,14 @@ mpl.figure.prototype._init_toolbar = function () {
267267
}
268268

269269
function on_mouseover_closure(tooltip) {
270-
return function (_event) {
271-
return fig.toolbar_button_onmouseover(tooltip);
270+
return function (event) {
271+
if (!event.currentTarget.disabled) {
272+
return fig.toolbar_button_onmouseover(tooltip);
273+
}
272274
};
273275
}
274276

277+
fig.buttons = {};
275278
var buttonGroup = document.createElement('div');
276279
buttonGroup.classList = 'mpl-button-group';
277280
for (var toolbar_ind in mpl.toolbar_items) {
@@ -290,7 +293,7 @@ mpl.figure.prototype._init_toolbar = function () {
290293
continue;
291294
}
292295

293-
var button = document.createElement('button');
296+
var button = (fig.buttons[name] = document.createElement('button'));
294297
button.classList = 'mpl-widget';
295298
button.setAttribute('role', 'button');
296299
button.setAttribute('aria-disabled', 'false');
@@ -423,6 +426,16 @@ mpl.figure.prototype.handle_image_mode = function (fig, msg) {
423426
fig.image_mode = msg['mode'];
424427
};
425428

429+
mpl.figure.prototype.handle_history_buttons = function (fig, msg) {
430+
for (var key in msg) {
431+
if (!(key in fig.buttons)) {
432+
continue;
433+
}
434+
fig.buttons[key].disabled = !msg[key];
435+
fig.buttons[key].setAttribute('aria-disabled', !msg[key]);
436+
}
437+
};
438+
426439
mpl.figure.prototype.updated_canvas_event = function () {
427440
// Called whenever the canvas gets updated.
428441
this.send_message('ack', {});

‎lib/matplotlib/backends/web_backend/js/nbagg_mpl.js

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/web_backend/js/nbagg_mpl.js
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,14 @@ mpl.figure.prototype._init_toolbar = function () {
104104
}
105105

106106
function on_mouseover_closure(tooltip) {
107-
return function (_event) {
108-
return fig.toolbar_button_onmouseover(tooltip);
107+
return function (event) {
108+
if (!event.currentTarget.disabled) {
109+
return fig.toolbar_button_onmouseover(tooltip);
110+
}
109111
};
110112
}
111113

114+
fig.buttons = {};
112115
var buttonGroup = document.createElement('div');
113116
buttonGroup.classList = 'btn-group';
114117
var button;
@@ -128,7 +131,7 @@ mpl.figure.prototype._init_toolbar = function () {
128131
continue;
129132
}
130133

131-
button = document.createElement('button');
134+
button = fig.buttons[name] = document.createElement('button');
132135
button.classList = 'btn btn-default';
133136
button.href = '#';
134137
button.title = name;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.