mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Merge pull request #2490 from chartjs/fix/2476
beginAtZero and linear scales with no data should play nice
This commit is contained in:
commit
51d8a5b55e
@ -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() {
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user