X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph.js;h=bd3a4cc3261f8fb13051dfa035f81aa3caf57c08;hb=6a6439da128e23cdb0af494f9185b683ee7f674c;hp=6c1569807d70aad9c18a9e66f048729aeebb3017;hpb=c02097ab8767f4977d97964a092923baddc7ca08;p=dygraphs.git diff --git a/dygraph.js b/dygraph.js index 6c15698..bd3a4cc 100644 --- a/dygraph.js +++ b/dygraph.js @@ -233,6 +233,7 @@ Dygraph.DEFAULT_ATTRS = { stepPlot: false, avoidMinZero: false, + drawAxesAtZero: false, // Sizes of the various chart labels. titleHeight: 28, @@ -985,14 +986,14 @@ Dygraph.prototype.destroy = function() { for (var idx = 0; idx < this.registeredEvents_.length; idx++) { var reg = this.registeredEvents_[idx]; - this.removeEvent(reg.elem, reg.type, reg.fn); + Dygraph.removeEvent(reg.elem, reg.type, reg.fn); } this.registeredEvents_ = []; // remove mouse event handlers (This may not be necessary anymore) - this.removeEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler); - this.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler); - this.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseUpHandler_); + Dygraph.removeEvent(this.mouseEventElement_, 'mouseout', this.mouseOutHandler); + Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler); + Dygraph.removeEvent(this.mouseEventElement_, 'mousemove', this.mouseUpHandler_); removeRecursive(this.maindiv_); var nullOut = function(obj) { @@ -1003,7 +1004,7 @@ Dygraph.prototype.destroy = function() { } }; // remove event handlers - this.removeEvent(window,'resize',this.resizeHandler); + Dygraph.removeEvent(window,'resize',this.resizeHandler); this.resizeHandler = null; // These may not all be necessary, but it can't hurt... nullOut(this.layout_); @@ -1062,8 +1063,10 @@ Dygraph.prototype.createMouseEventElement_ = function() { * @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) { @@ -1075,17 +1078,18 @@ Dygraph.prototype.setColors_ = function() { // 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_); }; /** @@ -1122,7 +1126,7 @@ Dygraph.prototype.getPropertiesForSeries = function(series_name) { 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] }; }; @@ -2101,7 +2105,10 @@ Dygraph.prototype.predraw_ = function() { this.computeYAxes_(); // Create a new plotter. - if (this.plotter_) this.plotter_.clear(); + if (this.plotter_) { + this.cascadeEvents_('clearChart'); + this.plotter_.clear(); + } this.plotter_ = new DygraphCanvasRenderer(this, this.hidden_, this.hidden_ctx_, @@ -2329,8 +2336,26 @@ Dygraph.prototype.drawGraph_ = function() { * @private */ Dygraph.prototype.renderGraph_ = function(is_initial_draw) { + 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. this.canvas_.getContext('2d').clearRect(0, 0, this.canvas_.width, this.canvas_.height); @@ -2339,8 +2364,6 @@ Dygraph.prototype.renderGraph_ = function(is_initial_draw) { if (this.rangeSelector_) { this.rangeSelector_.renderInteractiveLayer(); } - - this.cascadeEvents_('drawChart'); if (this.attr_("drawCallback") !== null) { this.attr_("drawCallback")(this, is_initial_draw); } @@ -3487,6 +3510,7 @@ Dygraph.prototype.datasetIndexFromSetName_ = function(name) { * 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; " +