Skip to content

Commit

Permalink
fix: Chart shrinking uncontrollably on browser zoom (chartjs#11089)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaron committed Feb 11, 2023
1 parent e417c60 commit 27f2e69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/helpers/helpers.dom.ts
Expand Up @@ -200,7 +200,7 @@ export function getMaximumSize(
const maintainHeight = bbWidth !== undefined || bbHeight !== undefined;

if (maintainHeight && aspectRatio && containerSize.height && height > containerSize.height) {
height = containerSize.height;
height = Math.round(containerSize.height);
width = round1(Math.floor(height * aspectRatio));
}

Expand Down
17 changes: 17 additions & 0 deletions test/specs/helpers.dom.tests.js
Expand Up @@ -545,4 +545,21 @@ describe('DOM helpers tests', function() {

document.body.removeChild(container);
});

it('should respect aspect ratio and container height and return height as integer', () => {
const container = document.createElement('div');
container.style.width = '500px';
container.style.height = '200px';

document.body.appendChild(container);

const target = document.createElement('div');
target.style.width = '500px';
target.style.height = '500px';
container.appendChild(target);

expect(helpers.getMaximumSize(target, 500, 199.975, 1)).toEqual(jasmine.objectContaining({width: 200, height: 200}));

document.body.removeChild(container);
});
});

0 comments on commit 27f2e69

Please sign in to comment.