]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix: beginAtZero for logarighmic (#7899)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Fri, 16 Oct 2020 14:32:37 +0000 (17:32 +0300)
committerGitHub <noreply@github.com>
Fri, 16 Oct 2020 14:32:37 +0000 (10:32 -0400)
src/scales/scale.logarithmic.js
test/specs/scale.logarithmic.tests.js

index 57bbafa78bb9f3deb3bf0cb67e441a8fe9b63590..526ada83559b3d6d3345402f7541d5e25fd54c94 100644 (file)
@@ -77,6 +77,10 @@ export default class LogarithmicScale extends Scale {
                me.min = isFinite(min) ? Math.max(0, min) : null;
                me.max = isFinite(max) ? Math.max(0, max) : null;
 
+               if (me.options.beginAtZero) {
+                       me._zero = true;
+               }
+
                me.handleTickRangeOptions();
        }
 
@@ -159,7 +163,6 @@ export default class LogarithmicScale extends Scale {
 
                me._startValue = log10(start);
                me._valueRange = log10(me.max) - log10(start);
-               me._zero = me.options.beginAtZero;
        }
 
        getPixelForValue(value) {
index df169c954166fd00ba8a0d0e831e0b281ee84e91..69988138099e81909ef0f65ea22c186fda22121c 100644 (file)
@@ -345,7 +345,7 @@ describe('Logarithmic Scale tests', function() {
                        }
                });
 
-               expect(chart.scales.y.min).toBe(1);
+               expect(chart.scales.y.min).toBe(0.1);
                expect(chart.scales.y.max).toBe(200);
        });
 
@@ -387,7 +387,7 @@ describe('Logarithmic Scale tests', function() {
                        }
                });
 
-               expect(chart.scales.y.min).toBe(1);
+               expect(chart.scales.y.min).toBe(0.1);
                expect(chart.scales.y.max).toBe(200);
        });
 
@@ -517,7 +517,7 @@ describe('Logarithmic Scale tests', function() {
                        type: 'bar',
                        data: {
                                datasets: [{
-                                       data: [10, 5, 1, 25, 78]
+                                       data: [10, 5, 2, 25, 78]
                                }],
                                labels: []
                        },
@@ -659,7 +659,7 @@ describe('Logarithmic Scale tests', function() {
                        type: 'bar',
                        data: {
                                datasets: [{
-                                       data: [10, 5, 1, 25, 78]
+                                       data: [10, 5, 2, 25, 78]
                                }],
                                labels: []
                        },