From 599fb4adc5928be949ee5c7e90b19b0c4cca6e54 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Wed, 3 Feb 2010 09:59:28 -0800 Subject: [PATCH] add xAxisRange and a few tests --- dygraph.js | 19 ++++++++++ tests/callback.html | 10 +++++- tests/link-interaction.html | 86 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 tests/link-interaction.html 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 + + + + -- 2.7.4