072d99294f9848fafd8d2501ad1bd4683331fd89
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
= function(g
, x
, y
, custom
) {
94 var px
= Dygraph
.findPosX(g
.canvas_
);
95 var py
= Dygraph
.findPosY(g
.canvas_
);
97 var pageX
= px
+ g
.toDomXCoord(x
);
98 var pageY
= py
+ g
.toDomYCoord(y
);
109 var event
= DygraphOps
.createEvent_(opts
, custom
);
110 g
.canvas_
.dispatchEvent(event
);
113 DygraphOps
.dispatchMouseMove
= function(g
, x
, y
, custom
) {
114 var px
= Dygraph
.findPosX(g
.canvas_
);
115 var py
= Dygraph
.findPosY(g
.canvas_
);
117 var pageX
= px
+ g
.toDomXCoord(x
);
118 var pageY
= py
+ g
.toDomYCoord(y
);
128 var event
= DygraphOps
.createEvent_(opts
, custom
);
129 g
.canvas_
.dispatchEvent(event
);
132 DygraphOps
.dispatchMouseUp
= function(g
, x
, y
, custom
) {
133 var px
= Dygraph
.findPosX(g
.canvas_
);
134 var py
= Dygraph
.findPosY(g
.canvas_
);
136 var pageX
= px
+ g
.toDomXCoord(x
);
137 var pageY
= py
+ g
.toDomYCoord(y
);
147 var event
= DygraphOps
.createEvent_(opts
, custom
);
148 g
.canvas_
.dispatchEvent(event
);