// 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_);
enclosing.appendChild(this.graphDiv);
// Create the canvas for interactive parts of the chart.
- this.canvas_ = document.createElement("canvas");
+ // this.canvas_ = document.createElement("canvas");
+ this.canvas_ = Dygraph.createCanvas();
this.canvas_.style.position = "absolute";
this.canvas_.width = this.width_;
this.canvas_.height = this.height_;
+ this.canvas_.style.width = this.width_ + "px"; // for IE
+ this.canvas_.style.height = this.height_ + "px"; // for IE
this.graphDiv.appendChild(this.canvas_);
// ... and for static parts of the chart.
* @private
*/
Dygraph.prototype.createPlotKitCanvas_ = function(canvas) {
- var h = document.createElement("canvas");
+ // var h = document.createElement("canvas");
+ var h = Dygraph.createCanvas();
h.style.position = "absolute";
h.style.top = canvas.style.top;
h.style.left = canvas.style.left;
h.width = this.width_;
h.height = this.height_;
+ h.style.width = this.width_ + "px"; // for IE
+ h.style.height = this.height_ + "px"; // for IE
this.graphDiv.appendChild(h);
return h;
};
Dygraph.update(messagestyle, this.attr_('labelsDivStyles'));
var div = document.createElement("div");
for (var name in messagestyle) {
- div.style[name] = messagestyle[name];
+ if (messagestyle.hasOwnProperty(name)) {
+ div.style[name] = messagestyle[name];
+ }
}
this.graphDiv.appendChild(div);
this.attrs_.labelsDiv = div;
roller.size = "2";
roller.value = this.rollPeriod_;
for (var name in textAttr) {
- roller.style[name] = textAttr[name];
+ if (textAttr.hasOwnProperty(name)) {
+ roller.style[name] = textAttr[name];
+ }
}
var pa = this.graphDiv;
ctx.beginPath();
ctx.fillStyle = this.colors_[i%clen];
ctx.arc(canvasx, this.selPoints_[i%clen].canvasy, circleSize,
- 0, 360, false);
+ 0, 2 * Math.PI, false);
ctx.fill();
}
ctx.restore();
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 != null && !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] != null && !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,
var num_ok = 0;
for (var j = Math.max(0, i - rollPeriod + 1); j < i + 1; j++) {
var y = originalData[j][1];
- if (!y || isNaN(y)) continue;
+ if (y == null || isNaN(y)) continue;
num_ok++;
sum += originalData[j][1];
}
var num_ok = 0;
for (var j = Math.max(0, i - rollPeriod + 1); j < i + 1; j++) {
var y = originalData[j][1][0];
- if (!y || isNaN(y)) continue;
+ if (y == null || isNaN(y)) continue;
num_ok++;
sum += originalData[j][1][0];
variance += Math.pow(originalData[j][1][1], 2);
var labels = [];
for (var i = 0; i < cols; i++) {
labels.push(data.getColumnLabel(i));
+ if (i != 0 && this.attr_("errorBars")) i += 1;
}
this.attrs_.labels = labels;
+ cols = labels.length;
var indepType = data.getColumnType(0);
if (indepType == 'date') {
} else {
row.push(data.getValue(i, 0));
}
- for (var j = 1; j < cols; j++) {
- row.push(data.getValue(i, j));
+ if (!this.attr_("errorBars")) {
+ for (var j = 1; j < cols; j++) {
+ row.push(data.getValue(i, j));
+ }
+ } else {
+ for (var j = 0; j < cols - 1; j++) {
+ row.push([ data.getValue(i, 1 + 2 * j), data.getValue(i, 2 + 2 * j) ]);
+ }
}
ret.push(row);
}
Dygraph.update = function (self, o) {
if (typeof(o) != 'undefined' && o !== null) {
for (var k in o) {
- self[k] = o[k];
+ if (o.hasOwnProperty(k)) {
+ self[k] = o[k];
+ }
}
}
return self;
this.drawGraph_(this.rawData_);
};
+/**
+ * Create a new canvas element. This is more complex than a simple
+ * document.createElement("canvas") because of IE and excanvas.
+ */
+Dygraph.createCanvas = function() {
+ var canvas = document.createElement("canvas");
+
+ isIE = (/MSIE/.test(navigator.userAgent) && !window.opera);
+ if (isIE) {
+ canvas = G_vmlCanvasManager.initElement(canvas);
+ }
+
+ return canvas;
+};
+
/**
* A wrapper around Dygraph that implements the gviz API.