From 840035ce918889273937ff43c1083a8637fb8bc0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 10 Sep 2020 23:26:00 -0400 Subject: [PATCH 1/2] nbagg: Use OutputArea event to trigger figure close. When converting from jQuery to vanilla JavaScript, the trigger for the figure closure was set to a non-existent event name, as the 'remove' event is jQuery-specific. As there is no DOM node removal event (unless using MutationObserver), connect this handler to the notebook's `Cell` `OutputArea`'s 'cleared' event. This is triggered both by re-running a cell, and by using the Clear Output menu option. Fixes #18447. --- .../backends/web_backend/js/nbagg_mpl.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js b/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js index 9881819de855..0f538979d19d 100644 --- a/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js +++ b/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js @@ -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(); @@ -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) { From 75da6c8c403984bf99d180ac8d6e2e8f25da9261 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 11 Sep 2020 19:52:35 -0400 Subject: [PATCH 2/2] CI: Pin nbconvert to working version. --- requirements/testing/travis_extra.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/testing/travis_extra.txt b/requirements/testing/travis_extra.txt index 19b774b382f7..0b18fc58394a 100644 --- a/requirements/testing/travis_extra.txt +++ b/requirements/testing/travis_extra.txt @@ -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