mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Fix chart crashing when only min is defined (#9718)
This commit is contained in:
parent
60b094a9af
commit
0d4880e35c
@ -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))
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user