this.dateWindow_ = attrs.dateWindow || null;
this.valueRange_ = attrs.valueRange || null;
this.wilsonInterval_ = attrs.wilsonInterval || true;
+ this.is_initial_draw_ = true;
// Clear the div. This ensure that, if multiple dygraphs are passed the same
// div, then only one will be drawn.
this.height_ = (this.height_ * self.innerHeight / 100) - 10;
}
+ // TODO(danvk): set fillGraph to be part of attrs_ here, not user_attrs_.
if (attrs['stackedGraph']) {
attrs['fillGraph'] = true;
// TODO(nikhilk): Add any other stackedGraph checks here.
}
}
- // MERGE: check if this breaks compatibility.
if (this.attr_("highlightCallback")) {
var px = this.lastHighlightCallbackX;
if (px !== null && lastx != px) {
+ // only fire if the selected point has changed.
this.lastHighlightCallbackX = lastx;
- this.attr_("highlightCallback")(event, lastx, this.selPoints_);
- var callbackPoints = this.selPoints_.map(
- function(p) { return {xval: p.xval, yval: p.yval, name: p.name} });
- if (this.attr_("stackedGraph")) {
+ if (!this.attr_("stackedGraph")) {
+ this.attr_("highlightCallback")(event, lastx, this.selPoints_);
+ } else {
// "unstack" the points.
+ var callbackPoints = this.selPoints_.map(
+ function(p) { return {xval: p.xval, yval: p.yval, name: p.name} });
var cumulative_sum = 0;
for (var j = callbackPoints.length - 1; j >= 0; j--) {
callbackPoints[j].yval -= cumulative_sum;
cumulative_sum += callbackPoints[j].yval;
}
+ this.attr_("highlightCallback")(event, lastx, callbackPoints);
}
- this.attr_("highlightCallback")(event, lastx, callbackPoints);
}
}
return zeropad(d.getHours()) + ":" +
zeropad(d.getMinutes()) + ":" +
zeropad(d.getSeconds());
- } else if (d.getMinutes()) {
- return zeropad(d.getHours()) + ":" + zeropad(d.getMinutes());
} else {
- return zeropad(d.getHours());
+ return zeropad(d.getHours()) + ":" + zeropad(d.getMinutes());
}
}
* @private
*/
Dygraph.prototype.drawGraph_ = function(data) {
+ // This is used to set the second parameter to drawCallback, below.
+ var is_initial_draw = this.is_initial_draw_;
+ this.is_initial_draw_ = false;
+
var minY = null, maxY = null;
this.layout_.removeAllDatasets();
this.setColors_();
// For stacked series.
var cumulative_y = [];
- var datasets = [];
+ var stacked_datasets = [];
// Loop over all fields in the dataset
if (!maxY || cumulative_y[series[j][0]] > maxY)
maxY = cumulative_y[series[j][0]];
}
- datasets.push([this.attr_("labels")[i], vals]);
+ stacked_datasets.push([this.attr_("labels")[i], vals]);
//this.layout_.addDataset(this.attr_("labels")[i], vals);
} else {
this.layout_.addDataset(this.attr_("labels")[i], series);
}
}
-// MERGE: move up into the stackedGraph section.
- if (datasets.length > 0) {
- for (var i = (datasets.length - 1); i >= 0; i--) {
- this.layout_.addDataset(datasets[i][0], datasets[i][1]);
+ if (stacked_datasets.length > 0) {
+ for (var i = (stacked_datasets.length - 1); i >= 0; i--) {
+ this.layout_.addDataset(stacked_datasets[i][0], stacked_datasets[i][1]);
}
}
this.canvas_.height);
if (this.attr_("drawCallback") !== null) {
- this.attr_("drawCallback")(this);
+ this.attr_("drawCallback")(this, is_initial_draw);
}
};
Dygraph.dateParser = function(dateStr, self) {
var dateStrSlashed;
var d;
- if (dateStr.length == 10 && dateStr.search("-") != -1) { // e.g. '2009-07-12'
+ if (dateStr.search("-") != -1) { // e.g. '2009-7-12' or '2009-07-12'
dateStrSlashed = dateStr.replace("-", "/", "g");
while (dateStrSlashed.search("-") != -1) {
dateStrSlashed = dateStrSlashed.replace("-", "/");