From 5d2acf298cb95cbcf42aaee980a516d13a961474 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 8 Feb 2013 17:45:36 -0500 Subject: [PATCH] Slightly scary change to fix issue 426 --- auto_tests/tests/rolling_average.js | 19 +++++++++++++++++++ dygraph.js | 2 -- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/auto_tests/tests/rolling_average.js b/auto_tests/tests/rolling_average.js index e798ca6..c0af8f9 100644 --- a/auto_tests/tests/rolling_average.js +++ b/auto_tests/tests/rolling_average.js @@ -81,3 +81,22 @@ rollingAverageTestCase.prototype.testRollBoxDoesntDisapper = function() { assertEquals("1", roll_box[0].value); }; +// Regression test for http://code.google.com/p/dygraphs/issues/detail?id=426 +rollingAverageTestCase.prototype.testRollShortFractions = function() { + var opts = { + customBars: true, + labels: ['x', 'A'] + }; + var data1 = [ [1, [1, 10, 20]] ]; + var data2 = [ [1, [1, 10, 20]], + [2, [1, 20, 30]], + ]; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, data1, opts); + + var rolled1 = g.rollingAverage(data1, 1); + var rolled2 = g.rollingAverage(data2, 1); + + assertEquals(rolled1[0], rolled2[0]); +}; diff --git a/dygraph.js b/dygraph.js index eba57db..3de6776 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2664,8 +2664,6 @@ Dygraph.prototype.extractSeries_ = function(rawData, i, logScale) { * data */ Dygraph.prototype.rollingAverage = function(originalData, rollPeriod) { - if (originalData.length < 2) - return originalData; rollPeriod = Math.min(rollPeriod, originalData.length); var rollingData = []; var sigma = this.attr_("sigma"); -- 2.7.4