Skip to content

nbagg: Use OutputArea event to trigger figure close. #18454

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 2 commits into from
Sep 14, 2020
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
16 changes: 12 additions & 4 deletions lib/matplotlib/backends/web_backend/js/nbagg_mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ mpl.mpl_figure_comm = function (comm, msg) {
console.error('Failed to find cell for figure', id, fig);
return;
}
fig.cell_info[0].output_area.element.one(
'cleared',
{ fig: fig },
fig._remove_fig_handler
);
};

mpl.figure.prototype.handle_close = function (fig, msg) {
var width = fig.canvas.width / fig.ratio;
fig.root.removeEventListener('remove', this._remove_fig_handler);
fig.cell_info[0].output_area.element.off(
'cleared',
fig._remove_fig_handler
);

// Update the output cell to use the data from the current canvas.
fig.push_to_output();
Expand Down Expand Up @@ -171,13 +179,13 @@ mpl.figure.prototype._init_toolbar = function () {
titlebar.insertBefore(buttongrp, titlebar.firstChild);
};

mpl.figure.prototype._remove_fig_handler = function () {
this.close_ws(this, {});
mpl.figure.prototype._remove_fig_handler = function (event) {
var fig = event.data.fig;
fig.close_ws(fig, {});
};

mpl.figure.prototype._root_extra_style = function (el) {
el.style.boxSizing = 'content-box'; // override notebook setting of border-box.
el.addEventListener('remove', this._remove_fig_handler);
};

mpl.figure.prototype._canvas_extra_style = function (el) {
Expand Down
2 changes: 1 addition & 1 deletion requirements/testing/travis_extra.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Extra pip requirements for the travis python 3.7+ builds

ipykernel
nbconvert[execute]
nbconvert[execute]!=6.0.0,!=6.0.1
nbformat!=5.0.0,!=5.0.1
pandas!=0.25.0
pikepdf
Expand Down