From: Evert Timberg Date: Sat, 7 May 2016 20:56:04 +0000 (-0400) Subject: beginAtZero and linear scales with no data should play nice X-Git-Tag: v2.1.2~2^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=refs%2Fpull%2F2490%2Fhead;p=thirdparty%2FChart.js.git beginAtZero and linear scales with no data should play nice --- diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 90fcab9fe..e3a7ab8b0 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -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() { diff --git a/test/scale.linear.tests.js b/test/scale.linear.tests.js index 40e60ce86..8785ed2f3 100644 --- a/test/scale.linear.tests.js +++ b/test/scale.linear.tests.js @@ -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',