From 30a900f20ca146d40a633a0b4f77077240c92a95 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 16 Dec 2020 17:48:39 -0500 Subject: [PATCH 1/2] webagg: Don't send figure pixel ratio too early. This is already done in the WebSocket's `onopen` function, and sending it during the object's initialization crashes due to the WebSocket not being ready. Fixes #19129. --- lib/matplotlib/backends/web_backend/js/mpl.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/matplotlib/backends/web_backend/js/mpl.js b/lib/matplotlib/backends/web_backend/js/mpl.js index 355d385568ac..ae001f06951c 100644 --- a/lib/matplotlib/backends/web_backend/js/mpl.js +++ b/lib/matplotlib/backends/web_backend/js/mpl.js @@ -157,9 +157,6 @@ mpl.figure.prototype._init_canvas = function () { 1; this.ratio = (window.devicePixelRatio || 1) / backingStore; - if (this.ratio !== 1) { - fig.send_message('set_dpi_ratio', { dpi_ratio: this.ratio }); - } var rubberband_canvas = (this.rubberband_canvas = document.createElement( 'canvas' From 725e908542a20100ef3e0a49c884bb26f304132b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 16 Dec 2020 17:50:09 -0500 Subject: [PATCH 2/2] webagg: Fix another too-early use of the WebSocket. Because this is behind the asynchronous `ResizeObserver`, it does _not_ cause a failure to initialize the JavaScript figure, but is similar in error as the previous commit. --- lib/matplotlib/backends/web_backend/js/mpl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/web_backend/js/mpl.js b/lib/matplotlib/backends/web_backend/js/mpl.js index ae001f06951c..05ed0e1b7187 100644 --- a/lib/matplotlib/backends/web_backend/js/mpl.js +++ b/lib/matplotlib/backends/web_backend/js/mpl.js @@ -224,7 +224,7 @@ mpl.figure.prototype._init_canvas = function () { // And update the size in Python. We ignore the initial 0/0 size // that occurs as the element is placed into the DOM, which should // otherwise not happen due to the minimum size styling. - if (width != 0 && height != 0) { + if (fig.ws.readyState == 1 && width != 0 && height != 0) { fig.request_resize(width, height); } }