add row number to highlightCallback params
authorStanislav Chachkov <vertigo@ajuz.local>
Wed, 10 Nov 2010 15:57:16 +0000 (16:57 +0100)
committerStanislav Chachkov <vertigo@ajuz.local>
Wed, 10 Nov 2010 15:57:16 +0000 (16:57 +0100)
dygraph.js
tests/callback.html

index 0893f65..944faf7 100644 (file)
@@ -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
index 484689a..04ed8ea 100644 (file)
@@ -36,7 +36,7 @@
     <script type="text/javascript">
       s = document.getElementById("status");
       g = null;
-      pts_info = function(e, x, pts) {
+      pts_info = function(e, x, pts, row) {
         var str = "(" + x + ") ";
         for (var i = 0; i < pts.length; i++) {
           var p = pts[i];
@@ -49,6 +49,7 @@
         var dataXY = g.toDataCoords(x, y);
         str += ", (" + x + ", " + y + ")";
         str += " -> (" + dataXY[0] + ", " + dataXY[1] + ")";
+        str += ", row #"+row;
 
         return str;
       };
@@ -60,9 +61,9 @@
               showRoller: true,
               errorBars: true,
 
-              highlightCallback: function(e, x, pts) {
+              highlightCallback: function(e, x, pts, row) {
                 if (document.getElementById('highlight').checked) {
-                  s.innerHTML += "<b>Highlight</b> " + pts_info(e,x,pts) + "<br/>";
+                  s.innerHTML += "<b>Highlight</b> " + pts_info(e,x,pts,row) + "<br/>";
                 }
               },