Fix chart crashing when only min is defined (#9718)

This commit is contained in:
Jukka Kurkela 2021-10-04 21:00:27 +03:00 committed by GitHub
parent 60b094a9af
commit 0d4880e35c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -323,6 +323,10 @@ export default class Scale extends Element {
}
}
// Make sure min <= max when only min or max is defined by user and the data is outside that range
min = maxDefined && min > max ? max : min;
max = minDefined && min > max ? min : max;
return {
min: finiteOrDefault(min, finiteOrDefault(max, min)),
max: finiteOrDefault(max, finiteOrDefault(min, max))

View File

@ -51,6 +51,28 @@ describe('Linear Scale', function() {
expect(chart.scales.y.max).toBe(150);
});
it('Should handle when only a min value is provided', () => {
var chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
yAxisID: 'y',
data: [200]
}],
},
options: {
scales: {
y: {
type: 'linear',
min: 250
}
}
}
});
expect(chart.scales.y.min).toBe(250);
});
it('Should handle when only a max value is provided', () => {
var chart = window.acquireChart({
type: 'line',