]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix charts shinking in size on certain Zoom values in Chrome (#12097)
authorBojidar Marinov <bojidar.marinov.bg@gmail.com>
Fri, 11 Jul 2025 19:38:17 +0000 (22:38 +0300)
committerGitHub <noreply@github.com>
Fri, 11 Jul 2025 19:38:17 +0000 (21:38 +0200)
src/helpers/helpers.dom.ts
test/specs/helpers.dom.tests.js

index bf88ac7d2f0c04760f4b16786ff294e2b50ab4f1..8224361c67190d4221068ff1e853dce44cd1c71c 100644 (file)
@@ -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;
 
index 4bf05da75680f36895cfe4d52ab02d6322b6aa47..51957168422fec23085ecff3f70a5072622bd16d 100644 (file)
@@ -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);