Merge pull request #2490 from chartjs/fix/2476

beginAtZero and linear scales with no data should play nice
This commit is contained in:
Evert Timberg 2016-05-07 17:04:37 -04:00
commit 51d8a5b55e
2 changed files with 29 additions and 1 deletions

View File

@ -147,8 +147,11 @@ module.exports = function(Chart) {
}
if (this.min === this.max) {
this.min--;
this.max++;
if (!this.options.ticks.beginAtZero) {
this.min--;
}
}
},
buildTicks: function() {

View File

@ -409,6 +409,31 @@ describe('Linear Scale', function() {
expect(chartInstance.scales.yScale0.max).toBe(1);
});
it('Should ensure that the scale has a max and min that are not equal when beginAtZero is set', function() {
chartInstance = window.acquireChart({
type: 'bar',
data: {
datasets: [],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
yAxes: [{
id: 'yScale0',
type: 'linear',
ticks: {
beginAtZero: true
}
}]
}
}
});
expect(chartInstance.scales.yScale0).not.toEqual(undefined); // must construct
expect(chartInstance.scales.yScale0.min).toBe(0);
expect(chartInstance.scales.yScale0.max).toBe(1);
});
it('Should use the suggestedMin and suggestedMax options', function() {
chartInstance = window.acquireChart({
type: 'bar',