Skip to content

webagg: Don't resize canvas if WebSocket isn't connected #27251

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 1 commit into from
Nov 2, 2023
Merged
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
11 changes: 10 additions & 1 deletion lib/matplotlib/backends/web_backend/js/mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ mpl.figure.prototype._init_canvas = function () {
}

this.resizeObserverInstance = new this.ResizeObserver(function (entries) {
// There's no need to resize if the WebSocket is not 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.
if (fig.ws.readyState != 1) {
return;
}
var nentries = entries.length;
for (var i = 0; i < nentries; i++) {
var entry = entries[i];
Expand Down Expand Up @@ -239,7 +248,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 (fig.ws.readyState == 1 && width != 0 && height != 0) {
if (width != 0 && height != 0) {
fig.request_resize(width, height);
}
}
Expand Down