From 27f2e69342e18a8295c2b05151bc227ba430fece Mon Sep 17 00:00:00 2001 From: Guy Baron Date: Fri, 10 Feb 2023 21:34:09 -0500 Subject: [PATCH] fix: Chart shrinking uncontrollably on browser zoom (#11089) --- src/helpers/helpers.dom.ts | 2 +- test/specs/helpers.dom.tests.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/helpers/helpers.dom.ts b/src/helpers/helpers.dom.ts index ebd8d978d91..fe057f422d2 100644 --- a/src/helpers/helpers.dom.ts +++ b/src/helpers/helpers.dom.ts @@ -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)); } diff --git a/test/specs/helpers.dom.tests.js b/test/specs/helpers.dom.tests.js index 4bf05da7568..24495e3793c 100644 --- a/test/specs/helpers.dom.tests.js +++ b/test/specs/helpers.dom.tests.js @@ -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); + }); });