1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var util_1 = require("@antv/util");
|
4 | var util_2 = require("./action/util");
|
5 |
|
6 |
|
7 |
|
8 | var Context = (function () {
|
9 | function Context(view) {
|
10 |
|
11 | this.actions = [];
|
12 |
|
13 | this.event = null;
|
14 | this.cacheMap = {};
|
15 | this.view = view;
|
16 | }
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | Context.prototype.cache = function () {
|
24 | var params = [];
|
25 | for (var _i = 0; _i < arguments.length; _i++) {
|
26 | params[_i] = arguments[_i];
|
27 | }
|
28 | if (params.length === 1) {
|
29 | return this.cacheMap[params[0]];
|
30 | }
|
31 | else if (params.length === 2) {
|
32 | this.cacheMap[params[0]] = params[1];
|
33 | }
|
34 | };
|
35 | |
36 |
|
37 |
|
38 |
|
39 | Context.prototype.getAction = function (name) {
|
40 | return this.actions.find(function (action) { return action.name === name; });
|
41 | };
|
42 | |
43 |
|
44 |
|
45 |
|
46 | Context.prototype.addAction = function (action) {
|
47 | this.actions.push(action);
|
48 | };
|
49 | |
50 |
|
51 |
|
52 |
|
53 | Context.prototype.removeAction = function (action) {
|
54 | var actions = this.actions;
|
55 | var index = this.actions.indexOf(action);
|
56 | if (index >= 0) {
|
57 | actions.splice(index, 1);
|
58 | }
|
59 | };
|
60 | |
61 |
|
62 |
|
63 | Context.prototype.getCurrentPoint = function () {
|
64 | var event = this.event;
|
65 | if (event) {
|
66 | if (event.target instanceof HTMLElement) {
|
67 | var canvas = this.view.getCanvas();
|
68 | var point = canvas.getPointByClient(event.clientX, event.clientY);
|
69 | return point;
|
70 | }
|
71 | else {
|
72 | return {
|
73 | x: event.x,
|
74 | y: event.y,
|
75 | };
|
76 | }
|
77 | }
|
78 | return null;
|
79 | };
|
80 | |
81 |
|
82 |
|
83 |
|
84 | Context.prototype.getCurrentShape = function () {
|
85 | return (0, util_1.get)(this.event, ['gEvent', 'shape']);
|
86 | };
|
87 | |
88 |
|
89 |
|
90 | Context.prototype.isInPlot = function () {
|
91 | var point = this.getCurrentPoint();
|
92 | if (point) {
|
93 | return this.view.isPointInPlot(point);
|
94 | }
|
95 | return false;
|
96 | };
|
97 | |
98 |
|
99 |
|
100 |
|
101 | Context.prototype.isInShape = function (name) {
|
102 | var shape = this.getCurrentShape();
|
103 | if (shape) {
|
104 | return shape.get('name') === name;
|
105 | }
|
106 | return false;
|
107 | };
|
108 | |
109 |
|
110 |
|
111 |
|
112 | Context.prototype.isInComponent = function (name) {
|
113 | var components = (0, util_2.getComponents)(this.view);
|
114 | var point = this.getCurrentPoint();
|
115 | if (point) {
|
116 | return !!components.find(function (component) {
|
117 | var bbox = component.getBBox();
|
118 | if (name) {
|
119 | return component.get('name') === name && (0, util_2.isInBox)(bbox, point);
|
120 | }
|
121 | else {
|
122 | return (0, util_2.isInBox)(bbox, point);
|
123 | }
|
124 | });
|
125 | }
|
126 | return false;
|
127 | };
|
128 | |
129 |
|
130 |
|
131 | Context.prototype.destroy = function () {
|
132 |
|
133 | (0, util_1.each)(this.actions.slice(), function (action) {
|
134 | action.destroy();
|
135 | });
|
136 | this.view = null;
|
137 | this.event = null;
|
138 | this.actions = null;
|
139 | this.cacheMap = null;
|
140 | };
|
141 | return Context;
|
142 | }());
|
143 | exports.default = Context;
|
144 |
|
\ | No newline at end of file |