UNPKG

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