X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph.js;h=1d33570a77aa1c9152dabb0b5798a698cde865de;hb=b66a63b16308084fc2fe24b5b70056c39f39beb7;hp=6a162e011f869807a792b160993d222a81294a3e;hpb=24c213629697b908cf5727990a17c265a7dfe444;p=dygraphs.git diff --git a/dygraph.js b/dygraph.js index 6a162e0..1d33570 100644 --- a/dygraph.js +++ b/dygraph.js @@ -44,7 +44,7 @@ */ /*jshint globalstrict: true */ -/*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false */ +/*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false,ActiveXObject:false */ "use strict"; /** @@ -62,6 +62,12 @@ * options, see http://dygraphs.com/options.html. */ var Dygraph = function(div, data, opts, opt_fourth_param) { + // These have to go above the "Hack for IE" in __init__ since .ready() can be + // called as soon as the constructor returns. Once support for OldIE is + // dropped, this can go down with the rest of the initializers. + this.is_initial_draw_ = true; + this.readyFns_ = []; + if (opt_fourth_param !== undefined) { // Old versions of dygraphs took in the series labels as a constructor // parameter. This doesn't make sense anymore, but it's easy to continue @@ -74,7 +80,7 @@ var Dygraph = function(div, data, opts, opt_fourth_param) { }; Dygraph.NAME = "Dygraph"; -Dygraph.VERSION = "1.2"; +Dygraph.VERSION = "1.0.1"; Dygraph.__repr__ = function() { return "[" + this.NAME + " " + this.VERSION + "]"; }; @@ -439,7 +445,6 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { this.fractions_ = attrs.fractions || false; this.dateWindow_ = attrs.dateWindow || null; - this.is_initial_draw_ = true; this.annotations_ = []; // Zoomed indicators - These indicate when the graph has been zoomed and on what axis. @@ -852,7 +857,7 @@ Dygraph.prototype.toDataYCoord = function(y, axis) { var yRange = this.yAxisRange(axis); if (typeof(axis) == "undefined") axis = 0; - if (!this.axes_[axis].logscale) { + if (!this.attributes_.getForAxis("logscale", axis)) { return yRange[0] + (area.y + area.h - y) / area.h * (yRange[1] - yRange[0]); } else { // Computing the inverse of toDomCoord. @@ -2282,6 +2287,7 @@ Dygraph.PointType = undefined; /** * Converts a series to a Point array. * + * @private * @param {Array.)>} series Array where * series[row] = [x,y] or [x, [y, err]] or [x, [y, yplus, yminus]]. * @param {boolean} bars True if error bars or custom bars are being drawn. @@ -2333,6 +2339,7 @@ Dygraph.seriesToPoints_ = function(series, bars, setName, boundaryIdStart) { * to reflect the stacked values. * @param {string} fillMethod Interpolation method, one of 'all', 'inside', or * 'none'. + * @private */ Dygraph.stackPoints_ = function( points, cumulativeYval, seriesExtremes, fillMethod) { @@ -2610,6 +2617,13 @@ Dygraph.prototype.renderGraph_ = function(is_initial_draw) { if (this.attr_("drawCallback") !== null) { this.attr_("drawCallback")(this, is_initial_draw); } + if (is_initial_draw) { + this.readyFired_ = true; + while (this.readyFns_.length > 0) { + var fn = this.readyFns_.pop(); + fn(this); + } + } }; /** @@ -3532,7 +3546,16 @@ Dygraph.prototype.start_ = function() { if (line_delimiter) { this.loadedEvent_(data); } else { - var req = new XMLHttpRequest(); + // REMOVE_FOR_IE + var req; + if (window.XMLHttpRequest) { + // Firefox, Opera, IE7, and other browsers will use the native object + req = new XMLHttpRequest(); + } else { + // IE 5 and 6 will use the ActiveX control + req = new ActiveXObject("Microsoft.XMLHTTP"); + } + var caller = this; req.onreadystatechange = function () { if (req.readyState == 4) { @@ -3765,7 +3788,7 @@ Dygraph.prototype.setAnnotations = function(ann, suppressDraw) { this.annotations_ = ann; if (!this.layout_) { this.warn("Tried to setAnnotations before dygraph was ready. " + - "Try setting them in a drawCallback. See " + + "Try setting them in a ready() block. See " + "dygraphs.com/tests/annotation.html"); return; } @@ -3803,6 +3826,26 @@ Dygraph.prototype.indexFromSetName = function(name) { }; /** + * Trigger a callback when the dygraph has drawn itself and is ready to be + * manipulated. This is primarily useful when dygraphs has to do an XHR for the + * data (i.e. a URL is passed as the data source) and the chart is drawn + * asynchronously. If the chart has already drawn, the callback will fire + * immediately. + * + * This is a good place to call setAnnotation(). + * + * @param {function(!Dygraph)} callback The callback to trigger when the chart + * is ready. + */ +Dygraph.prototype.ready = function(callback) { + if (this.is_initial_draw_) { + this.readyFns_.push(callback); + } else { + callback(this); + } +}; + +/** * @private * Adds a default style for the annotation CSS classes to the document. This is * only executed when annotations are actually used. It is designed to only be