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
,
48 * Create an event. Sets default event values except for special ones
49 * overridden by the 'custom' parameter.
51 * @param command the command to create.
52 * @param custom an associative array of event attributes and their new values.
54 DygraphOps
.createEvent
= function(command
, custom
) {
56 var copy
= function(from
, to
) {
58 for (var prop
in from
) {
59 if(from
.hasOwnProperty(prop
)) {
60 to
[prop
] = from
[prop
];
67 copy(DygraphOps
.defaultEvent_
, e
);
71 var event
= document
.createEvent('MouseEvents');
92 * Dispatch an event onto the graph's canvas.
94 DygraphOps
.dispatchCanvasEvent
= function(g
, event
) {
95 g
.canvas_
.dispatchEvent(event
);
98 DygraphOps
.dispatchDoubleClick
= function(g
, custom
) {
103 var event
= DygraphOps
.createEvent(opts
, custom
);
104 DygraphOps
.dispatchCanvasEvent(g
, event
);
107 DygraphOps
.dispatchMouseDown_Point
= function(g
, x
, y
, custom
) {
108 var pageX
= Dygraph
.findPosX(g
.canvas_
) + x
;
109 var pageY
= Dygraph
.findPosY(g
.canvas_
) + y
;
120 var event
= DygraphOps
.createEvent(opts
, custom
);
121 DygraphOps
.dispatchCanvasEvent(g
, event
);
124 DygraphOps
.dispatchMouseMove_Point
= function(g
, x
, y
, custom
) {
125 var pageX
= Dygraph
.findPosX(g
.canvas_
) + x
;
126 var pageY
= Dygraph
.findPosY(g
.canvas_
) + y
;
136 var event
= DygraphOps
.createEvent(opts
, custom
);
137 DygraphOps
.dispatchCanvasEvent(g
, event
);
140 DygraphOps
.dispatchMouseUp_Point
= function(g
, x
, y
, custom
) {
141 var pageX
= Dygraph
.findPosX(g
.canvas_
) + x
;
142 var pageY
= Dygraph
.findPosY(g
.canvas_
) + y
;
152 var event
= DygraphOps
.createEvent(opts
, custom
);
153 DygraphOps
.dispatchCanvasEvent(g
, event
);
157 * Dispatches a mouse down using the graph's data coordinate system.
158 * (The y value mapped to the first axis.)
160 DygraphOps
.dispatchMouseDown
= function(g
, x
, y
, custom
) {
161 DygraphOps
.dispatchMouseDown_Point(
169 * Dispatches a mouse move using the graph's data coordinate system.
170 * (The y value mapped to the first axis.)
172 DygraphOps
.dispatchMouseMove
= function(g
, x
, y
, custom
) {
173 DygraphOps
.dispatchMouseMove_Point(
181 * Dispatches a mouse up using the graph's data coordinate system.
182 * (The y value mapped to the first axis.)
184 DygraphOps
.dispatchMouseUp
= function(g
, x
, y
, custom
) {
185 DygraphOps
.dispatchMouseUp_Point(