From 9a7309104212501d777d2b47b2f20f98833b9241 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sat, 28 Nov 2009 10:23:34 -0500 Subject: [PATCH] basic support for missing data in CSV --- dygraph-canvas.js | 16 +++++++++++----- dygraph.js | 2 ++ tests/missing-data.html | 16 +++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index e03c840..2fc9eae 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -169,11 +169,17 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { var first_point = true; var addPoint = function(ctx_, point) { if (point.name == setName) { - if (first_point) - ctx_.moveTo(point.canvasx, point.canvasy); - else - ctx_.lineTo(point.canvasx, point.canvasy); - first_point = false; + if (isNaN(point.canvasy)) { + // this will make us move to the next point, not draw a line to it. + first_point = true; + } else { + if (first_point) { + ctx_.moveTo(point.canvasx, point.canvasy); + first_point = false; + } else { + ctx_.lineTo(point.canvasx, point.canvasy); + } + } } }; MochiKit.Iter.forEach(this.layout.points, partial(addPoint, ctx), this); diff --git a/dygraph.js b/dygraph.js index da089ce..0d77166 100644 --- a/dygraph.js +++ b/dygraph.js @@ -618,6 +618,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 (this.attr_("labelsSeparateLines")) { replace += "
"; } @@ -634,6 +635,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; ctx.beginPath(); ctx.fillStyle = this.colors_[i%clen].toRGBString(); ctx.arc(canvasx, selPoints[i%clen].canvasy, circleSize, 0, 360, false); diff --git a/tests/missing-data.html b/tests/missing-data.html index 082f415..482b082 100644 --- a/tests/missing-data.html +++ b/tests/missing-data.html @@ -1,6 +1,6 @@ - noise + missing data @@ -13,12 +13,14 @@ -- 2.7.4