fix: aspect ratio calc (#10693)

This commit is contained in:
Dan Onoshko
2022-09-29 02:31:19 +07:00
committed by GitHub
parent dec3d2338f
commit 52cf8e8a94
3 changed files with 25 additions and 4 deletions

View File

@@ -175,7 +175,9 @@ export function getMaximumSize(canvas, bbWidth, bbHeight, aspectRatio) {
height = round1(width / 2);
}
if (aspectRatio && height > containerSize.height) {
const maintainHeight = bbWidth !== undefined || bbHeight !== undefined;
if (maintainHeight && aspectRatio && containerSize.height && height > containerSize.height) {
height = containerSize.height;
width = round1(Math.floor(height * aspectRatio));
}

View File

@@ -487,4 +487,21 @@ describe('DOM helpers tests', function() {
document.body.removeChild(container);
});
it('should respect aspect ratio and skip container height', () => {
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, undefined, undefined, 1)).toEqual(jasmine.objectContaining({width: 500, height: 500}));
document.body.removeChild(container);
});
});

View File

@@ -286,9 +286,11 @@ describe('Platform.dom', function() {
}
});
expect(chart).toBeChartOfSize({
dw: 214, dh: 350,
rw: 214, rh: 350,
waitForResize(chart, () => {
expect(chart).toBeChartOfSize({
dw: 214, dh: 350,
rw: 214, rh: 350,
});
});
});
});