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: don't generate ticks > max if max is specified #11116

Merged
merged 3 commits into from
Feb 10, 2023
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
6 changes: 5 additions & 1 deletion src/scales/scale.linearbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ function generateTicks(generationOptions, dataRange) {
}

for (; j < numSpaces; ++j) {
ticks.push({value: Math.round((niceMin + j * spacing) * factor) / factor});
const tickValue = Math.round((niceMin + j * spacing) * factor) / factor;
if (maxDefined && tickValue > max) {
break;
}
ticks.push({value: tickValue});
}

if (maxDefined && includeBounds && niceMax !== max) {
Expand Down
22 changes: 22 additions & 0 deletions test/specs/scale.linear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,28 @@ describe('Linear Scale', function() {
expect(getLabels(chart.scales.y)).toEqual(['1', '3', '5', '7', '9', '11']);
});

it('Should not generate any ticks > max if max is specified', function() {
var chart = window.acquireChart({
type: 'line',
options: {
scales: {
x: {
type: 'linear',
min: 2.404e-8,
max: 2.4143e-8,
ticks: {
includeBounds: false,
},
},
},
},
});

expect(chart.scales.x.min).toBe(2.404e-8);
expect(chart.scales.x.max).toBe(2.4143e-8);
expect(chart.scales.x.ticks[chart.scales.x.ticks.length - 1].value).toBeLessThanOrEqual(2.4143e-8);
});

it('Should not generate insane amounts of ticks with small stepSize and large range', function() {
var chart = window.acquireChart({
type: 'bar',
Expand Down