Slightly scary change to fix issue 426
authorDan Vanderkam <danvdk@gmail.com>
Fri, 8 Feb 2013 22:45:36 +0000 (17:45 -0500)
committerDan Vanderkam <danvdk@gmail.com>
Fri, 8 Feb 2013 22:45:36 +0000 (17:45 -0500)
auto_tests/tests/rolling_average.js
dygraph.js

index e798ca6..c0af8f9 100644 (file)
@@ -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]);
+};
index eba57db..3de6776 100644 (file)
@@ -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");