@antv/coord 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/coordinate.min.js +1 -1
- package/esm/coordinate.d.ts +1 -1
- package/esm/coordinate.js +60 -23
- package/esm/coordinate.js.map +1 -1
- package/esm/coordinate3D.d.ts +64 -0
- package/esm/coordinate3D.js +217 -0
- package/esm/coordinate3D.js.map +1 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/transforms/cartesian.js +18 -3
- package/esm/transforms/cartesian.js.map +1 -1
- package/esm/transforms/cartesian3D.d.ts +2 -0
- package/esm/transforms/cartesian3D.js +39 -0
- package/esm/transforms/cartesian3D.js.map +1 -0
- package/esm/transforms/custom.js +17 -1
- package/esm/transforms/custom.js.map +1 -1
- package/esm/transforms/fisheye.js +28 -12
- package/esm/transforms/fisheye.js.map +1 -1
- package/esm/transforms/helix.js +19 -3
- package/esm/transforms/helix.js.map +1 -1
- package/esm/transforms/index.d.ts +3 -0
- package/esm/transforms/index.js +3 -0
- package/esm/transforms/index.js.map +1 -1
- package/esm/transforms/matrix.js +17 -1
- package/esm/transforms/matrix.js.map +1 -1
- package/esm/transforms/parallel.js +17 -1
- package/esm/transforms/parallel.js.map +1 -1
- package/esm/transforms/polar.js +19 -3
- package/esm/transforms/polar.js.map +1 -1
- package/esm/transforms/reflect.js +19 -3
- package/esm/transforms/reflect.js.map +1 -1
- package/esm/transforms/rotate.js +18 -3
- package/esm/transforms/rotate.js.map +1 -1
- package/esm/transforms/scale.js +18 -3
- package/esm/transforms/scale.js.map +1 -1
- package/esm/transforms/scale3D.d.ts +13 -0
- package/esm/transforms/scale3D.js +33 -0
- package/esm/transforms/scale3D.js.map +1 -0
- package/esm/transforms/shear.js +22 -6
- package/esm/transforms/shear.js.map +1 -1
- package/esm/transforms/translate.js +18 -3
- package/esm/transforms/translate.js.map +1 -1
- package/esm/transforms/translate3D.d.ts +13 -0
- package/esm/transforms/translate3D.js +33 -0
- package/esm/transforms/translate3D.js.map +1 -0
- package/esm/transforms/transpose.js +18 -2
- package/esm/transforms/transpose.js.map +1 -1
- package/esm/type.d.ts +23 -1
- package/esm/utils/extend.d.ts +2 -1
- package/esm/utils/extend.js +37 -1
- package/esm/utils/extend.js.map +1 -1
- package/esm/utils/index.d.ts +1 -1
- package/esm/utils/index.js +1 -1
- package/esm/utils/index.js.map +1 -1
- package/lib/coordinate.d.ts +1 -1
- package/lib/coordinate.js +64 -27
- package/lib/coordinate.js.map +1 -1
- package/lib/coordinate3D.d.ts +64 -0
- package/lib/coordinate3D.js +220 -0
- package/lib/coordinate3D.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/transforms/cartesian.js +18 -3
- package/lib/transforms/cartesian.js.map +1 -1
- package/lib/transforms/cartesian3D.d.ts +2 -0
- package/lib/transforms/cartesian3D.js +43 -0
- package/lib/transforms/cartesian3D.js.map +1 -0
- package/lib/transforms/custom.js +17 -1
- package/lib/transforms/custom.js.map +1 -1
- package/lib/transforms/fisheye.js +28 -12
- package/lib/transforms/fisheye.js.map +1 -1
- package/lib/transforms/helix.js +19 -3
- package/lib/transforms/helix.js.map +1 -1
- package/lib/transforms/index.d.ts +3 -0
- package/lib/transforms/index.js +7 -1
- package/lib/transforms/index.js.map +1 -1
- package/lib/transforms/matrix.js +17 -1
- package/lib/transforms/matrix.js.map +1 -1
- package/lib/transforms/parallel.js +17 -1
- package/lib/transforms/parallel.js.map +1 -1
- package/lib/transforms/polar.js +19 -3
- package/lib/transforms/polar.js.map +1 -1
- package/lib/transforms/reflect.js +19 -3
- package/lib/transforms/reflect.js.map +1 -1
- package/lib/transforms/rotate.js +20 -5
- package/lib/transforms/rotate.js.map +1 -1
- package/lib/transforms/scale.js +20 -5
- package/lib/transforms/scale.js.map +1 -1
- package/lib/transforms/scale3D.d.ts +13 -0
- package/lib/transforms/scale3D.js +37 -0
- package/lib/transforms/scale3D.js.map +1 -0
- package/lib/transforms/shear.js +22 -6
- package/lib/transforms/shear.js.map +1 -1
- package/lib/transforms/translate.js +20 -5
- package/lib/transforms/translate.js.map +1 -1
- package/lib/transforms/translate3D.d.ts +13 -0
- package/lib/transforms/translate3D.js +37 -0
- package/lib/transforms/translate3D.js.map +1 -0
- package/lib/transforms/transpose.js +18 -2
- package/lib/transforms/transpose.js.map +1 -1
- package/lib/type.d.ts +23 -1
- package/lib/utils/extend.d.ts +2 -1
- package/lib/utils/extend.js +39 -2
- package/lib/utils/extend.js.map +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +2 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +7 -6
- package/src/coordinate.ts +2 -2
- package/src/coordinate3D.ts +185 -0
- package/src/index.ts +2 -1
- package/src/transforms/cartesian.ts +1 -2
- package/src/transforms/cartesian3D.ts +25 -0
- package/src/transforms/index.ts +4 -0
- package/src/transforms/rotate.ts +1 -2
- package/src/transforms/scale.ts +1 -2
- package/src/transforms/scale3D.ts +18 -0
- package/src/transforms/translate.ts +1 -2
- package/src/transforms/translate3D.ts +18 -0
- package/src/type.ts +39 -2
- package/src/utils/extend.ts +13 -1
- package/src/utils/index.ts +1 -1
package/lib/utils/extend.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
2
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extend = void 0;
|
|
28
|
+
exports.extend3D = exports.extend = void 0;
|
|
4
29
|
// 对普通的变换函数进行扩展
|
|
5
30
|
// 对于长度大于2的向量,两两为一个点的 x 和 y 坐标
|
|
6
31
|
// 依次变换后合成新的向量返回
|
|
@@ -10,10 +35,22 @@ function extend(transform) {
|
|
|
10
35
|
for (var i = 0; i < vector.length - 1; i += 2) {
|
|
11
36
|
var from = [vector[i], vector[i + 1]];
|
|
12
37
|
var to = transform(from);
|
|
13
|
-
v.push.apply(v, to);
|
|
38
|
+
v.push.apply(v, __spreadArray([], __read(to), false));
|
|
14
39
|
}
|
|
15
40
|
return v;
|
|
16
41
|
};
|
|
17
42
|
}
|
|
18
43
|
exports.extend = extend;
|
|
44
|
+
function extend3D(transform) {
|
|
45
|
+
return function (vector) {
|
|
46
|
+
var v = [];
|
|
47
|
+
for (var i = 0; i < vector.length - 1; i += 3) {
|
|
48
|
+
var from = [vector[i], vector[i + 1], vector[i + 2]];
|
|
49
|
+
var to = transform(from);
|
|
50
|
+
v.push.apply(v, __spreadArray([], __read(to), false));
|
|
51
|
+
}
|
|
52
|
+
return v;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.extend3D = extend3D;
|
|
19
56
|
//# sourceMappingURL=extend.js.map
|
package/lib/utils/extend.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extend.js","sourceRoot":"src/","sources":["utils/extend.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extend.js","sourceRoot":"src/","sources":["utils/extend.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,eAAe;AACf,8BAA8B;AAC9B,gBAAgB;AAChB,SAAgB,MAAM,CAAC,SAAoB;IACzC,OAAO,UAAC,MAAc;QACpB,IAAM,CAAC,GAAG,EAAE,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;YAC7C,IAAM,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACxC,IAAM,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC,CAAC,IAAI,OAAN,CAAC,2BAAS,EAAE,WAAE;SACf;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;AACJ,CAAC;AAVD,wBAUC;AAED,SAAgB,QAAQ,CAAC,SAAsB;IAC7C,OAAO,UAAC,MAAc;QACpB,IAAM,CAAC,GAAG,EAAE,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;YAC7C,IAAM,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACvD,IAAM,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC,CAAC,IAAI,OAAN,CAAC,2BAAS,EAAE,WAAE;SACf;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;AACJ,CAAC;AAVD,4BAUC"}
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.adjustAngle = exports.extend = exports.isMatrix = exports.compose = void 0;
|
|
3
|
+
exports.adjustAngle = exports.extend3D = exports.extend = exports.isMatrix = exports.compose = void 0;
|
|
4
4
|
var compose_1 = require("./compose");
|
|
5
5
|
Object.defineProperty(exports, "compose", { enumerable: true, get: function () { return compose_1.compose; } });
|
|
6
6
|
var isMatrix_1 = require("./isMatrix");
|
|
7
7
|
Object.defineProperty(exports, "isMatrix", { enumerable: true, get: function () { return isMatrix_1.isMatrix; } });
|
|
8
8
|
var extend_1 = require("./extend");
|
|
9
9
|
Object.defineProperty(exports, "extend", { enumerable: true, get: function () { return extend_1.extend; } });
|
|
10
|
+
Object.defineProperty(exports, "extend3D", { enumerable: true, get: function () { return extend_1.extend3D; } });
|
|
10
11
|
var adjustAngle_1 = require("./adjustAngle");
|
|
11
12
|
Object.defineProperty(exports, "adjustAngle", { enumerable: true, get: function () { return adjustAngle_1.adjustAngle; } });
|
|
12
13
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["utils/index.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["utils/index.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,mCAA4C;AAAnC,gGAAA,MAAM,OAAA;AAAE,kGAAA,QAAQ,OAAA;AACzB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/coord",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "Toolkit for mapping elements of sets into geometric objects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -29,13 +29,14 @@
|
|
|
29
29
|
"prepare": "husky install"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"
|
|
33
|
-
"@antv/scale": "^0.4.
|
|
32
|
+
"gl-matrix": "^3.4.3",
|
|
33
|
+
"@antv/scale": "^0.4.12",
|
|
34
34
|
"@antv/util": "^2.0.13"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@commitlint/cli": "^11.0.0",
|
|
38
38
|
"@rollup/plugin-commonjs": "^20.0.0",
|
|
39
|
+
"@types/gl-matrix": "^2.4.5",
|
|
39
40
|
"@types/jest": "^26.0.20",
|
|
40
41
|
"@typescript-eslint/eslint-plugin": "^4.18.0",
|
|
41
42
|
"@typescript-eslint/parser": "^4.18.0",
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
"rollup-plugin-typescript": "^1.0.1",
|
|
54
55
|
"rollup-plugin-uglify": "^6.0.4",
|
|
55
56
|
"ts-jest": "^26.5.1",
|
|
56
|
-
"typescript": "
|
|
57
|
+
"typescript": "4.8.3"
|
|
57
58
|
},
|
|
58
59
|
"jest": {
|
|
59
60
|
"preset": "ts-jest",
|
|
@@ -73,12 +74,12 @@
|
|
|
73
74
|
"limit-size": [
|
|
74
75
|
{
|
|
75
76
|
"path": "dist/coordinate.min.js",
|
|
76
|
-
"limit": "
|
|
77
|
+
"limit": "12 Kb",
|
|
77
78
|
"gzip": true
|
|
78
79
|
},
|
|
79
80
|
{
|
|
80
81
|
"path": "dist/coordinate.min.js",
|
|
81
|
-
"limit": "
|
|
82
|
+
"limit": "40 Kb"
|
|
82
83
|
}
|
|
83
84
|
],
|
|
84
85
|
"husky": {
|
package/src/coordinate.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deepMix, identity } from '@antv/util';
|
|
2
|
-
import { mat3, vec3 } from '
|
|
2
|
+
import { mat3, vec3 } from 'gl-matrix';
|
|
3
3
|
import { Options, Transformation, Transform, Transformer, Matrix3, Vector3, Vector2, Vector } from './type';
|
|
4
4
|
import { compose, isMatrix, extend } from './utils';
|
|
5
5
|
import {
|
|
@@ -116,7 +116,7 @@ export class Coordinate {
|
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
118
|
* Returns the center of the bounding box of the coordinate.
|
|
119
|
-
* @returns [centerX, centerY]
|
|
119
|
+
* @returns [centerX, centerY, centerZ]
|
|
120
120
|
*/
|
|
121
121
|
public getCenter(): [number, number] {
|
|
122
122
|
const { x, y, width, height } = this.options;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { deepMix, identity } from '@antv/util';
|
|
2
|
+
import { mat4, vec4 } from 'gl-matrix';
|
|
3
|
+
import { Vector3, Vector, Transform3D, Options3D, Transformation3D, Transformer3D, Matrix4, Vector4 } from './type';
|
|
4
|
+
import { compose, isMatrix, extend3D } from './utils';
|
|
5
|
+
import { cartesian3D, translate3D, scale3D } from './transforms';
|
|
6
|
+
|
|
7
|
+
export class Coordinate3D {
|
|
8
|
+
// 所有变换合成后的函数
|
|
9
|
+
private output: Transform3D;
|
|
10
|
+
|
|
11
|
+
// 所有变换合成后的逆函数
|
|
12
|
+
private input: Transform3D;
|
|
13
|
+
|
|
14
|
+
// 当前的选项
|
|
15
|
+
private options: Options3D = {
|
|
16
|
+
x: 0,
|
|
17
|
+
y: 0,
|
|
18
|
+
z: 0,
|
|
19
|
+
width: 300,
|
|
20
|
+
height: 150,
|
|
21
|
+
depth: 150,
|
|
22
|
+
transformations: [],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// 当前可以使用的变换
|
|
26
|
+
private transformers = {
|
|
27
|
+
cartesian3D,
|
|
28
|
+
translate3D,
|
|
29
|
+
scale3D,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create a new Coordinate Object.
|
|
34
|
+
* @param options Custom options
|
|
35
|
+
*/
|
|
36
|
+
constructor(options?: Partial<Options3D>) {
|
|
37
|
+
this.update(options);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Update options and inner state.
|
|
42
|
+
* @param options Options to be updated
|
|
43
|
+
*/
|
|
44
|
+
public update(options: Partial<Options3D>) {
|
|
45
|
+
this.options = deepMix({}, this.options, options);
|
|
46
|
+
this.recoordinate();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Returns a new Coordinate with same options.
|
|
51
|
+
* @returns Coordinate
|
|
52
|
+
*/
|
|
53
|
+
public clone() {
|
|
54
|
+
return new Coordinate3D(this.options);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns current options.
|
|
59
|
+
* @returns options
|
|
60
|
+
*/
|
|
61
|
+
public getOptions() {
|
|
62
|
+
return this.options;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Clear transformations and update.
|
|
67
|
+
*/
|
|
68
|
+
public clear() {
|
|
69
|
+
this.update({
|
|
70
|
+
transformations: [],
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Returns the size of the bounding box of the coordinate.
|
|
76
|
+
* @returns [width, height, depth]
|
|
77
|
+
*/
|
|
78
|
+
public getSize(): [number, number, number] {
|
|
79
|
+
const { width, height, depth } = this.options;
|
|
80
|
+
return [width, height, depth];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the center of the bounding box of the coordinate.
|
|
85
|
+
* @returns [centerX, centerY, centerZ]
|
|
86
|
+
*/
|
|
87
|
+
public getCenter(): [number, number, number] {
|
|
88
|
+
const { x, y, z, width, height, depth } = this.options;
|
|
89
|
+
return [(x * 2 + width) / 2, (y * 2 + height) / 2, (z * 2 + depth) / 2];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Add selected transformation.
|
|
94
|
+
* @param args transform type and params
|
|
95
|
+
* @returns Coordinate
|
|
96
|
+
*/
|
|
97
|
+
public transform(...args: Transformation3D) {
|
|
98
|
+
const { transformations } = this.options;
|
|
99
|
+
this.update({
|
|
100
|
+
transformations: [...transformations, [...args]],
|
|
101
|
+
});
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Apples transformations for the current vector.
|
|
107
|
+
* @param vector original vector3
|
|
108
|
+
* @returns transformed vector3
|
|
109
|
+
*/
|
|
110
|
+
public map(vector: Vector3 | Vector) {
|
|
111
|
+
return this.output(vector);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Apples invert transformations for the current vector.
|
|
116
|
+
* @param vector transformed vector3
|
|
117
|
+
* @param vector original vector3
|
|
118
|
+
*/
|
|
119
|
+
public invert(vector: Vector3 | Vector) {
|
|
120
|
+
return this.input(vector);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private recoordinate() {
|
|
124
|
+
this.output = this.compose();
|
|
125
|
+
this.input = this.compose(true);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 将所有的变换合成一个函数
|
|
129
|
+
// 变换有两种类型:矩阵变换和函数变换
|
|
130
|
+
// 处理过程中需要把连续的矩阵变换合成一个变换函数,然后在和其他变换函数合成最终的变换函数
|
|
131
|
+
private compose(invert = false) {
|
|
132
|
+
const transformations = invert ? [...this.options.transformations].reverse() : this.options.transformations;
|
|
133
|
+
const getter = invert ? (d: Transformer3D) => d.untransform : (d: Transformer3D) => d.transform;
|
|
134
|
+
const matrixes = [];
|
|
135
|
+
const transforms = [];
|
|
136
|
+
const add = (transform: Transform3D, extended = true) =>
|
|
137
|
+
transforms.push(extended ? extend3D(transform) : transform);
|
|
138
|
+
|
|
139
|
+
for (const [name, ...args] of transformations) {
|
|
140
|
+
const createTransformer = this.transformers[name];
|
|
141
|
+
if (createTransformer) {
|
|
142
|
+
const { x, y, z, width, height, depth } = this.options;
|
|
143
|
+
const transformer = createTransformer([...args], x, y, z, width, height, depth);
|
|
144
|
+
|
|
145
|
+
if (isMatrix(transformer)) {
|
|
146
|
+
// 如果当前变换是矩阵变换,那么先保存下来
|
|
147
|
+
matrixes.push(transformer);
|
|
148
|
+
} else {
|
|
149
|
+
// 如果当前变换是函数变换,并且之前有没有合成的矩阵变换,那么现将之前的矩阵变换合成
|
|
150
|
+
if (matrixes.length) {
|
|
151
|
+
const transform = this.createMatrixTransform(matrixes, invert);
|
|
152
|
+
add(transform);
|
|
153
|
+
matrixes.splice(0, matrixes.length);
|
|
154
|
+
}
|
|
155
|
+
const transform = getter(transformer as Transformer3D) || identity;
|
|
156
|
+
add(transform, true);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 合成剩下的矩阵变换
|
|
162
|
+
if (matrixes.length) {
|
|
163
|
+
const transform = this.createMatrixTransform(matrixes, invert);
|
|
164
|
+
add(transform);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return compose<Vector3 | Vector>(...transforms);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 将连续的矩阵的运算合成一个变换函数
|
|
171
|
+
private createMatrixTransform(matrixes: Matrix4[], invert: boolean): Transform3D {
|
|
172
|
+
const matrix = mat4.create();
|
|
173
|
+
if (invert) matrixes.reverse();
|
|
174
|
+
matrixes.forEach((m) => mat4.mul(matrix, matrix, m));
|
|
175
|
+
if (invert) {
|
|
176
|
+
mat4.invert(matrix, mat4.clone(matrix));
|
|
177
|
+
}
|
|
178
|
+
return (vector: Vector3): Vector3 => {
|
|
179
|
+
const vector4: Vector4 = [vector[0], vector[1], vector[2], 1];
|
|
180
|
+
|
|
181
|
+
vec4.transformMat4(vector4, vector4, matrix);
|
|
182
|
+
return [vector4[0], vector4[1], vector4[2]];
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
1
|
import { Linear } from '@antv/scale';
|
|
3
|
-
import {
|
|
2
|
+
import { CreateTransformer, Vector2 } from '../type';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Maps normalized value to the bounding box of coordinate.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Linear } from '@antv/scale';
|
|
2
|
+
import { Vector3, CreateTransformer3D } from '../type';
|
|
3
|
+
|
|
4
|
+
export const cartesian3D: CreateTransformer3D = (params, x, y, z, width, height, depth) => {
|
|
5
|
+
const sx = new Linear({
|
|
6
|
+
range: [x, x + width],
|
|
7
|
+
});
|
|
8
|
+
const sy = new Linear({
|
|
9
|
+
range: [y, y + height],
|
|
10
|
+
});
|
|
11
|
+
const sz = new Linear({
|
|
12
|
+
range: [z, z + depth],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
transform(vector: Vector3) {
|
|
17
|
+
const [v1, v2, v3] = vector;
|
|
18
|
+
return [sx.map(v1), sy.map(v2), sz.map(v3)];
|
|
19
|
+
},
|
|
20
|
+
untransform(vector: Vector3) {
|
|
21
|
+
const [v1, v2, v3] = vector;
|
|
22
|
+
return [sx.invert(v1), sy.invert(v2), sz.invert(v3)];
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
package/src/transforms/index.ts
CHANGED
|
@@ -11,3 +11,7 @@ export { helix } from './helix';
|
|
|
11
11
|
export { parallel } from './parallel';
|
|
12
12
|
export { shearX, shearY } from './shear';
|
|
13
13
|
export { fisheye, fisheyeX, fisheyeY, fisheyeCircular } from './fisheye';
|
|
14
|
+
|
|
15
|
+
export { cartesian3D } from './cartesian3D';
|
|
16
|
+
export { translate3D } from './translate3D';
|
|
17
|
+
export { scale3D } from './scale3D';
|
package/src/transforms/rotate.ts
CHANGED
package/src/transforms/scale.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { mat4 } from 'gl-matrix';
|
|
2
|
+
import { CreateTransformer3D } from '../type';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Apply scale transformation for current vector.
|
|
6
|
+
* @param params [sx, sy, sz]
|
|
7
|
+
* @param x x of the the bounding box of coordinate
|
|
8
|
+
* @param y y of the the bounding box of coordinate
|
|
9
|
+
* @param z z of the the bounding box of coordinate
|
|
10
|
+
* @param width width of the the bounding box of coordinate
|
|
11
|
+
* @param height height of the the bounding box of coordinate
|
|
12
|
+
* @param depth depth of the the bounding box of coordinate
|
|
13
|
+
* @returns transformer
|
|
14
|
+
*/
|
|
15
|
+
export const scale3D: CreateTransformer3D = (params, x, y, z, width, height, depth) => {
|
|
16
|
+
const [sx, sy, sz] = params as number[];
|
|
17
|
+
return mat4.fromScaling(mat4.create(), [sx, sy, sz]);
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { mat4 } from 'gl-matrix';
|
|
2
|
+
import { CreateTransformer3D } from '../type';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Apply translate transformation for current vector.
|
|
6
|
+
* @param params [tx, ty, tz]
|
|
7
|
+
* @param x x of the the bounding box of coordinate
|
|
8
|
+
* @param y y of the the bounding box of coordinate
|
|
9
|
+
* @param z z of the the bounding box of coordinate
|
|
10
|
+
* @param width width of the the bounding box of coordinate
|
|
11
|
+
* @param height height of the the bounding box of coordinate
|
|
12
|
+
* @param depth depth of the the bounding box of coordinate
|
|
13
|
+
* @returns transformer
|
|
14
|
+
*/
|
|
15
|
+
export const translate3D: CreateTransformer3D = (params, x, y, z, width, height, depth) => {
|
|
16
|
+
const [tx, ty, tz] = params as number[];
|
|
17
|
+
return mat4.fromTranslation(mat4.create(), [tx, ty, tz]);
|
|
18
|
+
};
|
package/src/type.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { vec3, mat3 } from '
|
|
1
|
+
import { vec3, mat3, mat4, vec4 } from 'gl-matrix';
|
|
2
2
|
|
|
3
3
|
export type TransformCallback = (x: number, y: number, width: number, height: number) => Transformer;
|
|
4
|
+
export type Transform3DCallback = (
|
|
5
|
+
x: number,
|
|
6
|
+
y: number,
|
|
7
|
+
z: number,
|
|
8
|
+
width: number,
|
|
9
|
+
height: number,
|
|
10
|
+
depth: number,
|
|
11
|
+
) => Transformer3D;
|
|
4
12
|
|
|
5
13
|
type Translate = ['translate', number, number];
|
|
6
14
|
type Cartesian = ['cartesian'];
|
|
@@ -22,6 +30,10 @@ type FisheyeX = ['fisheye.x', number, number, boolean?];
|
|
|
22
30
|
type FisheyeY = ['fisheye.y', number, number, boolean?];
|
|
23
31
|
type FisheyeCircular = ['fisheye.circular', number, number, number, number, boolean?];
|
|
24
32
|
|
|
33
|
+
type Cartesian3D = ['cartesian3D'];
|
|
34
|
+
type Translate3D = ['translate3D', number, number, number];
|
|
35
|
+
type Scale3D = ['scale3D', number, number, number];
|
|
36
|
+
|
|
25
37
|
export type Transformation =
|
|
26
38
|
| Translate
|
|
27
39
|
| Cartesian
|
|
@@ -42,6 +54,7 @@ export type Transformation =
|
|
|
42
54
|
| FisheyeX
|
|
43
55
|
| FisheyeY
|
|
44
56
|
| FisheyeCircular;
|
|
57
|
+
export type Transformation3D = Cartesian3D | Translate3D | Scale3D;
|
|
45
58
|
|
|
46
59
|
export type Options = {
|
|
47
60
|
x?: number;
|
|
@@ -50,21 +63,36 @@ export type Options = {
|
|
|
50
63
|
height?: number;
|
|
51
64
|
transformations?: Transformation[];
|
|
52
65
|
};
|
|
66
|
+
export type Options3D = {
|
|
67
|
+
x?: number;
|
|
68
|
+
y?: number;
|
|
69
|
+
z?: number;
|
|
70
|
+
width?: number;
|
|
71
|
+
height?: number;
|
|
72
|
+
depth?: number;
|
|
73
|
+
transformations?: Transformation3D[];
|
|
74
|
+
};
|
|
53
75
|
|
|
54
76
|
export type Vector2 = [number, number];
|
|
55
|
-
|
|
56
77
|
export type Vector3 = vec3;
|
|
78
|
+
export type Vector4 = vec4;
|
|
57
79
|
|
|
58
80
|
export type Vector = number[];
|
|
59
81
|
|
|
60
82
|
export type Matrix3 = mat3;
|
|
83
|
+
export type Matrix4 = mat4;
|
|
61
84
|
|
|
62
85
|
export type Transform = (vector: Vector2 | Vector) => Vector2 | Vector;
|
|
86
|
+
export type Transform3D = (vector: Vector3 | Vector) => Vector3 | Vector;
|
|
63
87
|
|
|
64
88
|
export type Transformer = {
|
|
65
89
|
transform?: Transform;
|
|
66
90
|
untransform?: Transform;
|
|
67
91
|
};
|
|
92
|
+
export type Transformer3D = {
|
|
93
|
+
transform?: Transform3D;
|
|
94
|
+
untransform?: Transform3D;
|
|
95
|
+
};
|
|
68
96
|
|
|
69
97
|
export type CreateTransformer = (
|
|
70
98
|
params: number[] | (number | boolean)[] | [TransformCallback] | [Matrix3],
|
|
@@ -73,3 +101,12 @@ export type CreateTransformer = (
|
|
|
73
101
|
width: number,
|
|
74
102
|
height: number,
|
|
75
103
|
) => Transformer | Matrix3;
|
|
104
|
+
export type CreateTransformer3D = (
|
|
105
|
+
params: number[] | (number | boolean)[] | [TransformCallback] | [Matrix3],
|
|
106
|
+
x: number,
|
|
107
|
+
y: number,
|
|
108
|
+
z: number,
|
|
109
|
+
width: number,
|
|
110
|
+
height: number,
|
|
111
|
+
depth: number,
|
|
112
|
+
) => Transformer3D | Matrix4;
|
package/src/utils/extend.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transform, Vector } from '../type';
|
|
1
|
+
import { Transform, Transform3D, Vector } from '../type';
|
|
2
2
|
|
|
3
3
|
// 对普通的变换函数进行扩展
|
|
4
4
|
// 对于长度大于2的向量,两两为一个点的 x 和 y 坐标
|
|
@@ -14,3 +14,15 @@ export function extend(transform: Transform) {
|
|
|
14
14
|
return v;
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
export function extend3D(transform: Transform3D) {
|
|
19
|
+
return (vector: Vector) => {
|
|
20
|
+
const v = [];
|
|
21
|
+
for (let i = 0; i < vector.length - 1; i += 3) {
|
|
22
|
+
const from = [vector[i], vector[i + 1], vector[i + 2]];
|
|
23
|
+
const to = transform(from);
|
|
24
|
+
v.push(...to);
|
|
25
|
+
}
|
|
26
|
+
return v;
|
|
27
|
+
};
|
|
28
|
+
}
|
package/src/utils/index.ts
CHANGED