From: Dan Vanderkam <danvdk@gmail.com>
Date: Sat, 28 Nov 2009 15:23:34 +0000 (-0500)
Subject: basic support for missing data in CSV
X-Git-Tag: v1.0.0~873
X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=9a7309104212501d777d2b47b2f20f98833b9241;p=dygraphs.git

basic support for missing data in CSV
---

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 += "<br/>";
       }
@@ -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 @@
 <html>
   <head>
-    <title>noise</title>
+    <title>missing data</title>
     <!--[if IE]>
     <script type="text/javascript" src="excanvas.js"></script>
     <![endif]-->
@@ -13,12 +13,14 @@
     <script type="text/javascript">
     new Dygraph(
       document.getElementById("graph"),
-      "Date,Value\n" +
-      "2009/12/01,10\n" +
-      "2009/12/02,15\n" +
-      "2009/12/03,\n" +
-      "2009/12/04,20\n" +
-      "2009/12/05,15\n"
+      "Date,GapSeries1,GapSeries2\n" +
+      "2009/12/01,10,10\n" +
+      "2009/12/02,15,11\n" +
+      "2009/12/03,,12\n" +
+      "2009/12/04,20,13\n" +
+      "2009/12/05,15,\n" +
+      "2009/12/06,18,15\n" +
+      "2009/12/07,12,16\n"
     );
     </script>
   </body>