From 8f6c7ad7692372707cdd922b0e6b7d29dc043d9e Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Fri, 4 Jan 2013 14:45:20 -0500 Subject: [PATCH] Took a while to get conditional show to work; works in the case where you zoom in on a graph using the mouse, and don't have the mouseover event since you're already over. --- plugins/unzoom.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/unzoom.js b/plugins/unzoom.js index 32d185b..8eefcf3 100644 --- a/plugins/unzoom.js +++ b/plugins/unzoom.js @@ -35,6 +35,7 @@ Dygraph.Plugins.Unzoom = (function() { */ var unzoom = function() { this.button_ = null; + this.over_ = false; }; unzoom.prototype.toString = function() { @@ -51,6 +52,9 @@ Dygraph.Plugins.Unzoom = (function() { var g = e.dygraph; if (this.button_ != null) { + if (g.isZoomed() && this.over_) { + this.show(true); + } return; } @@ -69,16 +73,24 @@ Dygraph.Plugins.Unzoom = (function() { // TODO(konigsberg): doUnzoom_ is private. g.doUnzoom_(); } + g.addEvent(parent, 'mouseover', function() { - self.button_.style.display='block'; + if (g.isZoomed()) { + self.show(true); + } + self.over_ = true; }); - // TODO(konigsberg): Don't show unless the graph is zoomed. g.addEvent(parent, 'mouseout', function() { - self.button_.style.display='none'; + self.show(false); + self.over_ = false; }); }; + unzoom.prototype.show = function(enabled) { + this.button_.style.display = enabled ? 'block' : 'none'; + }; + unzoom.prototype.destroy = function() { this.button_.parentElement.removeChild(this.button_); }; -- 2.7.4