UNPKG

2.67 kBJavaScriptView Raw
1import { Event as GEvent } from '../dependents';
2/**
3 * @todo Whether it can(or necessary to) keep consistent with the structure of G.Event or directly use the structure of G.Event
4 * G2 事件的事件包装类,基于 G.Event
5 */
6var Event = /** @class */ (function () {
7 function Event(view, gEvent, data) {
8 this.view = view;
9 this.gEvent = gEvent;
10 this.data = data;
11 this.type = gEvent.type;
12 }
13 /**
14 * 非交互产生的事件
15 * @param view
16 * @param type
17 * @param data
18 */
19 Event.fromData = function (view, type, data) {
20 return new Event(view, new GEvent(type, {}), data);
21 };
22 Object.defineProperty(Event.prototype, "target", {
23 // below props are proxy props of G.event convenient
24 /** the real trigger shape of the event */
25 get: function () {
26 // @todo G 中事件定义为 object 不正确,这里先 ignore
27 // @ts-ignore
28 return this.gEvent.target;
29 },
30 enumerable: false,
31 configurable: true
32 });
33 Object.defineProperty(Event.prototype, "event", {
34 /** 获取对应的 dom 原生时间 */
35 get: function () {
36 return this.gEvent.originalEvent;
37 },
38 enumerable: false,
39 configurable: true
40 });
41 Object.defineProperty(Event.prototype, "x", {
42 /** x 画布坐标 */
43 get: function () {
44 return this.gEvent.x;
45 },
46 enumerable: false,
47 configurable: true
48 });
49 Object.defineProperty(Event.prototype, "y", {
50 /** y 画布坐标 */
51 get: function () {
52 return this.gEvent.y;
53 },
54 enumerable: false,
55 configurable: true
56 });
57 Object.defineProperty(Event.prototype, "clientX", {
58 /** x 窗口坐标 */
59 get: function () {
60 return this.gEvent.clientX;
61 },
62 enumerable: false,
63 configurable: true
64 });
65 Object.defineProperty(Event.prototype, "clientY", {
66 /** y 窗口坐标 */
67 get: function () {
68 return this.gEvent.clientY;
69 },
70 enumerable: false,
71 configurable: true
72 });
73 // end for proxy events
74 /**
75 * event string
76 * @returns string
77 */
78 Event.prototype.toString = function () {
79 return "[Event (type=".concat(this.type, ")]");
80 };
81 /**
82 * clone a new event with same attributes
83 * @returns [[Event]]
84 */
85 Event.prototype.clone = function () {
86 return new Event(this.view, this.gEvent, this.data);
87 };
88 return Event;
89}());
90export default Event;
91//# sourceMappingURL=event.js.map
\No newline at end of file