Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -138,7 +138,11 @@ function generateTicks(generationOptions, dataRange) {
ticks.push({value: max});
}
} else if (!maxDefined || niceMax === max) {
ticks.push({value: niceMax});
// Avoid duplicating the last emitted tick when the rounded niceMax
// coincides with it (e.g. bounds: 'data' with a fractional data max).
if (!ticks.length || ticks[ticks.length - 1].value !== niceMax) {
ticks.push({value: niceMax});
}
}

return ticks;
Expand Down
25 changes: 25 additions & 0 deletions test/specs/scale.linear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,31 @@ describe('Linear Scale', function() {
expect(chart.scales.y.max).toEqual(99);
});

it('Should not produce a duplicate final tick when bounding to a fractional data max', function() {
var chart = window.acquireChart({
type: 'line',
data: {
labels: ['a', 'b'],
datasets: [{
data: [0, 5.4]
}]
},
options: {
scales: {
y: {
type: 'linear',
bounds: 'data',
ticks: {
autoSkip: false
}
}
}
}
});

expect(getLabels(chart.scales.y)).toEqual(['0', '1', '2', '3', '4', '5']);
});

it('Should build labels using the user supplied callback', function() {
var chart = window.acquireChart({
type: 'bar',
Expand Down