]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
beginAtZero and linear scales with no data should play nice 2490/head
authorEvert Timberg <evert.timberg+github@gmail.com>
Sat, 7 May 2016 20:56:04 +0000 (16:56 -0400)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sat, 7 May 2016 20:56:04 +0000 (16:56 -0400)
src/scales/scale.linear.js
test/scale.linear.tests.js

index 90fcab9fec8158416f730f4e53e133b6e5d04449..e3a7ab8b0b7536b3ab3a5159ecda4529cdfe4d8f 100644 (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() {
index 40e60ce86eb680282f58d64df360405ac03e9f1e..8785ed2f3295305f6f74945936355a24149c4d5d 100644 (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',