Took a while to get conditional show to work; works in the case where you zoom in...
authorRobert Konigsberg <konigsberg@google.com>
Fri, 4 Jan 2013 19:45:20 +0000 (14:45 -0500)
committerRobert Konigsberg <konigsberg@google.com>
Fri, 4 Jan 2013 19:45:20 +0000 (14:45 -0500)
plugins/unzoom.js

index 32d185b..8eefcf3 100644 (file)
@@ -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_);
   };