802c31b57cd88a81c93ed4d0e8037c95b5fd5b08
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
21 /*global Dygraph:false */
24 * @fileoverview Plug-in for providing unzoom-on-hover.
26 * @author konigsberg@google.com (Robert Konigsberg)
28 Dygraph
.Plugins
.Unzoom
= (function() {
33 * Create a new instance.
37 var unzoom
= function() {
40 // True when the mouse is over the canvas. Must be tracked
41 // because the unzoom button state can change even when the
42 // mouse-over state hasn't.
46 unzoom
.prototype.toString
= function() {
47 return 'Unzoom Plugin';
50 unzoom
.prototype.activate
= function(g
) {
52 willDrawChart
: this.willDrawChart
56 unzoom
.prototype.willDrawChart
= function(e
) {
59 if (this.button_
!== null) {
60 // short-circuit: show the button only when we're moused over, and zoomed in.
61 var showButton
= g
.isZoomed() && this.over_
;
62 this.show(showButton
);
66 this.button_
= document
.createElement('button');
67 this.button_
.innerHTML
= 'Reset Zoom';
68 this.button_
.style
.display
= 'none';
69 this.button_
.style
.position
= 'absolute';
70 var area
= g
.plotter_
.area
;
71 this.button_
.style
.top
= (area
.y
+ 4) + 'px';
72 this.button_
.style
.left
= (area
.x
+ 4) + 'px';
73 this.button_
.style
.zIndex
= 11;
74 var parent
= g
.graphDiv
;
75 parent
.insertBefore(this.button_
, parent
.firstChild
);
78 this.button_
.onclick
= function() {
82 g
.addEvent(parent
, 'mouseover', function() {
89 g
.addEvent(parent
, 'mouseout', function() {
95 unzoom
.prototype.show
= function(enabled
) {
96 this.button_
.style
.display
= enabled
? '' : 'none';
99 unzoom
.prototype.destroy
= function() {
100 this.button_
.parentElement
.removeChild(this.button_
);