From a4c6a67c116af8d7f5810fb7cc7a8ded13caf707 Mon Sep 17 00:00:00 2001 From: Adam Vartanian Date: Tue, 30 Mar 2010 11:13:30 -0400 Subject: [PATCH] Add unhighlightCallback option, with documentation. --- docs/index.html | 11 ++++++++++- dygraph.js | 7 +++++-- tests/callback.html | 7 +++++++ tests/crosshair.html | 10 ++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/docs/index.html b/docs/index.html index 1035783..71df56b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -775,13 +775,22 @@ perl -ne 'BEGIN{print "Month,Nominal,Real\n"} chomp; ($m,$cpi,$low,$close,$high) highlightCallback function(event, x, points) - null + null When set, this callback gets called every time a new point is highlighted. The parameters are the JavaScript mousemove event, the x-coordinate of the highlighted points and an array of highlighted points: [ {name: 'series', yval: y-value}, … ] + unhighlightCallback + function(event) + null + When set, this callback gets called every time the user stops highlighting any point by mousing out of the graph. The parameter is the mouseout event. + + + + + strokeWidth 0.5, 2.0 1.0 diff --git a/dygraph.js b/dygraph.js index 26a3812..1012d76 100644 --- a/dygraph.js +++ b/dygraph.js @@ -928,10 +928,9 @@ Dygraph.prototype.mouseMove_ = function(event) { } if (this.attr_("highlightCallback")) { - var px = this.lastHighlightCallbackX; + var px = this.lastx_; if (px !== null && lastx != px) { // only fire if the selected point has changed. - this.lastHighlightCallbackX = lastx; this.attr_("highlightCallback")(event, lastx, this.selPoints_); } } @@ -1040,6 +1039,10 @@ Dygraph.prototype.setSelection = function(row) { * @private */ Dygraph.prototype.mouseOut_ = function(event) { + if (this.attr_("unhighlightCallback")) { + this.attr_("unhighlightCallback")(event); + } + if (this.attr_("hideOverlayOnMouseOut")) { this.clearSelection(); } diff --git a/tests/callback.html b/tests/callback.html index 997e464..5a08409 100644 --- a/tests/callback.html +++ b/tests/callback.html @@ -27,6 +27,7 @@ + @@ -65,6 +66,12 @@ } }, + unhighlightCallback: function(e) { + if (document.getElementById('unhighlight').checked) { + s.innerHTML += "Unhighlight
"; + } + }, + clickCallback: function(e, x, pts) { s.innerHTML += "Click " + pts_info(e,x,pts) + "
"; }, diff --git a/tests/crosshair.html b/tests/crosshair.html index e6c4adf..45d1616 100644 --- a/tests/crosshair.html +++ b/tests/crosshair.html @@ -28,16 +28,25 @@ highlightCallback: function(e, x, pts) { for (var i = 0; i < pts.length; i++) { var y = pts[i].canvasy; + lines[i].style.display = ""; lines[i].style.top = y + "px"; if (i == 0) xline.style.left = pts[i].canvasx + "px"; } + xline.style.display = ""; + }, + unhighlightCallback: function(e) { + for (var i = 0; i < 2; i++) { + lines[i].style.display = "none"; + } + xline.style.display = "none"; } } ); for (var i = 0; i < 2; i++) { var line = document.createElement("div"); + line.style.display = "none"; line.style.width = "100%"; line.style.height = "1px"; line.style.backgroundColor = "black"; @@ -47,6 +56,7 @@ } xline = document.createElement("div"); + xline.style.display = "none"; xline.style.width = "1px"; xline.style.height = "100%"; xline.style.top = "0px"; -- 2.7.4