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
21 import * as utils from
'../../src/dygraph-utils';
24 * @fileoverview Utility functions for Dygraphs.
26 * @author konigsberg@google.com (Robert Konigsberg)
30 DygraphOps
.defaultEvent_
= {
34 view
: document
.defaultView
,
49 * Create an event. Sets default event values except for special ones
50 * overridden by the 'custom' parameter.
52 * @param command the command to create.
53 * @param custom an associative array of event attributes and their new values.
55 DygraphOps
.createEvent
= function(command
, custom
) {
57 var copy
= function(from
, to
) {
59 for (var prop
in from
) {
60 if(from
.hasOwnProperty(prop
)) {
61 to
[prop
] = from
[prop
];
68 copy(DygraphOps
.defaultEvent_
, e
);
72 var event
= document
.createEvent('MouseEvents');
93 * Dispatch an event onto the graph's canvas.
95 DygraphOps
.dispatchCanvasEvent
= function(g
, event
) {
96 g
.canvas_
.dispatchEvent(event
);
99 DygraphOps
.dispatchDoubleClick
= function(g
, custom
) {
104 var event
= DygraphOps
.createEvent(opts
, custom
);
105 DygraphOps
.dispatchCanvasEvent(g
, event
);
109 * Create an 'opts' argument which can be passed to createEvent that contains
110 * type, screenX, screenY, clientX, clientY.
112 DygraphOps
.createOptsForPoint_
= function(g
, type
, x
, y
) {
113 var pos
= utils
.findPos(g
.canvas_
);
114 var pageX
= pos
.x
+ x
;
115 var pageY
= pos
.y
+ y
;
126 DygraphOps
.dispatchMouseDown_Point
= function(g
, x
, y
, custom
) {
127 var opts
= DygraphOps
.createOptsForPoint_(g
, 'mousedown', x
, y
);
129 var event
= DygraphOps
.createEvent(opts
, custom
);
130 DygraphOps
.dispatchCanvasEvent(g
, event
);
133 DygraphOps
.dispatchMouseMove_Point
= function(g
, x
, y
, custom
) {
134 var opts
= DygraphOps
.createOptsForPoint_(g
, 'mousemove', x
, y
);
135 var event
= DygraphOps
.createEvent(opts
, custom
);
136 DygraphOps
.dispatchCanvasEvent(g
, event
);
139 DygraphOps
.dispatchMouseUp_Point
= function(g
, x
, y
, custom
) {
140 var opts
= DygraphOps
.createOptsForPoint_(g
, 'mouseup', x
, y
);
141 var event
= DygraphOps
.createEvent(opts
, custom
);
142 DygraphOps
.dispatchCanvasEvent(g
, event
);
145 DygraphOps
.dispatchMouseOver_Point
= function(g
, x
, y
, custom
) {
146 var opts
= DygraphOps
.createOptsForPoint_(g
, 'mouseover', x
, y
);
147 var event
= DygraphOps
.createEvent(opts
, custom
);
148 DygraphOps
.dispatchCanvasEvent(g
, event
);
151 DygraphOps
.dispatchMouseOut_Point
= function(g
, x
, y
, custom
) {
152 var opts
= DygraphOps
.createOptsForPoint_(g
, 'mouseout', x
, y
);
153 var event
= DygraphOps
.createEvent(opts
, custom
);
154 DygraphOps
.dispatchCanvasEvent(g
, event
);
158 * Dispatches a mouse down using the graph's data coordinate system.
159 * (The y value mapped to the first axis.)
161 DygraphOps
.dispatchMouseDown
= function(g
, x
, y
, custom
) {
162 DygraphOps
.dispatchMouseDown_Point(
170 * Dispatches a mouse move using the graph's data coordinate system.
171 * (The y value mapped to the first axis.)
173 DygraphOps
.dispatchMouseMove
= function(g
, x
, y
, custom
) {
174 DygraphOps
.dispatchMouseMove_Point(
182 * Dispatches a mouse up using the graph's data coordinate system.
183 * (The y value mapped to the first axis.)
185 DygraphOps
.dispatchMouseUp
= function(g
, x
, y
, custom
) {
186 DygraphOps
.dispatchMouseUp_Point(
194 * Dispatches a mouse over using the graph's data coordinate system.
195 * (The y value mapped to the first axis.)
197 DygraphOps
.dispatchMouseOver
= function(g
, x
, y
, custom
) {
198 DygraphOps
.dispatchMouseOver_Point(
206 * Dispatches a mouse out using the graph's data coordinate system.
207 * (The y value mapped to the first axis.)
209 DygraphOps
.dispatchMouseOut
= function(g
, x
, y
, custom
) {
210 DygraphOps
.dispatchMouseOut_Point(
218 export default DygraphOps
;