Skip to content
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
29 changes: 25 additions & 4 deletions lib/matplotlib/backends/web_backend/js/mpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,37 @@ 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;
}

// 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;'
Expand Down Expand Up @@ -254,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;
});

Expand Down