From cf89eeed067fa2892ea502eab07a29546b9848a8 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Thu, 16 Aug 2012 18:01:12 -0400 Subject: [PATCH] Fix Issue 229:valueRange and errorBars not mixing when valueRange max = data max --- auto_tests/tests/custom_bars.js | 31 +++++++++++++++++++++++++++++++ dygraph-canvas.js | 10 +++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/auto_tests/tests/custom_bars.js b/auto_tests/tests/custom_bars.js index 1e1b0c9..22ffd20 100644 --- a/auto_tests/tests/custom_bars.js +++ b/auto_tests/tests/custom_bars.js @@ -75,3 +75,34 @@ CustomBarsTestCase.prototype.testCustomBarsZero = function() { assertTrue('y-axis must include 0', range[0] <= 0); assertTrue('y-axis must include 5', range[1] >= 5); }; + +// Regression test for http://code.google.com/p/dygraphs/issues/detail?id=229 +CustomBarsTestCase.prototype.testCustomBarsAtTop = function() { + var g = new Dygraph(document.getElementById("graph"), + [ + [1, [10, 10, 100]], + [1, [10, 10, 100]], + [2, [15, 20, 110]], + [3, [10, 30, 100]], + [4, [15, 40, 110]], + [5, [10,120, 100]], + [6, [15, 50, 110]], + [7, [10, 70, 100]], + [8, [15, 90, 110]], + [9, [10, 50, 100]] + ], { + width: 500, height: 350, + customBars: true, + errorBars: true, + drawXGrid: false, + drawYGrid: false, + drawXAxis: false, + drawYAxis: false, + valueRange: [0, 120], + fillAlpha: 0.15, + colors: [ '#00FF00' ] + }); + + var sampler = new PixelSampler(g); + assertEquals([0, 255, 0, 38], sampler.colorAtCoordinate(5, 60)); +}; diff --git a/dygraph-canvas.js b/dygraph-canvas.js index d9ef742..29e402e 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -615,9 +615,17 @@ DygraphCanvasRenderer._errorPlotter = function(e) { 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',' + fillAlpha + ')'; ctx.fillStyle = err_color; ctx.beginPath(); + + var isNullUndefinedOrNaN = function(x) { + return (x === null || + x === undefined || + isNaN(x)); + }; + while (iter.hasNext) { var point = iter.next(); - if ((!stepPlot && !Dygraph.isOK(point.y)) || (stepPlot && !isNaN(prevY) && !Dygraph.isOK(prevY))) { + if ((!stepPlot && isNullUndefinedOrNaN(point.y)) || + (stepPlot && !isNaN(prevY) && isNullUndefinedOrNaN(prevY))) { prevX = NaN; continue; } -- 2.7.4