From: Dan Vanderkam Date: Fri, 28 Nov 2014 20:50:29 +0000 (-0500) Subject: Patch up NaN values in error bars X-Git-Tag: v1.1.0~7^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=87c5a64c0521a645972b52e3a767d14548a06bc3;p=dygraphs.git Patch up NaN values in error bars --- diff --git a/auto_tests/tests/missing_points.js b/auto_tests/tests/missing_points.js index a78e0ac..eb1c575 100644 --- a/auto_tests/tests/missing_points.js +++ b/auto_tests/tests/missing_points.js @@ -368,3 +368,36 @@ MissingPointsTestCase.prototype.testEmptySeries = function() { g.setSelection(6); assertEquals("1381134466: Series 2: 94", Util.getLegend(graphDiv)); }; + +// Regression test for issue #485 +MissingPointsTestCase.prototype.testMissingFill = function() { + var graphDiv = document.getElementById("graph"); + var N = null; + var g = new Dygraph( + graphDiv, + [ + [1, [8, 10, 12]], + [2, [3, 5,7] ], + [3, N, ], + [4, [9, N, 2] ], // Note: nulls in arrays are not technically valid. + [5, [N, 2, N] ], // see dygraphs.com/data.html. + [6, [2, 3, 6] ] + ], + { + customBars: true, + connectSeparatedPoints: false, + labels: [ "X", "Series1"] + } + ); + + // Make sure there are no 'NaN' line segments. + var htx = g.hidden_ctx_; + for (var i = 0; i < htx.calls__.length; i++) { + var call = htx.calls__[i]; + if ((call.name == 'moveTo' || call.name == 'lineTo') && call.args) { + for (var j = 0; j < call.args.length; j++) { + assertFalse(isNaN(call.args[j])); + } + } + } +}; diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 4d7a7dd..6e503d9 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -599,12 +599,16 @@ DygraphCanvasRenderer._errorPlotter = function(e) { continue; } + newYs = [ point.y_bottom, point.y_top ]; if (stepPlot) { - newYs = [ point.y_bottom, point.y_top ]; prevY = point.y; - } else { - newYs = [ point.y_bottom, point.y_top ]; } + + // The documentation specifically disallows nulls inside the point arrays, + // but in case it happens we should do something sensible. + if (isNaN(newYs[0])) newYs[0] = point.y; + if (isNaN(newYs[1])) newYs[1] = point.y; + newYs[0] = e.plotArea.h * newYs[0] + e.plotArea.y; newYs[1] = e.plotArea.h * newYs[1] + e.plotArea.y; if (!isNaN(prevX)) {