From 8324b35506459407cbfeacbbc5e66b2655823cba Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sun, 1 Nov 2015 08:45:12 -0500 Subject: [PATCH] Update linear scale + tests --- src/scales/scale.linear.js | 24 ++++++++++++++++++------ test/scale.linear.tests.js | 10 ++++++++-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index e4cc4fd34..9b6200ef7 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -42,11 +42,21 @@ this.min = null; this.max = null; - var positiveValues = []; - var negativeValues = []; - if (this.options.stacked) { + var valuesPerType = {}; + helpers.each(this.data.datasets, function(dataset) { + if (valuesPerType[dataset.type] === undefined) { + valuesPerType[dataset.type] = { + positiveValues: [], + negativeValues: [], + }; + } + + // Store these per type + var positiveValues = valuesPerType[dataset.type].positiveValues; + var negativeValues = valuesPerType[dataset.type].negativeValues; + if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) { helpers.each(dataset.data, function(rawValue, index) { @@ -71,9 +81,11 @@ } }, this); - var values = positiveValues.concat(negativeValues); - this.min = helpers.min(values); - this.max = helpers.max(values); + helpers.each(valuesPerType, function(valuesForType) { + var values = valuesForType.positiveValues.concat(valuesForType.negativeValues); + this.min = Math.min(this.min, helpers.min(values)); + this.max = Math.max(this.max, helpers.max(values)); + }, this); } else { helpers.each(this.data.datasets, function(dataset) { diff --git a/test/scale.linear.tests.js b/test/scale.linear.tests.js index 4da804266..e83c77cdb 100644 --- a/test/scale.linear.tests.js +++ b/test/scale.linear.tests.js @@ -188,13 +188,19 @@ describe('Linear Scale', function() { var mockData = { datasets: [{ yAxisID: scaleID, - data: [10, 5, 0, -5, 78, -100] + data: [10, 5, 0, -5, 78, -100], + type: 'bar' }, { yAxisID: 'second scale', data: [-1000, 1000], }, { yAxisID: scaleID, - data: [150, 0, 0, -100, -10, 9] + data: [150, 0, 0, -100, -10, 9], + type: 'bar' + }, { + yAxisID: scaleID, + data: [10, 10, 10, 10, 10, 10], + type: 'line' }] }; -- 2.47.3