Add new option 'drawGapPoints'
authorKlaus Weidner <klausw@google.com>
Thu, 26 Apr 2012 21:10:23 +0000 (14:10 -0700)
committerKlaus Weidner <klausw@google.com>
Thu, 26 Apr 2012 21:10:23 +0000 (14:10 -0700)
Setting this option will draw points at the edges of gaps in the data.

It's similar to the built-in isolated point logic, but also draws
half-isolated points where only one neighbor is missing.

dygraph-canvas.js
dygraph-options-reference.js
tests/isolated-points.html

index ff291e5..e5939d0 100644 (file)
@@ -692,6 +692,7 @@ DygraphCanvasRenderer.prototype._drawStyledLine = function(
   if (!Dygraph.isArrayLike(strokePattern)) {
     strokePattern = null;
   }
+  var drawGapPoints = this.dygraph_.attr_('drawGapPoints', setName);
 
   var point;
   var next = DygraphCanvasRenderer.makeNextPointStep_(
@@ -715,6 +716,14 @@ DygraphCanvasRenderer.prototype._drawStyledLine = function(
       // and next points are null.
       var isIsolated = (!prevX && (j == points.length - 1 ||
                                    isNullOrNaN(points[j+1].canvasy)));
+      if (drawGapPoints) {
+        // Also consider a point to be is "isolated" if it's adjacent to a
+        // null point, excluding the graph edges.
+        if ((j > 0 && !prevX) ||
+            (j < points.length - 1 && isNullOrNaN(points[j+1].canvasy))) {
+          isIsolated = true;
+        }
+      }
       if (prevX === null) {
         prevX = point.canvasx;
         prevY = point.canvasy;
index 6a72616..3fdd4ea 100644 (file)
@@ -43,6 +43,12 @@ Dygraph.OPTIONS_REFERENCE =  // <JSON>
     "type": "boolean",
     "description": "Draw a small dot at each point, in addition to a line going through the point. This makes the individual data points easier to see, but can increase visual clutter in the chart. The small dot can be replaced with a custom rendering by supplying a <a href='#drawPointCallback'>drawPointCallback</a>."
   },
+  "drawGapPoints": {
+    "default": "false",
+    "labels": ["Data Line display"],
+    "type": "boolean",
+    "description": "Draw points at the edges of gaps in the data. This improves visibility of small data segments or other data irregularities."
+  },
   "drawPointCallback": {
     "default": "null",
     "labels": ["Data Line display"],
index c09048d..85e8fd8 100644 (file)
       ],
       {
         labels: ["X", "S1", "S2" ],
+        S1: {
+          drawGapPoints: true
+        },
+        pointSize: 4,
         showRoller: true
       }
     );