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 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,
|
43 | end: end }, cfg);
|
44 |
|
45 | var C = dependents_1.getCoordinate(isTheta ? 'polar' : type);
|
46 | this.coordinate = new C(props);
|
47 |
|
48 | this.coordinate.type = type;
|
49 |
|
50 | if (isTheta) {
|
51 |
|
52 | if (!this.hasAction('transpose')) {
|
53 | this.transpose();
|
54 | }
|
55 | }
|
56 |
|
57 | this.execActions();
|
58 | return this.coordinate;
|
59 | };
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | CoordinateController.prototype.adjust = function (start, end) {
|
67 | this.coordinate.update({
|
68 | start: start,
|
69 | end: end,
|
70 | });
|
71 |
|
72 |
|
73 |
|
74 | this.coordinate.resetMatrix();
|
75 | this.execActions(['scale', 'rotate', 'translate']);
|
76 | return this.coordinate;
|
77 | };
|
78 | |
79 |
|
80 |
|
81 |
|
82 | CoordinateController.prototype.rotate = function (angle) {
|
83 | this.option.actions.push(['rotate', angle]);
|
84 | return this;
|
85 | };
|
86 | |
87 |
|
88 |
|
89 |
|
90 | CoordinateController.prototype.reflect = function (dim) {
|
91 | this.option.actions.push(['reflect', dim]);
|
92 | return this;
|
93 | };
|
94 | |
95 |
|
96 |
|
97 |
|
98 |
|
99 | CoordinateController.prototype.scale = function (sx, sy) {
|
100 | this.option.actions.push(['scale', sx, sy]);
|
101 | return this;
|
102 | };
|
103 | |
104 |
|
105 |
|
106 | CoordinateController.prototype.transpose = function () {
|
107 | this.option.actions.push(['transpose']);
|
108 | return this;
|
109 | };
|
110 | |
111 |
|
112 |
|
113 | CoordinateController.prototype.getOption = function () {
|
114 | return this.option;
|
115 | };
|
116 | |
117 |
|
118 |
|
119 | CoordinateController.prototype.getCoordinate = function () {
|
120 | return this.coordinate;
|
121 | };
|
122 | |
123 |
|
124 |
|
125 |
|
126 | CoordinateController.prototype.wrapperOption = function (option) {
|
127 | return tslib_1.__assign({ type: 'rect', actions: [], cfg: {} }, option);
|
128 | };
|
129 | |
130 |
|
131 |
|
132 |
|
133 | CoordinateController.prototype.execActions = function (includeActions) {
|
134 | var _this = this;
|
135 | var actions = this.option.actions;
|
136 | util_1.each(actions, function (action) {
|
137 | var _a;
|
138 | var actionName = action[0], args = action.slice(1);
|
139 | var shouldExec = util_1.isNil(includeActions) ? true : includeActions.includes(actionName);
|
140 | if (shouldExec) {
|
141 | (_a = _this.coordinate)[actionName].apply(_a, args);
|
142 | }
|
143 | });
|
144 | };
|
145 | return CoordinateController;
|
146 | }());
|
147 | exports.default = CoordinateController;
|
148 |
|
\ | No newline at end of file |