Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/scales/scale.linearbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ module.exports = function(Chart) {
if (tickOpts.min !== undefined) {
me.min = tickOpts.min;
} else if (tickOpts.suggestedMin !== undefined) {
me.min = Math.min(me.min, tickOpts.suggestedMin);
if (me.min === null) {
me.min = tickOpts.suggestedMin;
} else {
me.min = Math.min(me.min, tickOpts.suggestedMin);
}
}

if (tickOpts.max !== undefined) {
me.max = tickOpts.max;
} else if (tickOpts.suggestedMax !== undefined) {
me.max = Math.max(me.max, tickOpts.suggestedMax);
if (me.max === null) {
me.max = tickOpts.suggestedMax;
} else {
me.max = Math.max(me.max, tickOpts.suggestedMax);
}
}

if (me.min === me.max) {
Expand Down
29 changes: 29 additions & 0 deletions test/specs/scale.linear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,35 @@ describe('Linear Scale', function() {
expect(chart.scales.yScale0.max).toBe(150);
});

it('Should correctly determine the max & min when no values provided and suggested minimum and maximum are set', function() {
var chart = window.acquireChart({
type: 'bar',
data: {
datasets: [{
yAxisID: 'yScale0',
data: []
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
yAxes: [{
id: 'yScale0',
type: 'linear',
ticks: {
suggestedMin: -10,
suggestedMax: 15
}
}]
}
}
});

expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
expect(chart.scales.yScale0.min).toBe(-10);
expect(chart.scales.yScale0.max).toBe(15);
});

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