Skip to content

Add Save Tool to NbAgg Figure [backport to 1.4.x] #3974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 12, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Stub out save as option for nbagg figure
  • Loading branch information
blink1073 committed Jan 12, 2015
commit 7ad216fa3ebf1a9d2499adbcc9f376ff4fa41d2e
4 changes: 3 additions & 1 deletion lib/matplotlib/backends/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def connection_info():
'forward': 'fa fa-arrow-right icon-arrow-right',
'zoom_to_rect': 'fa fa-square-o icon-check-empty',
'move': 'fa fa-arrows icon-move',
'download': 'fa fa-icon-save icon-save',
None: None
}

Expand All @@ -102,7 +103,8 @@ class NavigationIPy(NavigationToolbar2WebAgg):
toolitems = [(text, tooltip_text,
_FONT_AWESOME_CLASSES[image_file], name_of_method)
for text, tooltip_text, image_file, name_of_method
in NavigationToolbar2.toolitems
in (NavigationToolbar2.toolitems +
(('Download', 'Download plot', 'download', 'download'),))
if image_file in _FONT_AWESOME_CLASSES]


Expand Down
8 changes: 6 additions & 2 deletions lib/matplotlib/backends/web_backend/mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,12 @@ mpl.figure.prototype.key_event = function(event, name) {

mpl.figure.prototype.toolbar_button_onclick = function(name) {
if (name == 'download') {
var format_dropdown = this.format_dropdown;
var format = format_dropdown.options[format_dropdown.selectedIndex].value;
if (this.format_dropdown) {
var format_dropdown = this.format_dropdown;
var format = format_dropdown.options[format_dropdown.selectedIndex].value;
} else {
format = 'png';
}
this.ondownload(this, format);
} else {
this.send_message("toolbar_button", {name: name});
Expand Down
6 changes: 5 additions & 1 deletion lib/matplotlib/backends/web_backend/nbagg_mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ mpl.mpl_figure_comm = function(comm, msg) {
var element = $("#" + id);
var ws_proxy = comm_websocket_adapter(comm)

function ondownload(figure, format) {
window.location.href = 'hello.' + format
}

var fig = new mpl.figure(id, ws_proxy,
function() { },
ondownload,
element.get(0));

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