]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Scale min/max calculations now disregard bad values
authorTanner Linsley <tannerlinsley@gmail.com>
Fri, 23 Oct 2015 22:41:11 +0000 (16:41 -0600)
committerTanner Linsley <tannerlinsley@gmail.com>
Fri, 23 Oct 2015 22:41:11 +0000 (16:41 -0600)
src/scales/scale.linear.js
src/scales/scale.logarithmic.js
src/scales/scale.radialLinear.js

index 9de4d81cf6c0e178b8d35f379971ee2229997d23..cc682c19a819f32fa4ff7eebee71e1ba79ab1a99 100644 (file)
@@ -25,6 +25,9 @@
                                                helpers.each(dataset.data, function(rawValue, index) {
 
                                                        var value = this.getRightValue(rawValue);
+                                                       if (isNaN(value)) {
+                                                               return;
+                                                       }
 
                                                        positiveValues[index] = positiveValues[index] || 0;
                                                        negativeValues[index] = negativeValues[index] || 0;
@@ -51,6 +54,9 @@
                                        if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
                                                helpers.each(dataset.data, function(rawValue, index) {
                                                        var value = this.getRightValue(rawValue);
+                                                       if (isNaN(value)) {
+                                                               return;
+                                                       }
 
                                                        if (this.min === null) {
                                                                this.min = value;
                getPixelForValue: function(value, index, datasetIndex, includeOffset) {
                        // This must be called after fit has been run so that 
                        //      this.left, this.top, this.right, and this.bottom have been defined
+                       var rightValue = this.getRightValue(value);
                        var pixel;
                        var range = this.end - this.start;
 
                        if (this.isHorizontal()) {
 
                                var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
-                               pixel = this.left + (innerWidth / range * (this.getRightValue(value) - this.start));
+                               pixel = this.left + (innerWidth / range * (rightValue - this.start));
                                return Math.round(pixel + this.paddingLeft);
                        } else {
                                var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
-                               pixel = (this.bottom - this.paddingBottom) - (innerHeight / range * (this.getRightValue(value) - this.start));
+                               pixel = (this.bottom - this.paddingBottom) - (innerHeight / range * (rightValue - this.start));
                                return Math.round(pixel);
                        }
                },
index 9f5b62c47f682fc7b1e3fabdd1b08aa85e1c0520..9de8e1d4e5504d007477f8fbc8187de643397f14 100644 (file)
@@ -14,7 +14,7 @@
                                var remain = value / (Math.pow(10, Math.floor(Chart.helpers.log10(value))));
 
                                if (remain === 1 || remain === 2 || remain === 5) {
-                                       return value.toExponential()
+                                       return value.toExponential();
                                } else {
                                        return '';
                                }
@@ -38,6 +38,9 @@
                                                helpers.each(dataset.data, function(rawValue, index) {
 
                                                        var value = this.getRightValue(rawValue);
+                                                       if (isNaN(value)) {
+                                                               return;
+                                                       }
 
                                                        values[index] = values[index] || 0;
 
@@ -59,6 +62,9 @@
                                        if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
                                                helpers.each(dataset.data, function(rawValue, index) {
                                                        var value = this.getRightValue(rawValue);
+                                                       if (isNaN(value)) {
+                                                               return;
+                                                       }
 
                                                        if (this.min === null) {
                                                                this.min = value;
index d094eb4c89d22d6c916048a3c1510bc75eb200e1..7f315c73c78c5605b50d44024d59be4ca2797e1e 100644 (file)
 
                        helpers.each(this.data.datasets, function(dataset) {
                                if (helpers.isDatasetVisible(dataset)) {
-                                       helpers.each(dataset.data, function(value, index) {
-                                               if (value === null) return;
+                                       helpers.each(dataset.data, function(rawValue, index) {
+                                               var value = this.getRightValue(rawValue);
+                                               if (isNaN(value)) {
+                                                       return;
+                                               }
 
                                                if (this.min === null) {
                                                        this.min = value;