From: Dan Vanderkam Date: Wed, 3 Feb 2010 17:59:28 +0000 (-0800) Subject: add xAxisRange and a few tests X-Git-Tag: v1.0.0~741 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=599fb4adc5928be949ee5c7e90b19b0c4cca6e54;p=dygraphs.git add xAxisRange and a few tests --- diff --git a/dygraph.js b/dygraph.js index 1df7cc1..8a303a0 100644 --- a/dygraph.js +++ b/dygraph.js @@ -254,6 +254,21 @@ Dygraph.prototype.rollPeriod = function() { return this.rollPeriod_; }; +/** + * Returns the currently-visible x-range. This can be affected by zooming, + * panning or a call to updateOptions. + * Returns a two-element array: [left, right]. + * If the Dygraph has dates on the x-axis, these will be millis since epoch. + */ +Dygraph.prototype.xAxisRange = function() { + if (this.dateWindow_) return this.dateWindow_; + + // The entire chart is visible. + var left = this.rawData_[0][0]; + var right = this.rawData_[this.rawData_.length - 1][0]; + return [left, right]; +}; + Dygraph.addEvent = function(el, evt, fn) { var normed_fn = function(e) { if (!e) var e = window.event; @@ -1323,6 +1338,10 @@ Dygraph.prototype.drawGraph_ = function(data) { this.plotter_.render(); this.canvas_.getContext('2d').clearRect(0, 0, this.canvas_.width, this.canvas_.height); + + if (this.attr_("drawCallback") !== null) { + this.attr_("drawCallback")(this); + } }; /** diff --git a/tests/callback.html b/tests/callback.html index 7f9d278..b4ba5cd 100644 --- a/tests/callback.html +++ b/tests/callback.html @@ -13,6 +13,8 @@

Hover, click and zoom to test the callbacks:

+ +
+ + + + +
+ Zoom: + hour + day + week + month + full + Pan: + left + right + + + +