1 | var __read = (this && this.__read) || function (o, n) {
|
2 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
3 | if (!m) return o;
|
4 | var i = m.call(o), r, ar = [], e;
|
5 | try {
|
6 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
7 | }
|
8 | catch (error) { e = { error: error }; }
|
9 | finally {
|
10 | try {
|
11 | if (r && !r.done && (m = i["return"])) m.call(i);
|
12 | }
|
13 | finally { if (e) throw e.error; }
|
14 | }
|
15 | return ar;
|
16 | };
|
17 | var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
18 | if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
19 | if (ar || !(i in from)) {
|
20 | if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
21 | ar[i] = from[i];
|
22 | }
|
23 | }
|
24 | return to.concat(ar || Array.prototype.slice.call(from));
|
25 | };
|
26 | var __values = (this && this.__values) || function(o) {
|
27 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
28 | if (m) return m.call(o);
|
29 | if (o && typeof o.length === "number") return {
|
30 | next: function () {
|
31 | if (o && i >= o.length) o = void 0;
|
32 | return { value: o && o[i++], done: !o };
|
33 | }
|
34 | };
|
35 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
36 | };
|
37 | import { deepMix, identity } from '@antv/util';
|
38 | import { mat3, vec3 } from 'gl-matrix';
|
39 | import { compose, isMatrix, extend } from './utils';
|
40 | import { cartesian, translate, custom, matrix, polar, transpose, scale, shearX, shearY, reflect, reflectX, reflectY, rotate, helix, parallel, fisheye, fisheyeX, fisheyeY, fisheyeCircular, } from './transforms';
|
41 | var Coordinate = (function () {
|
42 | |
43 |
|
44 |
|
45 |
|
46 | function Coordinate(options) {
|
47 |
|
48 | this.options = {
|
49 | x: 0,
|
50 | y: 0,
|
51 | width: 300,
|
52 | height: 150,
|
53 | transformations: [],
|
54 | };
|
55 |
|
56 | this.transformers = {
|
57 | cartesian: cartesian,
|
58 | translate: translate,
|
59 | custom: custom,
|
60 | matrix: matrix,
|
61 | polar: polar,
|
62 | transpose: transpose,
|
63 | scale: scale,
|
64 | 'shear.x': shearX,
|
65 | 'shear.y': shearY,
|
66 | reflect: reflect,
|
67 | 'reflect.x': reflectX,
|
68 | 'reflect.y': reflectY,
|
69 | rotate: rotate,
|
70 | helix: helix,
|
71 | parallel: parallel,
|
72 | fisheye: fisheye,
|
73 | 'fisheye.x': fisheyeX,
|
74 | 'fisheye.y': fisheyeY,
|
75 | 'fisheye.circular': fisheyeCircular,
|
76 | };
|
77 | this.update(options);
|
78 | }
|
79 | |
80 |
|
81 |
|
82 |
|
83 | Coordinate.prototype.update = function (options) {
|
84 | this.options = deepMix({}, this.options, options);
|
85 | this.recoordinate();
|
86 | };
|
87 | |
88 |
|
89 |
|
90 |
|
91 | Coordinate.prototype.clone = function () {
|
92 | return new Coordinate(this.options);
|
93 | };
|
94 | |
95 |
|
96 |
|
97 |
|
98 | Coordinate.prototype.getOptions = function () {
|
99 | return this.options;
|
100 | };
|
101 | |
102 |
|
103 |
|
104 | Coordinate.prototype.clear = function () {
|
105 | this.update({
|
106 | transformations: [],
|
107 | });
|
108 | };
|
109 | |
110 |
|
111 |
|
112 |
|
113 | Coordinate.prototype.getSize = function () {
|
114 | var _a = this.options, width = _a.width, height = _a.height;
|
115 | return [width, height];
|
116 | };
|
117 | |
118 |
|
119 |
|
120 |
|
121 | Coordinate.prototype.getCenter = function () {
|
122 | var _a = this.options, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
|
123 | return [(x * 2 + width) / 2, (y * 2 + height) / 2];
|
124 | };
|
125 | |
126 |
|
127 |
|
128 |
|
129 |
|
130 | Coordinate.prototype.transform = function () {
|
131 | var args = [];
|
132 | for (var _i = 0; _i < arguments.length; _i++) {
|
133 | args[_i] = arguments[_i];
|
134 | }
|
135 | var transformations = this.options.transformations;
|
136 | this.update({
|
137 | transformations: __spreadArray(__spreadArray([], __read(transformations), false), [__spreadArray([], __read(args), false)], false),
|
138 | });
|
139 | return this;
|
140 | };
|
141 | |
142 |
|
143 |
|
144 |
|
145 |
|
146 | Coordinate.prototype.map = function (vector) {
|
147 | return this.output(vector);
|
148 | };
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 | Coordinate.prototype.invert = function (vector) {
|
155 | return this.input(vector);
|
156 | };
|
157 | Coordinate.prototype.recoordinate = function () {
|
158 | this.output = this.compose();
|
159 | this.input = this.compose(true);
|
160 | };
|
161 |
|
162 |
|
163 |
|
164 | Coordinate.prototype.compose = function (invert) {
|
165 | var e_1, _a;
|
166 | if (invert === void 0) { invert = false; }
|
167 | var transformations = invert ? __spreadArray([], __read(this.options.transformations), false).reverse() : this.options.transformations;
|
168 | var getter = invert ? function (d) { return d.untransform; } : function (d) { return d.transform; };
|
169 | var matrixes = [];
|
170 | var transforms = [];
|
171 | var add = function (transform, extended) {
|
172 | if (extended === void 0) { extended = true; }
|
173 | return transforms.push(extended ? extend(transform) : transform);
|
174 | };
|
175 | try {
|
176 | for (var transformations_1 = __values(transformations), transformations_1_1 = transformations_1.next(); !transformations_1_1.done; transformations_1_1 = transformations_1.next()) {
|
177 | var _b = __read(transformations_1_1.value), name_1 = _b[0], args = _b.slice(1);
|
178 | var createTransformer = this.transformers[name_1];
|
179 | if (createTransformer) {
|
180 | var _c = this.options, x = _c.x, y = _c.y, width = _c.width, height = _c.height;
|
181 | var transformer = createTransformer(__spreadArray([], __read(args), false), x, y, width, height);
|
182 | if (isMatrix(transformer)) {
|
183 |
|
184 | matrixes.push(transformer);
|
185 | }
|
186 | else {
|
187 |
|
188 | if (matrixes.length) {
|
189 | var transform_1 = this.createMatrixTransform(matrixes, invert);
|
190 | add(transform_1);
|
191 | matrixes.splice(0, matrixes.length);
|
192 | }
|
193 | var transform = getter(transformer) || identity;
|
194 | add(transform, name_1 !== 'parallel');
|
195 | }
|
196 | }
|
197 | }
|
198 | }
|
199 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
200 | finally {
|
201 | try {
|
202 | if (transformations_1_1 && !transformations_1_1.done && (_a = transformations_1.return)) _a.call(transformations_1);
|
203 | }
|
204 | finally { if (e_1) throw e_1.error; }
|
205 | }
|
206 |
|
207 | if (matrixes.length) {
|
208 | var transform = this.createMatrixTransform(matrixes, invert);
|
209 | add(transform);
|
210 | }
|
211 | return compose.apply(void 0, __spreadArray([], __read(transforms), false));
|
212 | };
|
213 |
|
214 | Coordinate.prototype.createMatrixTransform = function (matrixes, invert) {
|
215 | var matrix = mat3.create();
|
216 | if (invert)
|
217 | matrixes.reverse();
|
218 | matrixes.forEach(function (m) { return mat3.mul(matrix, matrix, m); });
|
219 | if (invert) {
|
220 | mat3.invert(matrix, mat3.clone(matrix));
|
221 | }
|
222 | return function (vector) {
|
223 | var vector3 = [vector[0], vector[1], 1];
|
224 | vec3.transformMat3(vector3, vector3, matrix);
|
225 | return [vector3[0], vector3[1]];
|
226 | };
|
227 | };
|
228 | return Coordinate;
|
229 | }());
|
230 | export { Coordinate };
|
231 |
|
\ | No newline at end of file |