From: Tanner Linsley Date: Fri, 23 Oct 2015 22:41:11 +0000 (-0600) Subject: Scale min/max calculations now disregard bad values X-Git-Tag: 2.0.0-beta~3^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea571003d9e18844d96c3900cef37b636ccc60bf;p=thirdparty%2FChart.js.git Scale min/max calculations now disregard bad values --- diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 9de4d81cf..cc682c19a 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -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; @@ -155,17 +161,18 @@ 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); } }, diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 9f5b62c47..9de8e1d4e 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -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; diff --git a/src/scales/scale.radialLinear.js b/src/scales/scale.radialLinear.js index d094eb4c8..7f315c73c 100644 --- a/src/scales/scale.radialLinear.js +++ b/src/scales/scale.radialLinear.js @@ -69,8 +69,11 @@ 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;