From 2ddb11979071a7d1168a456c4b5cd487477f1c5e Mon Sep 17 00:00:00 2001 From: Stanislav Chachkov Date: Wed, 10 Nov 2010 16:57:16 +0100 Subject: [PATCH] add row number to highlightCallback params --- dygraph.js | 21 ++++++++++++++++++++- tests/callback.html | 7 ++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/dygraph.js b/dygraph.js index 0893f65..944faf7 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1200,7 +1200,7 @@ Dygraph.prototype.mouseMove_ = function(event) { var px = this.lastx_; if (px !== null && lastx != px) { // only fire if the selected point has changed. - this.attr_("highlightCallback")(event, lastx, this.selPoints_); + this.attr_("highlightCallback")(event, lastx, this.selPoints_, this.idxToRow_(idx)); } } @@ -1211,6 +1211,25 @@ Dygraph.prototype.mouseMove_ = function(event) { }; /** + * Transforms layout_.points index into data row number + * @param int layout_.points index + * @return int row number + * @private + */ +Dygraph.prototype.idxToRow_ = function(idx) { + if(idx<0)return -1; + + for (var i in this.layout_.datasets) { + if (idx < this.layout_.datasets[i].length) { + return this.boundaryIds_[0][0]+idx; + } + idx-=this.layout_.datasets[i].length; + } + return -1; +} + + +/** * Draw dots over the selectied points in the data series. This function * takes care of cleanup of previously-drawn dots. * @private diff --git a/tests/callback.html b/tests/callback.html index 484689a..04ed8ea 100644 --- a/tests/callback.html +++ b/tests/callback.html @@ -36,7 +36,7 @@