Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 93fa19b

Browse filesBrowse files
committed
webagg: Don't resize canvas if WebSocket isn't connected
- If it is still connecting, then we will get an initial resize from Python once it connects. - If it has disconnected, then resizing will clear the canvas and never get anything back to refill it, so better to not resize and keep something visible.
1 parent cc46ee7 commit 93fa19b
Copy full SHA for 93fa19b

File tree

Expand file treeCollapse file tree

1 file changed

+10
-1
lines changed
Filter options
  • lib/matplotlib/backends/web_backend/js
Expand file treeCollapse file tree

1 file changed

+10
-1
lines changed

‎lib/matplotlib/backends/web_backend/js/mpl.js

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/web_backend/js/mpl.js
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ mpl.figure.prototype._init_canvas = function () {
192192
}
193193

194194
this.resizeObserverInstance = new this.ResizeObserver(function (entries) {
195+
// There's no need to resize if the WebSocket is not connected:
196+
// - If it is still connecting, then we will get an initial resize from
197+
// Python once it connects.
198+
// - If it has disconnected, then resizing will clear the canvas and
199+
// never get anything back to refill it, so better to not resize and
200+
// keep something visible.
201+
if (fig.ws.readyState != 1) {
202+
return;
203+
}
195204
var nentries = entries.length;
196205
for (var i = 0; i < nentries; i++) {
197206
var entry = entries[i];
@@ -239,7 +248,7 @@ mpl.figure.prototype._init_canvas = function () {
239248
// And update the size in Python. We ignore the initial 0/0 size
240249
// that occurs as the element is placed into the DOM, which should
241250
// otherwise not happen due to the minimum size styling.
242-
if (fig.ws.readyState == 1 && width != 0 && height != 0) {
251+
if (width != 0 && height != 0) {
243252
fig.request_resize(width, height);
244253
}
245254
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.