From bc505b1a9dfcf96176f9f8976e79efd29044d6e0 Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sat, 7 May 2016 16:56:04 -0400 Subject: [PATCH] beginAtZero and linear scales with no data should play nice --- src/scales/scale.linear.js | 5 ++++- test/scale.linear.tests.js | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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', -- 2.47.2