* @private
*/
Dygraph.prototype.setColors_ = function() {
- var num = this.attr_("labels").length - 1;
+ var labels = this.getLabels();
+ var num = labels.length - 1;
this.colors_ = [];
+ this.colorsMap_ = {};
var colors = this.attr_('colors');
var i;
if (!colors) {
// alternate colors for high contrast.
var idx = i % 2 ? Math.ceil(i / 2) : (half + i / 2);
var hue = (1.0 * idx/ (1 + num));
- this.colors_.push(Dygraph.hsvToRGB(hue, sat, val));
+ var colorStr = Dygraph.hsvToRGB(hue, sat, val);
+ this.colors_.push(colorStr);
+ this.colorsMap_[labels[i]] = colorStr;
}
} else {
for (i = 0; i < num; i++) {
if (!this.visibility()[i]) continue;
var colorStr = colors[i % colors.length];
this.colors_.push(colorStr);
+ this.colorsMap_[labels[1 + i]] = colorStr;
}
}
-
- this.plotter_.setColors(this.colors_);
};
/**
name: series_name,
column: idx,
visible: this.visibility()[idx - 1],
- color: this.plotter_.colors[series_name],
+ color: this.colorsMap_[series_name],
axis: 1 + this.seriesToAxisMap_[series_name]
};
};
this.cascadeEvents_('clearChart');
this.plotter_.clear();
+ if (this.attr_('underlayCallback')) {
+ // NOTE: we pass the dygraph object to this callback twice to avoid breaking
+ // users who expect a deprecated form of this callback.
+ this.attr_('underlayCallback')(
+ this.hidden_ctx_, this.layout_.getPlotArea(), this, this);
+ }
+
+ var e = {
+ canvas: this.hidden_,
+ drawingContext: this.hidden_ctx_,
+ };
+ this.cascadeEvents_('willDrawChart', e);
this.plotter_.render();
+ this.cascadeEvents_('didDrawChart', e);
// TODO(danvk): is this a performance bottleneck when panning?
// The interaction canvas should already be empty in that situation.
if (this.rangeSelector_) {
this.rangeSelector_.renderInteractiveLayer();
}
-
- this.cascadeEvents_('drawChart');
if (this.attr_("drawCallback") !== null) {
this.attr_("drawCallback")(this, is_initial_draw);
}
* called once -- all calls after the first will return immediately.
*/
Dygraph.addAnnotationRule = function() {
+ // TODO(danvk): move this function into plugins/annotations.js?
if (Dygraph.addedAnnotationCSS) return;
var rule = "border: 1px solid black; " +