Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9dda79c

Browse files
committed
Merge pull request #18454 from QuLogic/fix-nbagg-rerun
FIX: Use OutputArea event to trigger figure close in nbagg
1 parent eea9f63 commit 9dda79c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,19 @@ mpl.mpl_figure_comm = function (comm, msg) {
4848
console.error('Failed to find cell for figure', id, fig);
4949
return;
5050
}
51+
fig.cell_info[0].output_area.element.one(
52+
'cleared',
53+
{ fig: fig },
54+
fig._remove_fig_handler
55+
);
5156
};
5257

5358
mpl.figure.prototype.handle_close = function (fig, msg) {
5459
var width = fig.canvas.width / fig.ratio;
55-
fig.root.removeEventListener('remove', this._remove_fig_handler);
60+
fig.cell_info[0].output_area.element.off(
61+
'cleared',
62+
fig._remove_fig_handler
63+
);
5664

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

174-
mpl.figure.prototype._remove_fig_handler = function () {
175-
this.close_ws(this, {});
182+
mpl.figure.prototype._remove_fig_handler = function (event) {
183+
var fig = event.data.fig;
184+
fig.close_ws(fig, {});
176185
};
177186

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

183191
mpl.figure.prototype._canvas_extra_style = function (el) {

requirements/testing/travis_extra.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Extra pip requirements for the travis python 3.7+ builds
22

33
ipykernel
4-
nbconvert[execute]
4+
nbconvert[execute]!=6.0.0,!=6.0.1
55
nbformat!=5.0.0,!=5.0.1
66
pandas!=0.25.0
77
pikepdf

0 commit comments

Comments
 (0)