From ba049b8986972a9feb9c770e6094ea9035e9fb3b Mon Sep 17 00:00:00 2001 From: Neal Nelson Date: Wed, 2 Mar 2011 17:33:49 +0100 Subject: [PATCH] - Don't use invalid values for axis extreme calculation. - Ensure all estremes are valid or default to zero. --- dygraph.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/dygraph.js b/dygraph.js index 671de64..4bd775a 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2538,12 +2538,29 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) { var series = seriesForAxis[i]; var minY = Infinity; // extremes[series[0]][0]; var maxY = -Infinity; // extremes[series[0]][1]; + var extremeMinY, extremeMaxY; for (var j = 0; j < series.length; j++) { - minY = Math.min(extremes[series[j]][0], minY); - maxY = Math.max(extremes[series[j]][1], maxY); + // Only use valid extremes to stop null data series' from corrupting the scale. + extremeMinY = extremes[series[j]][0]; + if (extremeMinY != null) { + minY = Math.min(extremeMinY, minY); + } + extremeMaxY = extremes[series[j]][1]; + if (extremeMaxY != null) { + maxY = Math.max(extremeMaxY, maxY); + } } if (axis.includeZero && minY > 0) minY = 0; + // Ensure we have a valid scale, otherwise defualt to zero for safety. + if (minY == Infinity) { + minY = 0; + } + + if (maxY == -Infinity) { + maxY = 0; + } + // Add some padding and round up to an integer to be human-friendly. var span = maxY - minY; // special case: if we have no sense of scale, use +/-10% of the sole value. -- 2.7.4