1 | "use strict";
|
2 | var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
3 | for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
4 | to[j] = from[i];
|
5 | return to;
|
6 | };
|
7 | Object.defineProperty(exports, "__esModule", { value: true });
|
8 | exports.Coordinate = void 0;
|
9 | var util_1 = require("@antv/util");
|
10 | var matrix_util_1 = require("@antv/matrix-util");
|
11 | var utils_1 = require("./utils");
|
12 | var transforms_1 = require("./transforms");
|
13 | var Coordinate = (function () {
|
14 | |
15 |
|
16 |
|
17 |
|
18 | function Coordinate(options) {
|
19 |
|
20 | this.options = {
|
21 | x: 0,
|
22 | y: 0,
|
23 | width: 300,
|
24 | height: 150,
|
25 | transformations: [],
|
26 | };
|
27 |
|
28 | this.transformers = {
|
29 | cartesian: transforms_1.cartesian,
|
30 | translate: transforms_1.translate,
|
31 | custom: transforms_1.custom,
|
32 | matrix: transforms_1.matrix,
|
33 | polar: transforms_1.polar,
|
34 | transpose: transforms_1.transpose,
|
35 | scale: transforms_1.scale,
|
36 | 'shear.x': transforms_1.shearX,
|
37 | 'shear.y': transforms_1.shearY,
|
38 | reflect: transforms_1.reflect,
|
39 | 'reflect.x': transforms_1.reflectX,
|
40 | 'reflect.y': transforms_1.reflectY,
|
41 | rotate: transforms_1.rotate,
|
42 | helix: transforms_1.helix,
|
43 | parallel: transforms_1.parallel,
|
44 | fisheye: transforms_1.fisheye,
|
45 | 'fisheye.x': transforms_1.fisheyeX,
|
46 | 'fisheye.y': transforms_1.fisheyeY,
|
47 | 'fisheye.circular': transforms_1.fisheyeCircular,
|
48 | };
|
49 | this.update(options);
|
50 | }
|
51 | |
52 |
|
53 |
|
54 |
|
55 | Coordinate.prototype.update = function (options) {
|
56 | this.options = util_1.deepMix({}, this.options, options);
|
57 | this.recoordinate();
|
58 | };
|
59 | |
60 |
|
61 |
|
62 |
|
63 | Coordinate.prototype.clone = function () {
|
64 | return new Coordinate(this.options);
|
65 | };
|
66 | |
67 |
|
68 |
|
69 |
|
70 | Coordinate.prototype.getOptions = function () {
|
71 | return this.options;
|
72 | };
|
73 | |
74 |
|
75 |
|
76 | Coordinate.prototype.clear = function () {
|
77 | this.update({
|
78 | transformations: [],
|
79 | });
|
80 | };
|
81 | |
82 |
|
83 |
|
84 |
|
85 | Coordinate.prototype.getSize = function () {
|
86 | var _a = this.options, width = _a.width, height = _a.height;
|
87 | return [width, height];
|
88 | };
|
89 | |
90 |
|
91 |
|
92 |
|
93 | Coordinate.prototype.getCenter = function () {
|
94 | var _a = this.options, x = _a.x, y = _a.y, width = _a.width, height = _a.height;
|
95 | return [(x + width) / 2, (y + height) / 2];
|
96 | };
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 | Coordinate.prototype.transform = function () {
|
103 | var args = [];
|
104 | for (var _i = 0; _i < arguments.length; _i++) {
|
105 | args[_i] = arguments[_i];
|
106 | }
|
107 | var transformations = this.options.transformations;
|
108 | this.update({
|
109 | transformations: __spreadArray(__spreadArray([], transformations), [__spreadArray([], args)]),
|
110 | });
|
111 | return this;
|
112 | };
|
113 | |
114 |
|
115 |
|
116 |
|
117 |
|
118 | Coordinate.prototype.map = function (vector) {
|
119 | return this.output(vector);
|
120 | };
|
121 | |
122 |
|
123 |
|
124 |
|
125 |
|
126 | Coordinate.prototype.invert = function (vector) {
|
127 | return this.input(vector);
|
128 | };
|
129 | Coordinate.prototype.recoordinate = function () {
|
130 | this.output = this.compose();
|
131 | this.input = this.compose(true);
|
132 | };
|
133 |
|
134 |
|
135 |
|
136 | Coordinate.prototype.compose = function (invert) {
|
137 | if (invert === void 0) { invert = false; }
|
138 | var transformations = invert ? __spreadArray([], this.options.transformations).reverse() : this.options.transformations;
|
139 | var getter = invert ? function (d) { return d.untransform; } : function (d) { return d.transform; };
|
140 | var matrixes = [];
|
141 | var transforms = [];
|
142 | var add = function (transform, extended) {
|
143 | if (extended === void 0) { extended = true; }
|
144 | return transforms.push(extended ? utils_1.extend(transform) : transform);
|
145 | };
|
146 | for (var _i = 0, transformations_1 = transformations; _i < transformations_1.length; _i++) {
|
147 | var _a = transformations_1[_i], name_1 = _a[0], args = _a.slice(1);
|
148 | var createTransformer = this.transformers[name_1];
|
149 | if (createTransformer) {
|
150 | var _b = this.options, x = _b.x, y = _b.y, width = _b.width, height = _b.height;
|
151 | var transformer = createTransformer(__spreadArray([], args), x, y, width, height);
|
152 | if (utils_1.isMatrix(transformer)) {
|
153 |
|
154 | matrixes.push(transformer);
|
155 | }
|
156 | else {
|
157 |
|
158 | if (matrixes.length) {
|
159 | var transform_1 = this.createMatrixTransform(matrixes, invert);
|
160 | add(transform_1);
|
161 | matrixes.splice(0, matrixes.length);
|
162 | }
|
163 | var transform = getter(transformer) || util_1.identity;
|
164 | add(transform, name_1 !== 'parallel');
|
165 | }
|
166 | }
|
167 | }
|
168 |
|
169 | if (matrixes.length) {
|
170 | var transform = this.createMatrixTransform(matrixes, invert);
|
171 | add(transform);
|
172 | }
|
173 | return utils_1.compose.apply(void 0, transforms);
|
174 | };
|
175 |
|
176 | Coordinate.prototype.createMatrixTransform = function (matrixes, invert) {
|
177 | var matrix = matrix_util_1.mat3.create();
|
178 | if (invert)
|
179 | matrixes.reverse();
|
180 | matrixes.forEach(function (m) { return matrix_util_1.mat3.mul(matrix, matrix, m); });
|
181 | if (invert) {
|
182 | matrix_util_1.mat3.invert(matrix, matrix_util_1.mat3.clone(matrix));
|
183 | }
|
184 | return function (vector) {
|
185 | var vector3 = [vector[0], vector[1], 1];
|
186 | matrix_util_1.vec3.transformMat3(vector3, vector3, matrix);
|
187 | return [vector3[0], vector3[1]];
|
188 | };
|
189 | };
|
190 | return Coordinate;
|
191 | }());
|
192 | exports.Coordinate = Coordinate;
|
193 |
|
\ | No newline at end of file |