basic support for missing data in CSV
authorDan Vanderkam <danvdk@gmail.com>
Sat, 28 Nov 2009 15:23:34 +0000 (10:23 -0500)
committerDan Vanderkam <danvdk@gmail.com>
Sat, 28 Nov 2009 15:23:34 +0000 (10:23 -0500)
dygraph-canvas.js
dygraph.js
tests/missing-data.html

index e03c840..2fc9eae 100644 (file)
@@ -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);
index da089ce..0d77166 100644 (file)
@@ -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);
index 082f415..482b082 100644 (file)
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <title>noise</title>
+    <title>missing data</title>
     <!--[if IE]>
     <script type="text/javascript" src="excanvas.js"></script>
     <![endif]-->
     <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>