1 // Copyright (c) 2013 Google, Inc.
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * @fileoverview Plug-in for providing unzoom-on-hover.
25 * @author konigsberg@google.com (Robert Konigsberg)
27 Dygraph
.Plugins
.Unzoom
= (function() {
32 * Create a new instance.
36 var unzoom
= function() {
39 // True when the mouse is over the canvas. Must be tracked
40 // because the unzoom button state can change even when the
41 // mouse-over state hasn't.
45 unzoom
.prototype.toString
= function() {
46 return 'Unzoom Plugin';
49 unzoom
.prototype.activate
= function(g
) {
51 willDrawChart
: this.willDrawChart
55 unzoom
.prototype.willDrawChart
= function(e
) {
58 if (this.button_
!= null) {
59 // short-circuit: show the button only when we're moused over, and zoomed in.
60 var showButton
= g
.isZoomed() && this.over_
;
61 this.show(showButton
);
65 this.button_
= document
.createElement('button');
66 this.button_
.innerHTML
= 'Reset Zoom';
67 this.button_
.style
.display
= 'none';
68 this.button_
.style
.position
= 'absolute';
69 var area
= g
.plotter_
.area
;
70 this.button_
.style
.top
= (area
.y
+ 4) + 'px';
71 this.button_
.style
.left
= (area
.x
+ 4) + 'px';
72 this.button_
.style
.zIndex
= 11;
73 var parent
= g
.graphDiv
;
74 parent
.insertBefore(this.button_
, parent
.firstChild
);
77 this.button_
.onclick
= function() {
81 g
.addEvent(parent
, 'mouseover', function() {
88 g
.addEvent(parent
, 'mouseout', function() {
94 unzoom
.prototype.show
= function(enabled
) {
95 this.button_
.style
.display
= enabled
? '' : 'none';
98 unzoom
.prototype.destroy
= function() {
99 this.button_
.parentElement
.removeChild(this.button_
);