mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-09 01:36:51 +01:00
beginAtZero and linear scales with no data should play nice
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user