From: Klaus Weidner Date: Thu, 26 Apr 2012 21:10:23 +0000 (-0700) Subject: Add new option 'drawGapPoints' X-Git-Tag: v1.0.0~271^2~3 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=19b84fe78fbbb1d8d70727719780fe6c2a67adb2;p=dygraphs.git Add new option 'drawGapPoints' 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. --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index ff291e5..e5939d0 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -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; diff --git a/dygraph-options-reference.js b/dygraph-options-reference.js index 6a72616..3fdd4ea 100644 --- a/dygraph-options-reference.js +++ b/dygraph-options-reference.js @@ -43,6 +43,12 @@ Dygraph.OPTIONS_REFERENCE = // "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 drawPointCallback." }, + "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"], diff --git a/tests/isolated-points.html b/tests/isolated-points.html index c09048d..85e8fd8 100644 --- a/tests/isolated-points.html +++ b/tests/isolated-points.html @@ -29,6 +29,10 @@ ], { labels: ["X", "S1", "S2" ], + S1: { + drawGapPoints: true + }, + pointSize: 4, showRoller: true } );