From: Robert Konigsberg Date: Fri, 4 Jan 2013 19:45:20 +0000 (-0500) Subject: Took a while to get conditional show to work; works in the case where you zoom in... X-Git-Tag: v1.0.0~129^2~3 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=8f6c7ad7692372707cdd922b0e6b7d29dc043d9e;hp=eced46cfdfe378a0152ecae57db0cf2815850f20;p=dygraphs.git 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. --- 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_); };