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 all commits
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
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
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def release_zoom(self, event):

def save_figure(self, *args):
"""Save the current figure"""
warnings.warn('"Save figure" not implemented in Web Backend')
self.canvas.send_event('save')


class FigureManagerWebAgg(backend_bases.FigureManagerBase):
Expand Down
12 changes: 9 additions & 3 deletions lib/matplotlib/backends/web_backend/mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ mpl.figure.prototype.send_draw_message = function() {
}
}


mpl.figure.prototype.handle_save = function(fig, msg) {
var format_dropdown = fig.format_dropdown;
var format = format_dropdown.options[format_dropdown.selectedIndex].value;
fig.ondownload(fig, format);
}


mpl.figure.prototype.handle_resize = function(fig, msg) {
var size = msg['size'];
if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {
Expand Down Expand Up @@ -472,9 +480,7 @@ 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;
this.ondownload(this, format);
this.handle_save(this, null);
} else {
this.send_message("toolbar_button", {name: name});
}
Expand Down
11 changes: 10 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.open(figure.imageObj.src);
}

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 Expand Up @@ -142,6 +146,11 @@ mpl.figure.prototype._canvas_extra_style = function(el){
}


mpl.figure.prototype.handle_save = function(fig, msg) {
fig.ondownload(fig, null);
}


mpl.find_output_cell = function(html_output) {
// Return the cell and output element which can be found *uniquely* in the notebook.
// Note - this is a bit hacky, but it is done because the "notebook_saving.Notebook"
Expand Down