From 9e8cf8e96a0f8d169af3c64ac67f0b5effac4e6a Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 8 Feb 2019 20:57:28 -0800 Subject: [PATCH] Ignore invalid log scale min and max --- src/scales/scale.logarithmic.js | 8 +++---- test/specs/scale.logarithmic.tests.js | 31 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 91f90845da3..5fc6287913f 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -174,8 +174,8 @@ module.exports = Scale.extend({ var DEFAULT_MIN = 1; var DEFAULT_MAX = 10; - me.min = valueOrDefault(tickOpts.min, me.min); - me.max = valueOrDefault(tickOpts.max, me.max); + me.min = tickOpts.min >= 0 ? tickOpts.min : me.min; + me.max = tickOpts.max >= 0 ? tickOpts.max : me.max; if (me.min === me.max) { if (me.min !== 0 && me.min !== null) { @@ -211,8 +211,8 @@ module.exports = Scale.extend({ var reverse = !me.isHorizontal(); var generationOptions = { - min: tickOpts.min, - max: tickOpts.max + min: tickOpts.min >= 0 ? tickOpts.min : undefined, + max: tickOpts.max >= 0 ? tickOpts.max : undefined }; var ticks = me.ticks = generateTicks(generationOptions, me); diff --git a/test/specs/scale.logarithmic.tests.js b/test/specs/scale.logarithmic.tests.js index cb44f108d36..a1f2dbcbfde 100644 --- a/test/specs/scale.logarithmic.tests.js +++ b/test/specs/scale.logarithmic.tests.js @@ -477,6 +477,37 @@ describe('Logarithmic Scale tests', function() { expect(yScale.ticks[tickCount - 1]).toBe(10); }); + it('should ignore invalid min and max options', function() { + var chart = window.acquireChart({ + type: 'bar', + data: { + datasets: [{ + data: [1, 1, 1, 2, 1, 0] + }], + labels: [] + }, + options: { + scales: { + yAxes: [{ + id: 'yScale', + type: 'logarithmic', + ticks: { + min: -10, + max: -1010, + callback: function(value) { + return value; + } + } + }] + } + } + }); + + var yScale = chart.scales.yScale; + expect(yScale.min).toBe(0); + expect(yScale.max).toBe(2); + }); + it('should generate tick marks', function() { var chart = window.acquireChart({ type: 'bar',