Skip to content

Commit 7ad216f

Browse files
committed
Stub out save as option for nbagg figure
1 parent b9eb1ff commit 7ad216f

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

lib/matplotlib/backends/backend_nbagg.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def connection_info():
9292
'forward': 'fa fa-arrow-right icon-arrow-right',
9393
'zoom_to_rect': 'fa fa-square-o icon-check-empty',
9494
'move': 'fa fa-arrows icon-move',
95+
'download': 'fa fa-icon-save icon-save',
9596
None: None
9697
}
9798

@@ -102,7 +103,8 @@ class NavigationIPy(NavigationToolbar2WebAgg):
102103
toolitems = [(text, tooltip_text,
103104
_FONT_AWESOME_CLASSES[image_file], name_of_method)
104105
for text, tooltip_text, image_file, name_of_method
105-
in NavigationToolbar2.toolitems
106+
in (NavigationToolbar2.toolitems +
107+
(('Download', 'Download plot', 'download', 'download'),))
106108
if image_file in _FONT_AWESOME_CLASSES]
107109

108110

lib/matplotlib/backends/web_backend/mpl.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,12 @@ mpl.figure.prototype.key_event = function(event, name) {
472472

473473
mpl.figure.prototype.toolbar_button_onclick = function(name) {
474474
if (name == 'download') {
475-
var format_dropdown = this.format_dropdown;
476-
var format = format_dropdown.options[format_dropdown.selectedIndex].value;
475+
if (this.format_dropdown) {
476+
var format_dropdown = this.format_dropdown;
477+
var format = format_dropdown.options[format_dropdown.selectedIndex].value;
478+
} else {
479+
format = 'png';
480+
}
477481
this.ondownload(this, format);
478482
} else {
479483
this.send_message("toolbar_button", {name: name});

lib/matplotlib/backends/web_backend/nbagg_mpl.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ mpl.mpl_figure_comm = function(comm, msg) {
3030
var element = $("#" + id);
3131
var ws_proxy = comm_websocket_adapter(comm)
3232

33+
function ondownload(figure, format) {
34+
window.location.href = 'hello.' + format
35+
}
36+
3337
var fig = new mpl.figure(id, ws_proxy,
34-
function() { },
38+
ondownload,
3539
element.get(0));
3640

3741
// Call onopen now - mpl needs it, as it is assuming we've passed it a real

0 commit comments

Comments
 (0)