1 // Copyright (c) 2011 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 Utility functions for Dygraphs.
25 * @author konigsberg@google.com (Robert Konigsberg)
29 DygraphOps
.defaultEvent_
= {
33 view
: document
.defaultView
,
47 DygraphOps
.createEvent_
= function(command
, custom
) {
49 var copy
= function(from
, to
) {
51 for (var prop
in from
) {
52 if(from
.hasOwnProperty(prop
)) {
53 to
[prop
] = from
[prop
];
60 copy(DygraphOps
.defaultEvent_
, e
);
64 var event
= document
.createEvent('MouseEvents');
84 DygraphOps
.dispatchDoubleClick
= function(g
, custom
) {
89 var event
= DygraphOps
.createEvent_(opts
, custom
);
90 g
.canvas_
.dispatchEvent(event
);
93 DygraphOps
.dispatchMouseDown_Point
= function(g
, x
, y
, custom
) {
94 var pageX
= Dygraph
.findPosX(g
.canvas_
) + x
;
95 var pageY
= Dygraph
.findPosY(g
.canvas_
) + y
;
106 var event
= DygraphOps
.createEvent_(opts
, custom
);
107 g
.canvas_
.dispatchEvent(event
);
110 DygraphOps
.dispatchMouseMove_Point
= function(g
, x
, y
, custom
) {
111 var pageX
= Dygraph
.findPosX(g
.canvas_
) + x
;
112 var pageY
= Dygraph
.findPosY(g
.canvas_
) + y
;
122 var event
= DygraphOps
.createEvent_(opts
, custom
);
123 g
.canvas_
.dispatchEvent(event
);
126 DygraphOps
.dispatchMouseUp_Point
= function(g
, x
, y
, custom
) {
127 var pageX
= Dygraph
.findPosX(g
.canvas_
) + x
;
128 var pageY
= Dygraph
.findPosY(g
.canvas_
) + y
;
138 var event
= DygraphOps
.createEvent_(opts
, custom
);
139 g
.canvas_
.dispatchEvent(event
);
142 DygraphOps
.dispatchMouseDown
= function(g
, x
, y
, custom
) {
143 DygraphOps
.dispatchMouseDown_Point(
150 DygraphOps
.dispatchMouseMove
= function(g
, x
, y
, custom
) {
151 DygraphOps
.dispatchMouseMove_Point(
158 DygraphOps
.dispatchMouseUp
= function(g
, x
, y
, custom
) {
159 DygraphOps
.dispatchMouseUp_Point(