]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Log scale + tests 1601/head
authorEvert Timberg <evert.timberg@gmail.com>
Sun, 1 Nov 2015 14:07:18 +0000 (09:07 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Sun, 1 Nov 2015 14:07:18 +0000 (09:07 -0500)
src/scales/scale.linear.js
src/scales/scale.logarithmic.js
test/scale.logarithmic.tests.js

index 9b6200ef7ae01c427dbe9fd4e3089ea9b3485a37..ac8954fa1208ceefbc0049002c99cddf2bff7e87 100644 (file)
 
                                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));
+                                       var minVal = helpers.min(values);
+                                       var maxVal = helpers.max(values);
+                                       this.min = this.min === null ? minVal : Math.min(this.min, minVal);
+                                       this.max = this.max === null ? maxVal : Math.max(this.max, maxVal);
                                }, this);
 
                        } else {
index 9de8e1d4e5504d007477f8fbc8187de643397f14..467a4cc8bf7558ef58f7652b51b104ca250d2cb2 100644 (file)
                        this.min = null;
                        this.max = null;
 
-                       var values = [];
-
                        if (this.options.stacked) {
+                               var valuesPerType = {};
+
                                helpers.each(this.data.datasets, function(dataset) {
                                        if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
-                                               helpers.each(dataset.data, function(rawValue, index) {
+                                               if (valuesPerType[dataset.type] === undefined) {
+                                                       valuesPerType[dataset.type] = [];
+                                               }
 
+                                               helpers.each(dataset.data, function(rawValue, index) {
+                                                       var values = valuesPerType[dataset.type];
                                                        var value = this.getRightValue(rawValue);
                                                        if (isNaN(value)) {
                                                                return;
                                        }
                                }, this);
 
-                               this.min = helpers.min(values);
-                               this.max = helpers.max(values);
+                               helpers.each(valuesPerType, function(valuesForType) {
+                                       var minVal = helpers.min(valuesForType);
+                                       var maxVal = helpers.max(valuesForType);
+                                       this.min = this.min === null ? minVal : Math.min(this.min, minVal);
+                                       this.max = this.max === null ? maxVal : Math.max(this.max, maxVal);
+                               }, this);
 
                        } else {
                                helpers.each(this.data.datasets, function(dataset) {
index 72250df73ba0832984c0b39ce596a23dff7a3b9c..7493e3de6302f29ae17c6955c710a1a7a1f4b415 100644 (file)
@@ -175,13 +175,19 @@ describe('Logarithmic Scale tests', function() {
                var mockData = {
                        datasets: [{
                                yAxisID: scaleID,
-                               data: [10, 5, 1, 5, 78, 100]
+                               data: [10, 5, 1, 5, 78, 100],
+                               type: 'bar'
                        }, {
                                yAxisID: 'second scale',
                                data: [-1000, 1000],
                        }, {
                                yAxisID: scaleID,
-                               data: [150, 10, 10, 100, 10, 9]
+                               data: [150, 10, 10, 100, 10, 9],
+                               type: 'bar'
+                       }, {
+                               yAxisID: scaleID,
+                               data: [100, 100, 100, 100, 100, 100],
+                               type: 'line'
                        }]
                };
 
@@ -208,17 +214,21 @@ describe('Logarithmic Scale tests', function() {
                var mockData = {
                        datasets: [{
                                yAxisID: scaleID,
-                               data: [10, 5, 1, 5, 78, 100]
+                               data: [10, 5, 1, 5, 78, 100],
+                               type: 'bar'
                        }, {
                                yAxisID: 'second scale',
                                data: [-1000, 1000],
+                               type: 'bar'
                        }, {
                                yAxisID: scaleID,
-                               data: [150, 10, 10, 100, 10, 9]
+                               data: [150, 10, 10, 100, 10, 9],
+                               type: 'bar'
                        }, {
                                yAxisID: scaleID,
                                data: [10000, 10000, 10000, 10000, 10000, 10000],
-                               hidden: true
+                               hidden: true,
+                               type: 'bar'
                        }]
                };