fix some customError bugs
authorDan Vanderkam <danvdk@gmail.com>
Sun, 6 Dec 2009 01:57:25 +0000 (17:57 -0800)
committerDan Vanderkam <danvdk@gmail.com>
Sun, 6 Dec 2009 01:57:25 +0000 (17:57 -0800)
dygraph-combined.js
dygraph.js

index 61733c0..8b1628e 100644 (file)
@@ -470,9 +470,10 @@ this.attrs_={};
 Dygraph.update(this.attrs_,Dygraph.DEFAULT_ATTRS);
 this.labelsFromCSV_=(this.attr_("labels")==null);
 this.createInterface_();
-this.layoutOptions_={"errorBars":(this.attr_("errorBars")||this.attr_("customBars")),"xOriginIsZero":false};
+this.layoutOptions_={"xOriginIsZero":false};
 Dygraph.update(this.layoutOptions_,this.attrs_);
 Dygraph.update(this.layoutOptions_,this.user_attrs_);
+Dygraph.update(this.layoutOptions_,{"errorBars":(this.attr_("errorBars")||this.attr_("customBars"))});
 this.layout_=new DygraphLayout(this,this.layoutOptions_);
 this.renderOptions_={colorScheme:this.colors_,strokeColor:null,axisLineWidth:Dygraph.AXIS_LINE_WIDTH};
 Dygraph.update(this.renderOptions_,this.attrs_);
@@ -1297,17 +1298,21 @@ for(var i=0;i<_235.length;i++){
 var data=_235[i][1];
 var y=data[1];
 _237[i]=[_235[i][0],[y,y-data[0],data[2]-y]];
+if(y&&!isNaN(y)){
 low+=data[0];
 mid+=y;
 high+=data[2];
 _246+=1;
+}
 if(i-_236>=0){
 var prev=_235[i-_236];
+if(prev[1][1]&&!isNaN(prev[1][1])){
 low-=prev[1][0];
 mid-=prev[1][1];
 high-=prev[1][2];
 _246-=1;
 }
+}
 _237[i]=[_235[i][0],[1*mid/_246,1*(mid-low)/_246,1*(high-mid)/_246]];
 }
 }else{
index 402bcc7..bdfa1b1 100644 (file)
@@ -193,11 +193,11 @@ Dygraph.prototype.__init__ = function(div, file, attrs) {
 
   // Create the PlotKit grapher
   // TODO(danvk): why does the Layout need its own set of options?
-  this.layoutOptions_ = { 'errorBars': (this.attr_("errorBars") ||
-                                        this.attr_("customBars")),
-                          'xOriginIsZero': false };
+  this.layoutOptions_ = { 'xOriginIsZero': false };
   Dygraph.update(this.layoutOptions_, this.attrs_);
   Dygraph.update(this.layoutOptions_, this.user_attrs_);
+  Dygraph.update(this.layoutOptions_, {
+    'errorBars': (this.attr_("errorBars") || this.attr_("customBars")) });
 
   this.layout_ = new DygraphLayout(this, this.layoutOptions_);
 
@@ -1268,16 +1268,20 @@ Dygraph.prototype.rollingAverage = function(originalData, rollPeriod) {
       var y = data[1];
       rollingData[i] = [originalData[i][0], [y, y - data[0], data[2] - y]];
 
-      low += data[0];
-      mid += y;
-      high += data[2];
-      count += 1;
+      if (y && !isNaN(y)) {
+        low += data[0];
+        mid += y;
+        high += data[2];
+        count += 1;
+      }
       if (i - rollPeriod >= 0) {
         var prev = originalData[i - rollPeriod];
-        low -= prev[1][0];
-        mid -= prev[1][1];
-        high -= prev[1][2];
-        count -= 1;
+        if (prev[1][1] && !isNaN(prev[1][1])) {
+          low -= prev[1][0];
+          mid -= prev[1][1];
+          high -= prev[1][2];
+          count -= 1;
+        }
       }
       rollingData[i] = [originalData[i][0], [ 1.0 * mid / count,
                                               1.0 * (mid - low) / count,