Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chart crashing when max is defined but ticks are empty #9641

Merged
merged 2 commits into from Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scales/scale.linearbase.js
Expand Up @@ -128,7 +128,7 @@ function generateTicks(generationOptions, dataRange) {

if (maxDefined && includeBounds && niceMax !== max) {
// If the previous tick is too close to max, replace it with max, else add max
if (almostEquals(ticks[ticks.length - 1].value, max, relativeLabelSize(max, minSpacing, generationOptions))) {
if (ticks.length && almostEquals(ticks[ticks.length - 1].value, max, relativeLabelSize(max, minSpacing, generationOptions))) {
ticks[ticks.length - 1].value = max;
} else {
ticks.push({value: max});
Expand Down
23 changes: 23 additions & 0 deletions test/specs/scale.linear.tests.js
Expand Up @@ -51,6 +51,29 @@ describe('Linear Scale', function() {
expect(chart.scales.y.max).toBe(150);
});

it('Should handle when only a max value is provided', () => {
var chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
yAxisID: 'y',
data: [200]
}],
},
options: {
scales: {
y: {
type: 'linear',
max: 150
}
}
}
});

expect(chart.scales.y).not.toEqual(undefined); // must construct
expect(chart.scales.y.max).toBe(150);
});

it('Should correctly determine the max & min of string data values', function() {
var chart = window.acquireChart({
type: 'bar',
Expand Down