mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-09 17:56:51 +01:00
fix: aspect ratio calc (#10693)
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user