From 9ad99c464cf71796ff9e200be5d058f477db6943 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 31 Jul 2020 20:42:27 -0400 Subject: [PATCH 1/3] Fix nbAgg sizing on Chrome 84. The ResizeObserver spec changed, though Firefox still does the old way. Previous Chrome implemented an even older version, and 84 implements the latest version, but not this in-between one we're using. --- lib/matplotlib/backends/web_backend/js/mpl.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/web_backend/js/mpl.js b/lib/matplotlib/backends/web_backend/js/mpl.js index f7ef50dabff0..4a45d60af366 100644 --- a/lib/matplotlib/backends/web_backend/js/mpl.js +++ b/lib/matplotlib/backends/web_backend/js/mpl.js @@ -172,9 +172,17 @@ mpl.figure.prototype._init_canvas = function () { var entry = entries[i]; var width, height; if (entry.contentBoxSize) { - width = entry.contentBoxSize.inlineSize; - height = entry.contentBoxSize.blockSize; + if (entry.contentBoxSize instanceof Array) { + // Chrome 84 implements new version of spec. + width = entry.contentBoxSize[0].inlineSize; + height = entry.contentBoxSize[0].blockSize; + } else { + // Firefox implements old version of spec. + width = entry.contentBoxSize.inlineSize; + height = entry.contentBoxSize.blockSize; + } } else { + // Chrome <84 implements even older version of spec. width = entry.contentRect.width; height = entry.contentRect.height; } From d50fdedfe173d7b1e72bf39db2e31d0ded1458ad Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 31 Jul 2020 21:04:01 -0400 Subject: [PATCH 2/3] nbagg: Use device sized content size to resize canvas. This is only implemented on Chrome, but prevents some blurriness. --- lib/matplotlib/backends/web_backend/js/mpl.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/web_backend/js/mpl.js b/lib/matplotlib/backends/web_backend/js/mpl.js index 4a45d60af366..f52c22d31beb 100644 --- a/lib/matplotlib/backends/web_backend/js/mpl.js +++ b/lib/matplotlib/backends/web_backend/js/mpl.js @@ -189,8 +189,20 @@ mpl.figure.prototype._init_canvas = function () { // Keep the size of the canvas and rubber band canvas in sync with // the canvas container. - canvas.setAttribute('width', width * mpl.ratio); - canvas.setAttribute('height', height * mpl.ratio); + if (entry.devicePixelContentBoxSize) { + // Chrome 84 implements new version of spec. + canvas.setAttribute( + 'width', + entry.devicePixelContentBoxSize[0].inlineSize + ); + canvas.setAttribute( + 'height', + entry.devicePixelContentBoxSize[0].blockSize + ); + } else { + canvas.setAttribute('width', width * mpl.ratio); + canvas.setAttribute('height', height * mpl.ratio); + } canvas.setAttribute( 'style', 'width: ' + width + 'px; height: ' + height + 'px;' From d9652610f609065014ebe2680c6c6f796a7ad15a Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 31 Jul 2020 21:07:10 -0400 Subject: [PATCH 3/3] nbAgg: Fix disabling the context menu in the canvas. --- lib/matplotlib/backends/web_backend/js/mpl.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/backends/web_backend/js/mpl.js b/lib/matplotlib/backends/web_backend/js/mpl.js index f52c22d31beb..9eeb14f399e0 100644 --- a/lib/matplotlib/backends/web_backend/js/mpl.js +++ b/lib/matplotlib/backends/web_backend/js/mpl.js @@ -274,6 +274,7 @@ mpl.figure.prototype._init_canvas = function () { // Disable right mouse context menu. this.rubberband_canvas.addEventListener('contextmenu', function (_e) { + event.preventDefault(); return false; });