From: Bojidar Marinov Date: Fri, 11 Jul 2025 19:38:17 +0000 (+0300) Subject: Fix charts shinking in size on certain Zoom values in Chrome (#12097) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5feebdf7b7d9ccbade9bbbf736b8464c97ecbf06;p=thirdparty%2FChart.js.git Fix charts shinking in size on certain Zoom values in Chrome (#12097) --- diff --git a/src/helpers/helpers.dom.ts b/src/helpers/helpers.dom.ts index bf88ac7d2..8224361c6 100644 --- a/src/helpers/helpers.dom.ts +++ b/src/helpers/helpers.dom.ts @@ -211,11 +211,11 @@ export function retinaScale( forceStyle?: boolean ): boolean | void { const pixelRatio = forceRatio || 1; - const deviceHeight = Math.floor(chart.height * pixelRatio); - const deviceWidth = Math.floor(chart.width * pixelRatio); + const deviceHeight = round1(chart.height * pixelRatio); + const deviceWidth = round1(chart.width * pixelRatio); - (chart as PrivateChart).height = Math.floor(chart.height); - (chart as PrivateChart).width = Math.floor(chart.width); + (chart as PrivateChart).height = round1(chart.height); + (chart as PrivateChart).width = round1(chart.width); const canvas = chart.canvas; diff --git a/test/specs/helpers.dom.tests.js b/test/specs/helpers.dom.tests.js index 4bf05da75..519571684 100644 --- a/test/specs/helpers.dom.tests.js +++ b/test/specs/helpers.dom.tests.js @@ -268,8 +268,8 @@ describe('DOM helpers tests', function() { helpers.retinaScale(chart, devicePixelRatio, true); var canvas = chart.canvas; - expect(canvas.width).toBe(Math.floor(chartWidth * devicePixelRatio)); - expect(canvas.height).toBe(Math.floor(chartHeight * devicePixelRatio)); + expect(canvas.width).toBe(Math.round(chartWidth * devicePixelRatio)); + expect(canvas.height).toBe(Math.round(chartHeight * devicePixelRatio)); expect(chart.width).toBe(chartWidth); expect(chart.height).toBe(chartHeight);