mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Fix: Avoid negative layout dimensions (#9027)
This commit is contained in:
parent
f5c51afd51
commit
1a1e677699
@ -309,8 +309,8 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const padding = toPadding(chart.options.layout.padding);
|
const padding = toPadding(chart.options.layout.padding);
|
||||||
const availableWidth = width - padding.width;
|
const availableWidth = Math.max(width - padding.width, 0);
|
||||||
const availableHeight = height - padding.height;
|
const availableHeight = Math.max(height - padding.height, 0);
|
||||||
const boxes = buildLayoutBoxes(chart.boxes);
|
const boxes = buildLayoutBoxes(chart.boxes);
|
||||||
const verticalBoxes = boxes.vertical;
|
const verticalBoxes = boxes.vertical;
|
||||||
const horizontalBoxes = boxes.horizontal;
|
const horizontalBoxes = boxes.horizontal;
|
||||||
|
@ -1220,4 +1220,31 @@ describe('Linear Scale', function() {
|
|||||||
expect(scale.getValueForPixel(end)).toBeCloseTo(min, 4);
|
expect(scale.getValueForPixel(end)).toBeCloseTo(min, 4);
|
||||||
expect(scale.getValueForPixel(start)).toBeCloseTo(max, 4);
|
expect(scale.getValueForPixel(start)).toBeCloseTo(max, 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not throw errors when chart size is negative', function() {
|
||||||
|
function createChart() {
|
||||||
|
return window.acquireChart({
|
||||||
|
type: 'bar',
|
||||||
|
data: {
|
||||||
|
labels: [0, 1, 2, 3, 4, 5, 6, 7, '7+'],
|
||||||
|
datasets: [{
|
||||||
|
data: [29.05, 4, 15.69, 11.69, 2.84, 4, 0, 3.84, 4],
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
plugins: false,
|
||||||
|
layout: {
|
||||||
|
padding: {top: 30, left: 1, right: 1, bottom: 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
canvas: {
|
||||||
|
height: 0,
|
||||||
|
width: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(createChart).not.toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user