this.createRollInterface_();
this.createDragInterface_();
- connect(window, 'onload', this, function(e) { this.start_(); });
+ // connect(window, 'onload', this, function(e) { this.start_(); });
+ this.start_();
};
/**
*/
DateGraph.prototype.createRollInterface_ = function() {
var padding = this.plotter_.options.padding;
+ if (typeof this.attrs_.showRoller == 'undefined') {
+ this.attrs_.showRoller = false;
+ }
+ var display = this.attrs_.showRoller ? "block" : "none";
var textAttr = { "type": "text",
"size": "2",
"value": this.rollPeriod_,
"style": { "position": "absolute",
"zIndex": 10,
"top": (this.height_ - 25 - padding.bottom) + "px",
- "left": (padding.left+1) + "px" }
+ "left": (padding.left+1) + "px",
+ "display": display }
};
var roller = MochiKit.DOM.INPUT(textAttr);
var pa = this.graphDiv;
}
}
} else if (this.customBars_) {
- // just ignore the rolling for now.
- // TODO(danvk): do something reasonable.
+ var low = 0;
+ var mid = 0;
+ var high = 0;
+ var count = 0;
for (var i = 0; i < originalData.length; i++) {
var data = originalData[i][1];
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 (i - rollPeriod >= 0) {
+ var prev = originalData[i - rollPeriod];
+ 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,
+ 1.0 * (high - mid) / count ]];
} else {
// Calculate the rolling average for the first rollPeriod - 1 points where
// there is not enough data to roll over the full number of days