1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var util_1 = require("@antv/util");
|
5 | var dependents_1 = require("../../dependents");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | var CoordinateController = (function () {
|
12 | function CoordinateController(option) {
|
13 |
|
14 | this.option = this.wrapperOption(option);
|
15 | }
|
16 | |
17 |
|
18 |
|
19 |
|
20 | CoordinateController.prototype.update = function (option) {
|
21 | this.option = this.wrapperOption(option);
|
22 | return this;
|
23 | };
|
24 | |
25 |
|
26 |
|
27 |
|
28 | CoordinateController.prototype.hasAction = function (actionName) {
|
29 | var actions = this.option.actions;
|
30 | return (0, util_1.some)(actions, function (action) { return action[0] === actionName; });
|
31 | };
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | CoordinateController.prototype.create = function (start, end) {
|
39 | var _a = this.option, type = _a.type, cfg = _a.cfg;
|
40 | var isTheta = type === 'theta';
|
41 |
|
42 | var props = tslib_1.__assign({ start: start, end: end }, cfg);
|
43 |
|
44 | var C = (0, dependents_1.getCoordinate)(isTheta ? 'polar' : type);
|
45 | this.coordinate = new C(props);
|
46 |
|
47 | this.coordinate.type = type;
|
48 |
|
49 | if (isTheta) {
|
50 |
|
51 | if (!this.hasAction('transpose')) {
|
52 | this.transpose();
|
53 | }
|
54 | }
|
55 |
|
56 | this.execActions();
|
57 | return this.coordinate;
|
58 | };
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | CoordinateController.prototype.adjust = function (start, end) {
|
66 | this.coordinate.update({
|
67 | start: start,
|
68 | end: end,
|
69 | });
|
70 |
|
71 |
|
72 |
|
73 | this.coordinate.resetMatrix();
|
74 | this.execActions(['scale', 'rotate', 'translate']);
|
75 | return this.coordinate;
|
76 | };
|
77 | |
78 |
|
79 |
|
80 |
|
81 | CoordinateController.prototype.rotate = function (angle) {
|
82 | this.option.actions.push(['rotate', angle]);
|
83 | return this;
|
84 | };
|
85 | |
86 |
|
87 |
|
88 |
|
89 | CoordinateController.prototype.reflect = function (dim) {
|
90 | this.option.actions.push(['reflect', dim]);
|
91 | return this;
|
92 | };
|
93 | |
94 |
|
95 |
|
96 |
|
97 |
|
98 | CoordinateController.prototype.scale = function (sx, sy) {
|
99 | this.option.actions.push(['scale', sx, sy]);
|
100 | return this;
|
101 | };
|
102 | |
103 |
|
104 |
|
105 | CoordinateController.prototype.transpose = function () {
|
106 | this.option.actions.push(['transpose']);
|
107 | return this;
|
108 | };
|
109 | |
110 |
|
111 |
|
112 | CoordinateController.prototype.getOption = function () {
|
113 | return this.option;
|
114 | };
|
115 | |
116 |
|
117 |
|
118 | CoordinateController.prototype.getCoordinate = function () {
|
119 | return this.coordinate;
|
120 | };
|
121 | |
122 |
|
123 |
|
124 |
|
125 | CoordinateController.prototype.wrapperOption = function (option) {
|
126 | return tslib_1.__assign({ type: 'rect', actions: [], cfg: {} }, option);
|
127 | };
|
128 | |
129 |
|
130 |
|
131 |
|
132 | CoordinateController.prototype.execActions = function (includeActions) {
|
133 | var _this = this;
|
134 | var actions = this.option.actions;
|
135 | (0, util_1.each)(actions, function (action) {
|
136 | var _a;
|
137 | var _b = tslib_1.__read(action), actionName = _b[0], args = _b.slice(1);
|
138 | var shouldExec = (0, util_1.isNil)(includeActions) ? true : includeActions.includes(actionName);
|
139 | if (shouldExec) {
|
140 | (_a = _this.coordinate)[actionName].apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false));
|
141 | }
|
142 | });
|
143 | };
|
144 | return CoordinateController;
|
145 | }());
|
146 | exports.default = CoordinateController;
|
147 |
|
\ | No newline at end of file |