From ddd1c43f2c149483b2943b99c1b6226f0fdbd4f8 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Sat, 18 Jan 2020 02:08:38 +0200 Subject: [PATCH] Fix updating retinaScale (#6971) * Fix updating retinaScale * Destructure --- src/helpers/helpers.dom.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/helpers/helpers.dom.js b/src/helpers/helpers.dom.js index 939e4bbe8..4db17b6dc 100644 --- a/src/helpers/helpers.dom.js +++ b/src/helpers/helpers.dom.js @@ -152,24 +152,18 @@ 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, width, height} = chart; - 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'; } } -- 2.47.2