Skip to content

Commit

Permalink
Fix chart crashing when only min is defined (#9718)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Oct 4, 2021
1 parent 60b094a commit 0d4880e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/core.scale.js
Expand Up @@ -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))
Expand Down
22 changes: 22 additions & 0 deletions test/specs/scale.linear.tests.js
Expand Up @@ -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',
Expand Down

0 comments on commit 0d4880e

Please sign in to comment.