From 7a6183ccc5a9b9aa4eb5adfab6a76066e1e619d3 Mon Sep 17 00:00:00 2001 From: Colin <34158322+teroman@users.noreply.github.com> Date: Tue, 30 Jan 2018 16:03:36 +0000 Subject: [PATCH 1/7] Incorrect conversion of number to boolean Check for min/max/stepSize coerces numbers to truthy values. A min setting of 0 is therefore interpreted as not being set. Checking against undefined means settings are correctly detected. --- src/scales/scale.linearbase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scales/scale.linearbase.js b/src/scales/scale.linearbase.js index 3e4b5c083f3..3b28cd0d20f 100644 --- a/src/scales/scale.linearbase.js +++ b/src/scales/scale.linearbase.js @@ -25,7 +25,7 @@ function generateTicks(generationOptions, dataRange) { var niceMax = Math.ceil(dataRange.max / spacing) * spacing; // If min, max and stepSize is set and they make an evenly spaced scale use it. - if (generationOptions.min && generationOptions.max && generationOptions.stepSize) { + if (generationOptions.min !== undefined && generationOptions.max !== undefined && generationOptions.stepSize !== undefined) { // If very close to our whole number, use it. if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) { niceMin = generationOptions.min; From 262967782b013161eb13d32e0cd93cb7a653eb14 Mon Sep 17 00:00:00 2001 From: Colin <34158322+teroman@users.noreply.github.com> Date: Fri, 25 May 2018 14:43:56 +0100 Subject: [PATCH 2/7] Update scale.linearbase.js --- src/scales/scale.linearbase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scales/scale.linearbase.js b/src/scales/scale.linearbase.js index 3b28cd0d20f..9de9ba6d248 100644 --- a/src/scales/scale.linearbase.js +++ b/src/scales/scale.linearbase.js @@ -25,7 +25,7 @@ function generateTicks(generationOptions, dataRange) { var niceMax = Math.ceil(dataRange.max / spacing) * spacing; // If min, max and stepSize is set and they make an evenly spaced scale use it. - if (generationOptions.min !== undefined && generationOptions.max !== undefined && generationOptions.stepSize !== undefined) { + if (!helpers.isNullOrUndef(generationOptions.min) && !helpers.isNullOrUndef(generationOptions.max) && !helpers.isNullOrUndef(generationOptions.stepSize)) { // If very close to our whole number, use it. if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) { niceMin = generationOptions.min; From fd7f051ce86f9b64d57a4e9cbedc7da00579f279 Mon Sep 17 00:00:00 2001 From: Colin <34158322+teroman@users.noreply.github.com> Date: Fri, 25 May 2018 15:17:44 +0100 Subject: [PATCH 3/7] Update scale.linear.tests.js --- test/specs/scale.linear.tests.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/specs/scale.linear.tests.js b/test/specs/scale.linear.tests.js index 60dd07698c0..853672e5a14 100644 --- a/test/specs/scale.linear.tests.js +++ b/test/specs/scale.linear.tests.js @@ -905,4 +905,33 @@ describe('Linear Scale', function() { expect(chart.scales['x-axis-0'].min).toEqual(20); expect(chart.scales['x-axis-0'].max).toEqual(21); }); + + it('max setting should be used if it set to zero', function() { + var barData = { + labels: ['S1', 'S2', 'S3'], + datasets: [{ + label: 'dataset 1', + backgroundColor: '#382765', + data: [-2500, -2000, -1500], + hidden: true, + }] + }; + + var chart = window.acquireChart({ + type: 'horizontalBar', + data: barData, + options: { + scales: { + xAxes: [{ + ticks: { + min: -3000, + max: 0 + } + }] + } + } + }); + + expect(chart.scales['x-axis-0'].max).toEqual(0); + }); }); From a5740e0ffd2839091ed2a0531babfce3ac1aa5e5 Mon Sep 17 00:00:00 2001 From: Colin <34158322+teroman@users.noreply.github.com> Date: Fri, 25 May 2018 15:26:14 +0100 Subject: [PATCH 4/7] Update scale.linear.tests.js --- test/specs/scale.linear.tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/specs/scale.linear.tests.js b/test/specs/scale.linear.tests.js index 853672e5a14..85d67f5243b 100644 --- a/test/specs/scale.linear.tests.js +++ b/test/specs/scale.linear.tests.js @@ -905,7 +905,7 @@ describe('Linear Scale', function() { expect(chart.scales['x-axis-0'].min).toEqual(20); expect(chart.scales['x-axis-0'].max).toEqual(21); }); - + it('max setting should be used if it set to zero', function() { var barData = { labels: ['S1', 'S2', 'S3'], From 998840c5261827b890ac9c58feac9f122885c996 Mon Sep 17 00:00:00 2001 From: Colin <34158322+teroman@users.noreply.github.com> Date: Tue, 19 Jun 2018 17:30:58 +0100 Subject: [PATCH 5/7] Update scale.linear.tests.js --- test/specs/scale.linear.tests.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/specs/scale.linear.tests.js b/test/specs/scale.linear.tests.js index 85d67f5243b..4610bea24e4 100644 --- a/test/specs/scale.linear.tests.js +++ b/test/specs/scale.linear.tests.js @@ -906,7 +906,7 @@ describe('Linear Scale', function() { expect(chart.scales['x-axis-0'].max).toEqual(21); }); - it('max setting should be used if it set to zero', function() { + it('min/max/stepSize settings should be used if set to zero', function() { var barData = { labels: ['S1', 'S2', 'S3'], datasets: [{ @@ -924,14 +924,17 @@ describe('Linear Scale', function() { scales: { xAxes: [{ ticks: { - min: -3000, - max: 0 + min: 0, + max: 0, + stepSize: 0 } }] } } }); + expect(chart.scales['x-axis-0'].min).toEqual(0); expect(chart.scales['x-axis-0'].max).toEqual(0); + expect(chart.scales['x-axis-0'].stepSize).toEqual(0); }); }); From b8809211aa3edae572d903e27f05427166224f83 Mon Sep 17 00:00:00 2001 From: Colin <34158322+teroman@users.noreply.github.com> Date: Tue, 19 Jun 2018 17:40:28 +0100 Subject: [PATCH 6/7] Update scale.linear.tests.js --- test/specs/scale.linear.tests.js | 36 ++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/test/specs/scale.linear.tests.js b/test/specs/scale.linear.tests.js index 4610bea24e4..9fbb475ae30 100644 --- a/test/specs/scale.linear.tests.js +++ b/test/specs/scale.linear.tests.js @@ -906,14 +906,13 @@ describe('Linear Scale', function() { expect(chart.scales['x-axis-0'].max).toEqual(21); }); - it('min/max/stepSize settings should be used if set to zero', function() { + it('min settings should be used if set to zero', function() { var barData = { labels: ['S1', 'S2', 'S3'], datasets: [{ label: 'dataset 1', backgroundColor: '#382765', - data: [-2500, -2000, -1500], - hidden: true, + data: [2500, 2000, 1500] }] }; @@ -925,8 +924,7 @@ describe('Linear Scale', function() { xAxes: [{ ticks: { min: 0, - max: 0, - stepSize: 0 + max: 3000 } }] } @@ -934,7 +932,33 @@ describe('Linear Scale', function() { }); expect(chart.scales['x-axis-0'].min).toEqual(0); + }); + + it('max settings should be used if set to zero', function() { + var barData = { + labels: ['S1', 'S2', 'S3'], + datasets: [{ + label: 'dataset 1', + backgroundColor: '#382765', + data: [-2500, -2000, -1500] + }] + }; + + var chart = window.acquireChart({ + type: 'horizontalBar', + data: barData, + options: { + scales: { + xAxes: [{ + ticks: { + min: -3000, + max: 0 + } + }] + } + } + }); + expect(chart.scales['x-axis-0'].max).toEqual(0); - expect(chart.scales['x-axis-0'].stepSize).toEqual(0); }); }); From a802fb1d006b3e41137e424437f13c0234b85f97 Mon Sep 17 00:00:00 2001 From: Colin <34158322+teroman@users.noreply.github.com> Date: Thu, 12 Jul 2018 15:43:50 +0100 Subject: [PATCH 7/7] Update scale.linearbase.js Good spot, I must have been on autopilot! --- src/scales/scale.linearbase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scales/scale.linearbase.js b/src/scales/scale.linearbase.js index 9de9ba6d248..b40aab511d4 100644 --- a/src/scales/scale.linearbase.js +++ b/src/scales/scale.linearbase.js @@ -25,7 +25,7 @@ function generateTicks(generationOptions, dataRange) { var niceMax = Math.ceil(dataRange.max / spacing) * spacing; // If min, max and stepSize is set and they make an evenly spaced scale use it. - if (!helpers.isNullOrUndef(generationOptions.min) && !helpers.isNullOrUndef(generationOptions.max) && !helpers.isNullOrUndef(generationOptions.stepSize)) { + if (!helpers.isNullOrUndef(generationOptions.min) && !helpers.isNullOrUndef(generationOptions.max) && generationOptions.stepSize) { // If very close to our whole number, use it. if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) { niceMin = generationOptions.min;