]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Update linear scale + tests
authorEvert Timberg <evert.timberg@gmail.com>
Sun, 1 Nov 2015 13:45:12 +0000 (08:45 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Sun, 1 Nov 2015 13:45:12 +0000 (08:45 -0500)
src/scales/scale.linear.js
test/scale.linear.tests.js

index e4cc4fd34fcab5e434fbd50af34226ab17471103..9b6200ef7ae01c427dbe9fd4e3089ea9b3485a37 100644 (file)
                        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) {
 
                                        }
                                }, 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) {
index 4da804266e1fce39766c4f05dc10b8f9b6055483..e83c77cdb61dfc490946da46a5167873655eec08 100644 (file)
@@ -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'
                        }]
                };