Skip to content
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

Fix updating retinaScale #6971

Merged
merged 2 commits into from
Jan 18, 2020
Merged
Changes from 1 commit
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
24 changes: 10 additions & 14 deletions src/helpers/helpers.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,20 @@ export function getMaximumHeight(domNode) {
}

export function retinaScale(chart, forceRatio) {
var pixelRatio = chart.currentDevicePixelRatio = forceRatio || (typeof window !== 'undefined' && window.devicePixelRatio) || 1;
if (pixelRatio === 1) {
return;
}

var canvasElement = chart.canvas;
var height = chart.height;
var width = chart.width;
const pixelRatio = chart.currentDevicePixelRatio = forceRatio || (typeof window !== 'undefined' && window.devicePixelRatio) || 1;
const canvas = chart.canvas;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe destructure here:
const {canvas, width, height} = chart;

const height = chart.height;
const width = chart.width;

canvasElement.height = height * pixelRatio;
canvasElement.width = width * pixelRatio;
chart.ctx.scale(pixelRatio, pixelRatio);
canvas.height = height * pixelRatio;
canvas.width = width * pixelRatio;
chart.ctx.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);

// If no style has been set on the canvas, the render size is used as display size,
// making the chart visually bigger, so let's enforce it to the "correct" values.
// See https://github.com/chartjs/Chart.js/issues/3575
if (!canvasElement.style.height && !canvasElement.style.width) {
canvasElement.style.height = height + 'px';
canvasElement.style.width = width + 'px';
if (!canvas.style.height && !canvas.style.width) {
canvas.style.height = height + 'px';
canvas.style.width = width + 'px';
}
}