1 | import { Event as GEvent, IShape } from '../dependents';
|
2 | import { Datum } from '../interface';
|
3 | import View from './view';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export default class Event {
|
10 |
|
11 | public view: View;
|
12 |
|
13 | public gEvent: GEvent;
|
14 |
|
15 | public data?: Datum;
|
16 |
|
17 | public type: string;
|
18 |
|
19 | constructor(view: View, gEvent: GEvent, data?: Datum) {
|
20 | this.view = view;
|
21 | this.gEvent = gEvent;
|
22 | this.data = data;
|
23 | this.type = gEvent.type;
|
24 | }
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | public static fromData(view: View, type: string, data: Datum) {
|
33 | return new Event(view, new GEvent(type, {}), data);
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | public get target(): IShape {
|
40 |
|
41 |
|
42 | return this.gEvent.target;
|
43 | }
|
44 |
|
45 |
|
46 | public get event(): any {
|
47 | return this.gEvent.originalEvent;
|
48 | }
|
49 |
|
50 |
|
51 | public get x(): number {
|
52 | return this.gEvent.x;
|
53 | }
|
54 |
|
55 |
|
56 | public get y(): number {
|
57 | return this.gEvent.y;
|
58 | }
|
59 |
|
60 |
|
61 | public get clientX(): number {
|
62 | return this.gEvent.clientX;
|
63 | }
|
64 |
|
65 |
|
66 | public get clientY(): number {
|
67 | return this.gEvent.clientY;
|
68 | }
|
69 |
|
70 |
|
71 | |
72 |
|
73 |
|
74 |
|
75 | public toString(): string {
|
76 | return `[Event (type=${this.type})]`;
|
77 | }
|
78 |
|
79 | |
80 |
|
81 |
|
82 |
|
83 | public clone(): Event {
|
84 | return new Event(this.view, this.gEvent, this.data);
|
85 | }
|
86 | }
|