3bd3c4417ea5a1a86e80f49c429da6e41950af85
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
.dispatchDoubleClick
= function(g
, func
) {
30 var evt
= document
.createEvent('MouseEvents');
33 true, true, document
.defaultView
,
35 false, false, false, false, 0, null);
39 g
.canvas_
.dispatchEvent(evt
);
42 DygraphOps
.dispatchMouseDown
= function(g
, x
, y
, func
) {
43 var px
= Dygraph
.findPosX(g
.canvas_
);
44 var py
= Dygraph
.findPosY(g
.canvas_
);
46 var pageX
= px
+ g
.toDomXCoord(x
);
47 var pageY
= py
+ g
.toDomYCoord(y
);
49 var evt
= document
.createEvent('MouseEvents');
52 true, true, document
.defaultView
,
53 1, pageX
, pageY
, pageX
, pageY
,
54 false, false, false, false, 0, null);
58 g
.canvas_
.dispatchEvent(evt
);
61 DygraphOps
.dispatchMouseMove
= function(g
, x
, y
, func
) {
62 var px
= Dygraph
.findPosX(g
.canvas_
);
63 var py
= Dygraph
.findPosY(g
.canvas_
);
65 var pageX
= px
+ g
.toDomXCoord(x
);
66 var pageY
= py
+ g
.toDomYCoord(y
);
68 var evt
= document
.createEvent('MouseEvents');
71 true, true, document
.defaultView
,
72 0, pageX
, pageY
, pageX
, pageY
,
73 false, false, false, false, 0, null);
77 g
.canvas_
.dispatchEvent(evt
);
80 DygraphOps
.dispatchMouseUp
= function(g
, x
, y
, func
) {
81 var px
= Dygraph
.findPosX(g
.canvas_
);
82 var py
= Dygraph
.findPosY(g
.canvas_
);
84 var pageX
= px
+ g
.toDomXCoord(x
);
85 var pageY
= py
+ g
.toDomYCoord(y
);
87 var evt
= document
.createEvent('MouseEvents');
90 true, true, document
.defaultView
,
91 0, pageX
, pageY
, pageX
, pageY
,
92 false, false, false, false, 0, null);
96 g
.canvas_
.dispatchEvent(evt
);