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