From 5b8ec5306855b27740eaf4cb4a26d68762a21fd4 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Fri, 17 Jan 2020 10:05:51 +0200 Subject: [PATCH 1/2] Fix updating retinaScale --- src/helpers/helpers.dom.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/helpers/helpers.dom.js b/src/helpers/helpers.dom.js index 939e4bbe8c7..4fda483e93e 100644 --- a/src/helpers/helpers.dom.js +++ b/src/helpers/helpers.dom.js @@ -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; + 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'; } } From 3a26df0eb22e0d0b06097dd2cabc8f8f9e4d9851 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Fri, 17 Jan 2020 19:01:08 +0200 Subject: [PATCH 2/2] Destructure --- src/helpers/helpers.dom.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/helpers/helpers.dom.js b/src/helpers/helpers.dom.js index 4fda483e93e..4db17b6dc5b 100644 --- a/src/helpers/helpers.dom.js +++ b/src/helpers/helpers.dom.js @@ -153,9 +153,7 @@ export function getMaximumHeight(domNode) { export function retinaScale(chart, forceRatio) { const pixelRatio = chart.currentDevicePixelRatio = forceRatio || (typeof window !== 'undefined' && window.devicePixelRatio) || 1; - const canvas = chart.canvas; - const height = chart.height; - const width = chart.width; + const {canvas, width, height} = chart; canvas.height = height * pixelRatio; canvas.width = width * pixelRatio;