Skip to content

Commit 27f2e69

Browse files
committed
fix: Chart shrinking uncontrollably on browser zoom (chartjs#11089)
1 parent e417c60 commit 27f2e69

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/helpers/helpers.dom.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export function getMaximumSize(
200200
const maintainHeight = bbWidth !== undefined || bbHeight !== undefined;
201201

202202
if (maintainHeight && aspectRatio && containerSize.height && height > containerSize.height) {
203-
height = containerSize.height;
203+
height = Math.round(containerSize.height);
204204
width = round1(Math.floor(height * aspectRatio));
205205
}
206206

test/specs/helpers.dom.tests.js

+17
Original file line numberDiff line numberDiff line change
@@ -545,4 +545,21 @@ describe('DOM helpers tests', function() {
545545

546546
document.body.removeChild(container);
547547
});
548+
549+
it('should respect aspect ratio and container height and return height as integer', () => {
550+
const container = document.createElement('div');
551+
container.style.width = '500px';
552+
container.style.height = '200px';
553+
554+
document.body.appendChild(container);
555+
556+
const target = document.createElement('div');
557+
target.style.width = '500px';
558+
target.style.height = '500px';
559+
container.appendChild(target);
560+
561+
expect(helpers.getMaximumSize(target, 500, 199.975, 1)).toEqual(jasmine.objectContaining({width: 200, height: 200}));
562+
563+
document.body.removeChild(container);
564+
});
548565
});

0 commit comments

Comments
 (0)