From: Dan Vanderkam Date: Sat, 28 Nov 2009 15:47:34 +0000 (-0500) Subject: nulls in array data X-Git-Tag: v1.0.0~872 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=584ceeaa0a8bba49baa33c87a231c408dda3ccf8;p=dygraphs.git nulls in array data --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 2fc9eae..1c5b502 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -169,7 +169,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { var first_point = true; var addPoint = function(ctx_, point) { if (point.name == setName) { - if (isNaN(point.canvasy)) { + if (!point.canvasy || isNaN(point.canvasy)) { // this will make us move to the next point, not draw a line to it. first_point = true; } else { diff --git a/dygraph.js b/dygraph.js index 0d77166..30ea8f6 100644 --- a/dygraph.js +++ b/dygraph.js @@ -611,6 +611,8 @@ Dygraph.prototype.mouseMove_ = function(event) { ctx.clearRect(px - circleSize - 1, 0, 2 * circleSize + 2, this.height_); } + var isOK = function(x) { return x && !isNaN(x); }; + if (selPoints.length > 0) { var canvasx = selPoints[0].canvasx; @@ -618,7 +620,7 @@ Dygraph.prototype.mouseMove_ = function(event) { var replace = this.attr_('xValueFormatter')(lastx, this) + ":"; var clen = this.colors_.length; for (var i = 0; i < selPoints.length; i++) { - if (isNaN(selPoints[i].canvasy)) continue; + if (!isOK(selPoints[i].canvasy)) continue; if (this.attr_("labelsSeparateLines")) { replace += "
"; } @@ -635,7 +637,7 @@ Dygraph.prototype.mouseMove_ = function(event) { // Draw colored circles over the center of each selected point ctx.save() for (var i = 0; i < selPoints.length; i++) { - if (isNaN(selPoints[i%clen].canvasy)) continue; + if (!isOK(selPoints[i%clen].canvasy)) continue; ctx.beginPath(); ctx.fillStyle = this.colors_[i%clen].toRGBString(); ctx.arc(canvasx, selPoints[i%clen].canvasy, circleSize, 0, 360, false); @@ -992,6 +994,7 @@ Dygraph.prototype.drawGraph_ = function(data) { if (series[k][0] >= low && series[k][0] <= high) { pruned.push(series[k]); var y = bars ? series[k][1][0] : series[k][1]; + if (!y) continue; if (maxY == null || y > maxY) maxY = y; if (minY == null || y < minY) minY = y; } @@ -1001,6 +1004,7 @@ Dygraph.prototype.drawGraph_ = function(data) { if (!this.customBars_) { for (var j = 0; j < series.length; j++) { var y = bars ? series[j][1][0] : series[j][1]; + if (!y) continue; if (maxY == null || y > maxY) { maxY = bars ? y + series[j][1][1] : y; } @@ -1148,6 +1152,10 @@ Dygraph.prototype.rollingAverage = function(originalData, rollPeriod) { 1.0 * (high - mid) / count ]]; } } else { + if (rollPeriod == 1) { + return originalData; + } + // Calculate the rolling average for the first rollPeriod - 1 points where // there is not enough data to roll over the full number of days var num_init_points = Math.min(rollPeriod - 1, originalData.length - 2); diff --git a/tests/missing-data.html b/tests/missing-data.html index 482b082..0206852 100644 --- a/tests/missing-data.html +++ b/tests/missing-data.html @@ -6,10 +6,14 @@ +
+
+
+