vislite 0.6.0-alpha.0 → 0.6.0-alpha.2
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/.eslintrc.js +24 -0
- package/CHANGELOG +2 -0
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +13 -8
- package/lib/Canvas/index.umd.min.js +3 -3
- package/lib/Cardinal/index.umd.js +2 -2
- package/lib/Cardinal/index.umd.min.js +2 -2
- package/lib/Eoap/index.umd.js +2 -2
- package/lib/Eoap/index.umd.min.js +2 -2
- package/lib/Geometry/index.umd.js +7 -4
- package/lib/Geometry/index.umd.min.js +2 -2
- package/lib/Hermite/index.umd.js +2 -2
- package/lib/Hermite/index.umd.min.js +2 -2
- package/lib/Matrix4/index.umd.js +2 -2
- package/lib/Matrix4/index.umd.min.js +2 -2
- package/lib/Mercator/index.umd.js +2 -2
- package/lib/Mercator/index.umd.min.js +2 -2
- package/lib/OralCanvas/index.es.js +8 -6
- package/lib/OralCanvas/index.es.min.js +3 -3
- package/lib/OralWebGL/index.es.js +7 -5
- package/lib/OralWebGL/index.es.min.js +3 -3
- package/lib/SVG/index.umd.js +6 -4
- package/lib/SVG/index.umd.min.js +2 -2
- package/lib/Shader/index.umd.js +2 -2
- package/lib/Shader/index.umd.min.js +2 -2
- package/lib/Texture/index.umd.js +4 -3
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +8 -5
- package/lib/TreeLayout/index.umd.min.js +2 -2
- package/lib/WebGL/index.umd.js +7 -5
- package/lib/WebGL/index.umd.min.js +3 -3
- package/lib/animation/index.umd.js +4 -3
- package/lib/animation/index.umd.min.js +2 -2
- package/lib/formatColor/index.umd.js +2 -2
- package/lib/formatColor/index.umd.min.js +2 -2
- package/lib/getLoopColors/index.umd.js +2 -2
- package/lib/getLoopColors/index.umd.min.js +2 -2
- package/lib/getWebGLContext/index.umd.js +4 -3
- package/lib/getWebGLContext/index.umd.min.js +2 -2
- package/lib/index.umd.js +35 -20
- package/lib/index.umd.min.js +3 -3
- package/lib/move/index.umd.js +2 -2
- package/lib/move/index.umd.min.js +2 -2
- package/lib/resizeObserver/index.umd.js +4 -3
- package/lib/resizeObserver/index.umd.min.js +2 -2
- package/lib/rotate/index.umd.js +2 -2
- package/lib/rotate/index.umd.min.js +2 -2
- package/lib/ruler/index.umd.js +2 -2
- package/lib/ruler/index.umd.min.js +2 -2
- package/lib/scale/index.umd.js +2 -2
- package/lib/scale/index.umd.min.js +2 -2
- package/lib/throttle/index.umd.js +2 -2
- package/lib/throttle/index.umd.min.js +2 -2
- package/lib/viewHandler/index.umd.js +4 -4
- package/lib/viewHandler/index.umd.min.js +3 -3
- package/package.json +6 -2
- package/src/Canvas.ts +8 -5
- package/src/Eoap.ts +6 -6
- package/src/Geometry.ts +5 -5
- package/src/Matrix4/index.ts +4 -4
- package/src/Matrix4/move.ts +1 -1
- package/src/Matrix4/rotate.ts +1 -1
- package/src/Matrix4/transform.ts +1 -1
- package/src/Mercator.ts +4 -4
- package/src/SVG.ts +2 -2
- package/src/WebGL.ts +3 -3
- package/src/animation.ts +6 -6
- package/src/common/assemble.ts +1 -1
- package/src/common/canvas/arc.ts +4 -3
- package/src/common/canvas/config.ts +5 -5
- package/src/common/canvas/gradient.ts +6 -6
- package/src/common/canvas/index.ts +13 -12
- package/src/common/canvas/painter.ts +5 -14
- package/src/common/geometry/prism-horizontal.ts +4 -2
- package/src/common/geometry/prism-vertical.ts +3 -3
- package/src/common/geometry/sphere-fragment.ts +5 -4
- package/src/common/geometry/tool/circle.ts +2 -2
- package/src/common/mergeOption.ts +1 -1
- package/src/common/setStyle.ts +1 -1
- package/src/common/svg/config.ts +11 -11
- package/src/common/svg/dictionary.ts +1 -1
- package/src/common/svg/gradient.ts +12 -12
- package/src/common/svg/index.ts +6 -6
- package/src/common/svg/tool.ts +2 -2
- package/src/common/tree/toInnerTree.ts +4 -3
- package/src/common/tree/toPlainTree.ts +8 -7
- package/src/common/webgl/buffer.ts +4 -4
- package/src/common/webgl/doDraw.ts +2 -2
- package/src/common/webgl/getColorFactory.ts +6 -6
- package/src/common/webgl/getShader.ts +5 -5
- package/src/common/webgl/getTexture.ts +2 -2
- package/src/common/webgl/getWebGLContext.ts +5 -4
- package/src/common/webgl/index.ts +11 -10
- package/src/common/webgl/shader.ts +6 -6
- package/src/common/webgl/texture.ts +7 -6
- package/src/formatColor.ts +5 -5
- package/src/getLoopColors.ts +1 -1
- package/src/interpolation/Cardinal.ts +1 -1
- package/src/interpolation/Hermite.ts +3 -3
- package/src/layout/TreeLayout.ts +21 -21
- package/src/move.ts +1 -1
- package/src/resizeObserver.ts +2 -1
- package/src/rotate.ts +1 -1
- package/src/ruler.ts +18 -18
- package/src/throttle.ts +3 -2
- package/src/viewHandler.ts +13 -13
- package/types/CanvasOption.d.ts +3 -2
- package/types/CanvasOpts.d.ts +10 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.6.0-alpha.
|
|
2
|
+
* VISLite JavaScript Library v0.6.0-alpha.2
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Dec 17 2023 12:58:48 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
12
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.6.0-alpha.
|
|
2
|
+
* VISLite JavaScript Library v0.6.0-alpha.2
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Dec 17 2023 12:58:48 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
var e,t;e=this,t=function(){"use strict";return function(e,t){void 0===t&&(t={}),t=function(e,t){for(var n in e)t[n]=e[n];return t}(t,{time:200,keep:!1,opportunity:"end"});var n,o=!1,i=!1,r=!1;return function(){var p=this;if(n=arguments,o)i=!0,r=!0;else{"end"!=t.opportunity&&e.apply(p,n),o=!0;var f=setInterval((function(){i?t.keep||e.apply(p,n):("begin"!=t.opportunity&&(r||"end"==t.opportunity)&&e.apply(p,n),o=!1,r=!1,clearInterval(f)),i=!1}),t.time)}}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_throttle=t();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.6.0-alpha.
|
|
2
|
+
* VISLite JavaScript Library v0.6.0-alpha.2
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Dec 17 2023 12:58:48 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
12
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -98,13 +98,13 @@
|
|
|
98
98
|
el.addEventListener("mousedown", function (event) {
|
|
99
99
|
mouseP = mousePosition(el, event);
|
|
100
100
|
});
|
|
101
|
-
el.addEventListener("mouseup", function (
|
|
101
|
+
el.addEventListener("mouseup", function () {
|
|
102
102
|
mouseP = null;
|
|
103
103
|
});
|
|
104
104
|
el.addEventListener("mousemove", function (event) {
|
|
105
105
|
doMove(event);
|
|
106
106
|
});
|
|
107
|
-
el.addEventListener("touchend", function (
|
|
107
|
+
el.addEventListener("touchend", function () {
|
|
108
108
|
mouseP = null;
|
|
109
109
|
});
|
|
110
110
|
el.addEventListener("touchstart", function (event) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.6.0-alpha.
|
|
2
|
+
* VISLite JavaScript Library v0.6.0-alpha.2
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Dec 17 2023 12:58:48 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
|
-
var e,n;e=this,n=function(){"use strict";var e=function(e,n){var t=e.getBoundingClientRect();return{x:n.clientX-t.left,y:n.clientY-t.top}};return function(n){var t=document.getElementsByTagName("body")[0];t.addEventListener("keydown",(function(e){var t=function(e){return{37:"left",38:"up",39:"right",40:"down"}[e.keyCode||e.which]}(e);"up"==t?n({type:"lookUp",normal:[],value:.1,event:e}):"down"==t?n({type:"lookDown",normal:[],value:.1,event:e}):"left"==t?n({type:"lookLeft",normal:[],value:.1,event:e}):"right"==t&&n({type:"lookRight",normal:[],value:.1,event:e})}));var o=null,i=function(i){if(null==o)n({type:"hover",normal:[],value:0,event:i});else{var u=e(t,i),l=[u.x-o.x,u.y-o.y],a=[l[1],l[0],0];if(0==a[0]&&0==a[1])return;n({type:"rotate",normal:a,value:.01*(Math.abs(u.x-o.x)+Math.abs(u.y-o.y)),event:i}),o=u}};t.addEventListener("mousedown",(function(n){o=e(t,n)})),t.addEventListener("mouseup",(function(
|
|
11
|
+
var e,n;e=this,n=function(){"use strict";var e=function(e,n){var t=e.getBoundingClientRect();return{x:n.clientX-t.left,y:n.clientY-t.top}};return function(n){var t=document.getElementsByTagName("body")[0];t.addEventListener("keydown",(function(e){var t=function(e){return{37:"left",38:"up",39:"right",40:"down"}[e.keyCode||e.which]}(e);"up"==t?n({type:"lookUp",normal:[],value:.1,event:e}):"down"==t?n({type:"lookDown",normal:[],value:.1,event:e}):"left"==t?n({type:"lookLeft",normal:[],value:.1,event:e}):"right"==t&&n({type:"lookRight",normal:[],value:.1,event:e})}));var o=null,i=function(i){if(null==o)n({type:"hover",normal:[],value:0,event:i});else{var u=e(t,i),l=[u.x-o.x,u.y-o.y],a=[l[1],l[0],0];if(0==a[0]&&0==a[1])return;n({type:"rotate",normal:a,value:.01*(Math.abs(u.x-o.x)+Math.abs(u.y-o.y)),event:i}),o=u}};t.addEventListener("mousedown",(function(n){o=e(t,n)})),t.addEventListener("mouseup",(function(){o=null})),t.addEventListener("mousemove",(function(e){i(e)})),t.addEventListener("touchend",(function(){o=null})),t.addEventListener("touchstart",(function(n){o=e(t,n)})),t.addEventListener("touchmove",(function(e){i(e.touches[0])}));var u=function(e,t){0!=e&&n({type:"scale",value:e<0?.899:1.101,normal:[],event:t})};t.addEventListener("mousewheel",(function(e){u(e.wheelDelta,e)})),window.addEventListener&&window.addEventListener("DOMMouseScroll",(function(e){u(-1*e.detail,e)}),!1)}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_viewHandler=n();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vislite",
|
|
3
|
-
"version": "0.6.0-alpha.
|
|
3
|
+
"version": "0.6.0-alpha.2",
|
|
4
4
|
"description": "灵活、快速、简单的数据可视化交互式跨端前端库",
|
|
5
5
|
"main": "./lib/index.umd.min.js",
|
|
6
6
|
"typings": "./types/index.d.ts",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"dev": "webpack serve --config ./build/webpack.config.js",
|
|
11
11
|
"build": "devby --delete ./lib && node ./build/pkg.js",
|
|
12
|
-
"test": "karma start ./build/karma.config.js"
|
|
12
|
+
"test": "karma start ./build/karma.config.js",
|
|
13
|
+
"lint": "eslint src/**/*.{js,ts} --fix"
|
|
13
14
|
},
|
|
14
15
|
"miniprogram": ".",
|
|
15
16
|
"repository": {
|
|
@@ -49,7 +50,10 @@
|
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"@rollup/plugin-typescript": "^11.1.0",
|
|
51
52
|
"@types/jasmine": "^4.3.1",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
|
54
|
+
"@typescript-eslint/parser": "^6.14.0",
|
|
52
55
|
"devby": "^0.4.6",
|
|
56
|
+
"eslint": "^8.56.0",
|
|
53
57
|
"karma": "^6.3.10",
|
|
54
58
|
"karma-chrome-launcher": "^3.1.0",
|
|
55
59
|
"karma-jasmine": "^4.0.1",
|
package/src/Canvas.ts
CHANGED
|
@@ -12,14 +12,15 @@ class Canvas extends OralCanvas implements CanvasType {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
option = mergeOption(option, {
|
|
15
|
-
region: true
|
|
15
|
+
region: true,
|
|
16
|
+
willReadFrequently: false
|
|
16
17
|
})
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
const width = el.clientWidth, height = el.clientHeight
|
|
19
20
|
|
|
20
21
|
let ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
const _el = el as any
|
|
23
24
|
|
|
24
25
|
// 如果已经初始化过了
|
|
25
26
|
if (_el._vislite_canvas_) {
|
|
@@ -42,7 +43,7 @@ class Canvas extends OralCanvas implements CanvasType {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
// 设置画布大小
|
|
45
|
-
for (
|
|
46
|
+
for (const canvas of [ViewCanvas, RegionCanvas]) {
|
|
46
47
|
|
|
47
48
|
if (canvas) {
|
|
48
49
|
canvas.style.width = width + "px"
|
|
@@ -53,7 +54,9 @@ class Canvas extends OralCanvas implements CanvasType {
|
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
super(ViewCanvas, RegionCanvas
|
|
57
|
+
super(ViewCanvas, RegionCanvas, {
|
|
58
|
+
willReadFrequently: option.willReadFrequently
|
|
59
|
+
})
|
|
57
60
|
|
|
58
61
|
this.__canvas = ViewCanvas
|
|
59
62
|
}
|
package/src/Eoap.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type MapType from '../types/Map'
|
|
2
2
|
|
|
3
3
|
// 围绕X轴旋转
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const rotateX = function (deg: number, x: number, y: number, z: number) {
|
|
5
|
+
const cos = Math.cos(deg), sin = Math.sin(deg)
|
|
6
6
|
return [x, y * cos - z * sin, y * sin + z * cos]
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// 围绕Y轴旋转
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const rotateY = function (deg: number, x: number, y: number, z: number) {
|
|
11
|
+
const cos = Math.cos(deg), sin = Math.sin(deg)
|
|
12
12
|
return [z * sin + x * cos, y, z * cos - x * sin]
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// 围绕Z轴旋转
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const rotateZ = function (deg: number, x: number, y: number, z: number) {
|
|
17
|
+
const cos = Math.cos(deg), sin = Math.sin(deg)
|
|
18
18
|
return [x * cos - y * sin, x * sin + y * cos, z]
|
|
19
19
|
}
|
|
20
20
|
|
package/src/Geometry.ts
CHANGED
|
@@ -21,7 +21,7 @@ class Geometry implements GeometryType {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
config(option: GeometryOptionType) {
|
|
24
|
-
for (
|
|
24
|
+
for (const key in option) {
|
|
25
25
|
this.__option[key] = option[key]
|
|
26
26
|
}
|
|
27
27
|
return this
|
|
@@ -31,14 +31,14 @@ class Geometry implements GeometryType {
|
|
|
31
31
|
cylinder(x: number, y: number, z: number, radius: number, height: number): Array<GeometryResultType> {
|
|
32
32
|
|
|
33
33
|
// 求解出需要切割多少份比较合理
|
|
34
|
-
|
|
34
|
+
const num = splitNum(this.__option.precision, radius)
|
|
35
35
|
return this.prism(x, y, z, radius, height, num)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// 棱柱体
|
|
39
39
|
prism(x: number, y: number, z: number, radius: number, height: number, num: number): Array<GeometryResultType> {
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
const result = [{
|
|
42
42
|
points: [],
|
|
43
43
|
length: 0,
|
|
44
44
|
method: "TRIANGLES" as const
|
|
@@ -61,10 +61,10 @@ class Geometry implements GeometryType {
|
|
|
61
61
|
sphere(cx: number, cy: number, cz: number, radius: number): Array<GeometryResultType> {
|
|
62
62
|
|
|
63
63
|
// 求解出需要切割多少份比较合理
|
|
64
|
-
|
|
64
|
+
const num = splitNum(this.__option.precision, radius)
|
|
65
65
|
|
|
66
66
|
// 然后一瓣瓣的绘制
|
|
67
|
-
|
|
67
|
+
const result = [{
|
|
68
68
|
points: [],
|
|
69
69
|
length: 0,
|
|
70
70
|
method: "TRIANGLES" as const
|
package/src/Matrix4/index.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type Matrix4Type from '../../types/Matrix4'
|
|
|
2
2
|
|
|
3
3
|
// 两个4x4矩阵相乘
|
|
4
4
|
// 或矩阵和齐次坐标相乘
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const _multiply = function (matrix4: number[], param: number[]) {
|
|
6
|
+
const newParam: number[] = []
|
|
7
7
|
for (let i = 0; i < 4; i++)
|
|
8
8
|
for (let j = 0; j < param.length / 4; j++)
|
|
9
9
|
newParam[j * 4 + i] =
|
|
@@ -21,7 +21,7 @@ import _transform from './transform'
|
|
|
21
21
|
|
|
22
22
|
// 列主序存储的4x4矩阵
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
const __initMatrix4 = [
|
|
25
25
|
1, 0, 0, 0,
|
|
26
26
|
0, 1, 0, 0,
|
|
27
27
|
0, 0, 1, 0,
|
|
@@ -51,7 +51,7 @@ class Matrix4 implements Matrix4Type {
|
|
|
51
51
|
|
|
52
52
|
// 旋转
|
|
53
53
|
rotate(deg: number, a1: number, b1: number, c1?: number, a2?: number, b2?: number, c2?: number) {
|
|
54
|
-
|
|
54
|
+
const matrix4s = _transform(a1, b1, c1, a2, b2, c2)
|
|
55
55
|
this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4)
|
|
56
56
|
return this
|
|
57
57
|
}
|
package/src/Matrix4/move.ts
CHANGED
package/src/Matrix4/rotate.ts
CHANGED
package/src/Matrix4/transform.ts
CHANGED
|
@@ -28,7 +28,7 @@ export default function (a1: number, b1: number, c1: number, a2: number, b2: num
|
|
|
28
28
|
|
|
29
29
|
if (a1 == a2 && b1 == b2 && c1 == c2) throw new Error('It\'s not a legitimate ray!')
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
const sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)),
|
|
32
32
|
cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1,
|
|
33
33
|
sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0,
|
|
34
34
|
|
package/src/Mercator.ts
CHANGED
|
@@ -7,12 +7,12 @@ class Mercator implements MapType {
|
|
|
7
7
|
use: (λ: number, φ: number) => [number, number, number]
|
|
8
8
|
constructor(scale: number = 7, center: number[] = [107, 36]) {
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const perimeter = 100 * scale * Math.PI // 半周长
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const help = perimeter / 180
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const cx = help * center[0] // 中心横坐标
|
|
15
|
+
const cy = -1 * help * center[1] // 中心纵坐标
|
|
16
16
|
|
|
17
17
|
this.use = (λ: number, φ: number) => {
|
|
18
18
|
return [
|
package/src/SVG.ts
CHANGED
|
@@ -8,9 +8,9 @@ class SVG extends OralSVG implements SVGType {
|
|
|
8
8
|
throw new Error("VISLite SVG:The mount point requires an HTMLElement type but encountered null.")
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const width = el.clientWidth, height = el.clientHeight
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const ViewSVG = document.createElementNS("http://www.w3.org/2000/svg", 'svg')
|
|
14
14
|
el.appendChild(ViewSVG)
|
|
15
15
|
|
|
16
16
|
ViewSVG.setAttribute("width", width + "")
|
package/src/WebGL.ts
CHANGED
|
@@ -14,11 +14,11 @@ class WebGL extends OralWebGL implements WebGLType {
|
|
|
14
14
|
region: true
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const width = el.clientWidth, height = el.clientHeight
|
|
18
18
|
|
|
19
19
|
let ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const _el = el as any
|
|
22
22
|
|
|
23
23
|
// 如果已经初始化过了
|
|
24
24
|
if (_el._vislite_canvas_) {
|
|
@@ -49,7 +49,7 @@ class WebGL extends OralWebGL implements WebGLType {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
// 设置画布大小
|
|
52
|
-
for (
|
|
52
|
+
for (const canvas of [ViewCanvas, RegionCanvas]) {
|
|
53
53
|
|
|
54
54
|
if (canvas) {
|
|
55
55
|
canvas.style.width = width + "px"
|
package/src/animation.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//当前正在运动的动画的tick函数堆栈
|
|
2
2
|
let $timers: any[] = []
|
|
3
3
|
//唯一定时器的定时间隔
|
|
4
|
-
|
|
4
|
+
const $interval = 13
|
|
5
5
|
//定时器ID
|
|
6
6
|
let $timerId: any
|
|
7
7
|
|
|
@@ -15,13 +15,13 @@ let $timerId: any
|
|
|
15
15
|
*/
|
|
16
16
|
export default function (doback: (deep: number) => void, duration: number = 400, callback: (deep: number) => void = () => { }): Function {
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const clock = {
|
|
19
19
|
//把tick函数推入堆栈
|
|
20
20
|
"timer": function (tick: (deep: number) => void, duration: number, callback: (deep: number) => void) {
|
|
21
21
|
if (!tick) {
|
|
22
22
|
throw new Error('Tick is required!')
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
const id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0)
|
|
25
25
|
$timers.push({
|
|
26
26
|
"id": id,
|
|
27
27
|
"createTime": new Date(),
|
|
@@ -42,8 +42,8 @@ export default function (doback: (deep: number) => void, duration: number = 400,
|
|
|
42
42
|
|
|
43
43
|
//被定时器调用,遍历timers堆栈
|
|
44
44
|
"tick": function () {
|
|
45
|
-
let createTime: Date, flag: number, tick: (deep: number) => void, callback: (deep: number) => void, timer: any, duration: number, passTime: number
|
|
46
|
-
|
|
45
|
+
let createTime: Date, flag: number, tick: (deep: number) => void, callback: (deep: number) => void, timer: any, duration: number, passTime: number
|
|
46
|
+
const timers: any[] = $timers
|
|
47
47
|
$timers = []
|
|
48
48
|
$timers.length = 0
|
|
49
49
|
for (flag = 0; flag < timers.length; flag++) {
|
|
@@ -79,7 +79,7 @@ export default function (doback: (deep: number) => void, duration: number = 400,
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
const id = clock.timer(function (deep: number) {
|
|
83
83
|
//其中deep为0-1,表示改变的程度
|
|
84
84
|
doback(deep)
|
|
85
85
|
}, duration, callback)
|
package/src/common/assemble.ts
CHANGED
package/src/common/canvas/arc.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
// 点(x,y)围绕中心(cx,cy)旋转deg度
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const rotate = function (cx: number, cy: number, deg: number, x: number, y: number) {
|
|
5
|
+
const cos = Math.cos(deg), sin = Math.sin(deg)
|
|
6
6
|
return [
|
|
7
7
|
+((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
|
|
8
8
|
+((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
|
|
@@ -20,7 +20,8 @@ export default function (beginA: number, rotateA: number, cx: number, cy: number
|
|
|
20
20
|
rotateA *= -1
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const temp: number[] = []
|
|
24
|
+
let p: number[]
|
|
24
25
|
|
|
25
26
|
// 内部
|
|
26
27
|
p = rotate(0, 0, beginA, r1, 0)
|
|
@@ -3,7 +3,7 @@ import type CanvasConfigType from "../../../types/CanvasConfig"
|
|
|
3
3
|
import arc from "./arc"
|
|
4
4
|
|
|
5
5
|
// 文字统一设置方法
|
|
6
|
-
export
|
|
6
|
+
export const initText = function (
|
|
7
7
|
painter: CanvasRenderingContext2D,
|
|
8
8
|
config: CanvasConfigType,
|
|
9
9
|
x: number,
|
|
@@ -25,7 +25,7 @@ export let initText = function (
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// 画弧统一设置方法
|
|
28
|
-
export
|
|
28
|
+
export const initArc = function (
|
|
29
29
|
painter: CanvasRenderingContext2D,
|
|
30
30
|
config: CanvasConfigType,
|
|
31
31
|
cx: number,
|
|
@@ -36,7 +36,7 @@ export let initArc = function (
|
|
|
36
36
|
deg: number
|
|
37
37
|
) {
|
|
38
38
|
if (r1 > r2) {
|
|
39
|
-
|
|
39
|
+
const temp = r1
|
|
40
40
|
r1 = r2
|
|
41
41
|
r2 = temp
|
|
42
42
|
}
|
|
@@ -132,7 +132,7 @@ export let initArc = function (
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
// 画圆统一设置方法
|
|
135
|
-
export
|
|
135
|
+
export const initCircle = function (
|
|
136
136
|
painter: CanvasRenderingContext2D,
|
|
137
137
|
cx: number,
|
|
138
138
|
cy: number,
|
|
@@ -145,7 +145,7 @@ export let initCircle = function (
|
|
|
145
145
|
};
|
|
146
146
|
|
|
147
147
|
// 画矩形统一设置方法
|
|
148
|
-
export
|
|
148
|
+
export const initRect = function (
|
|
149
149
|
painter: CanvasRenderingContext2D,
|
|
150
150
|
x: number,
|
|
151
151
|
y: number,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// 线性渐变
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export const linearGradient = function (painter: CanvasRenderingContext2D, x0: number, y0: number, x1: number, y1: number) {
|
|
3
|
+
const gradient = painter.createLinearGradient(x0, y0, x1, y1)
|
|
4
|
+
const enhanceGradient = {
|
|
5
5
|
"value": function () {
|
|
6
6
|
return gradient
|
|
7
7
|
},
|
|
@@ -14,9 +14,9 @@ export let linearGradient = function (painter: CanvasRenderingContext2D, x0: num
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// 环形渐变
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
export const radialGradient = function (painter: CanvasRenderingContext2D, cx: number, cy: number, r: number) {
|
|
18
|
+
const gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r)
|
|
19
|
+
const enhanceGradient = {
|
|
20
20
|
"value": function () {
|
|
21
21
|
return gradient
|
|
22
22
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type CanvasConfigType from "../../../types/CanvasConfig"
|
|
2
|
+
import type CanvasOptsType from '../../../types/CanvasOpts'
|
|
2
3
|
|
|
3
4
|
import PainterRender from "./painter"
|
|
4
5
|
import assemble from "../assemble"
|
|
@@ -6,7 +7,7 @@ import { linearGradient, radialGradient } from "./gradient"
|
|
|
6
7
|
import { initText } from './config'
|
|
7
8
|
|
|
8
9
|
// 属性名向下兼容
|
|
9
|
-
|
|
10
|
+
const oldAttrName = {
|
|
10
11
|
"font-size": "fontSize",
|
|
11
12
|
"font-family": "fontFamily",
|
|
12
13
|
"font-weight": "fontWeight",
|
|
@@ -24,10 +25,10 @@ class Canvas extends PainterRender {
|
|
|
24
25
|
// 2023年7月6日 于南京
|
|
25
26
|
private __regionAssemble = assemble(0, 255, 10, 3)
|
|
26
27
|
|
|
27
|
-
constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement) {
|
|
28
|
+
constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement, opts: CanvasOptsType = {}) {
|
|
28
29
|
super(
|
|
29
30
|
ViewCanvas,
|
|
30
|
-
|
|
31
|
+
opts,
|
|
31
32
|
RegionCanvas ? new PainterRender(RegionCanvas, {
|
|
32
33
|
willReadFrequently: true,
|
|
33
34
|
}) : null, true
|
|
@@ -37,8 +38,8 @@ class Canvas extends PainterRender {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
config(configs: CanvasConfigType) {
|
|
40
|
-
for (
|
|
41
|
-
|
|
41
|
+
for (const key in configs) {
|
|
42
|
+
const _key = oldAttrName[key] || key
|
|
42
43
|
this.useConfig(_key, configs[key])
|
|
43
44
|
}
|
|
44
45
|
|
|
@@ -56,7 +57,7 @@ class Canvas extends PainterRender {
|
|
|
56
57
|
if (this.__region) {
|
|
57
58
|
if (regionName) {
|
|
58
59
|
if (this.__regionList[regionName] == void 0) {
|
|
59
|
-
|
|
60
|
+
const tempColor = this.__regionAssemble()
|
|
60
61
|
this.__regionList[regionName] =
|
|
61
62
|
"rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")"
|
|
62
63
|
}
|
|
@@ -73,19 +74,19 @@ class Canvas extends PainterRender {
|
|
|
73
74
|
|
|
74
75
|
// 获取当前事件触发的区域名称
|
|
75
76
|
getRegion(x: number, y: number): Promise<string> {
|
|
76
|
-
return new Promise((resolve
|
|
77
|
-
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
const imgData = this.__region ? this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
|
|
78
79
|
data: [0, 0, 0, 0]
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
// 获取点击点的颜色
|
|
82
83
|
let currentRGBA = imgData.data
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
const doit = () => {
|
|
85
86
|
if (this.__region) {
|
|
86
87
|
|
|
87
88
|
// 查找当前点击的区域
|
|
88
|
-
for (
|
|
89
|
+
for (const key in this.__regionList) {
|
|
89
90
|
if (
|
|
90
91
|
"rgb(" +
|
|
91
92
|
currentRGBA[0] +
|
|
@@ -126,7 +127,7 @@ class Canvas extends PainterRender {
|
|
|
126
127
|
initText(this.painter, this.__specialConfig, 0, 0, 0)
|
|
127
128
|
|
|
128
129
|
// 虽然我们限制了只可以输入字符串,可是不代表所有环境都可以保证,为了确保方法不失效,强转成字符串
|
|
129
|
-
|
|
130
|
+
const width = this.painter.measureText(text + "").width
|
|
130
131
|
|
|
131
132
|
this.painter.restore()
|
|
132
133
|
|
|
@@ -158,7 +159,7 @@ class Canvas extends PainterRender {
|
|
|
158
159
|
|
|
159
160
|
// 获取指定位置颜色
|
|
160
161
|
getColor(x: number, y: number) {
|
|
161
|
-
|
|
162
|
+
const currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data
|
|
162
163
|
return (
|
|
163
164
|
"rgba(" +
|
|
164
165
|
currentRGBA[0] +
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import type { arcCapType } from '../../../types/painterConfig'
|
|
2
|
+
import type CanvasOptsType from '../../../types/CanvasOpts'
|
|
2
3
|
|
|
3
4
|
import { initText, initArc, initCircle, initRect } from './config'
|
|
4
5
|
import texts from './texts'
|
|
5
6
|
|
|
6
|
-
interface OptsType {
|
|
7
|
-
|
|
8
|
-
// https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently
|
|
9
|
-
willReadFrequently?: boolean
|
|
10
|
-
|
|
11
|
-
alpha?: boolean
|
|
12
|
-
|
|
13
|
-
storage?: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
7
|
class Painter {
|
|
17
8
|
|
|
18
9
|
painter: CanvasRenderingContext2D
|
|
@@ -72,7 +63,7 @@ class Painter {
|
|
|
72
63
|
|
|
73
64
|
}
|
|
74
65
|
|
|
75
|
-
constructor(canvas: HTMLCanvasElement, opts:
|
|
66
|
+
constructor(canvas: HTMLCanvasElement, opts: CanvasOptsType = {}, region?: Painter, isPainter = false) {
|
|
76
67
|
this.painter = canvas.getContext("2d", opts) as CanvasRenderingContext2D
|
|
77
68
|
this.__region = region
|
|
78
69
|
this.__isPainter = isPainter
|
|
@@ -175,7 +166,7 @@ class Painter {
|
|
|
175
166
|
this.painter.save()
|
|
176
167
|
initText(this.painter, this.__specialConfig, x, y, deg)
|
|
177
168
|
|
|
178
|
-
|
|
169
|
+
const height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, (content, top) => {
|
|
179
170
|
this.painter.fillText(content, 0, top)
|
|
180
171
|
})
|
|
181
172
|
|
|
@@ -191,7 +182,7 @@ class Painter {
|
|
|
191
182
|
this.painter.save()
|
|
192
183
|
initText(this.painter, this.__specialConfig, x, y, deg)
|
|
193
184
|
|
|
194
|
-
|
|
185
|
+
const height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, (content, top) => {
|
|
195
186
|
this.painter.strokeText(content, 0, top)
|
|
196
187
|
})
|
|
197
188
|
|
|
@@ -207,7 +198,7 @@ class Painter {
|
|
|
207
198
|
this.painter.save()
|
|
208
199
|
initText(this.painter, this.__specialConfig, x, y, deg)
|
|
209
200
|
|
|
210
|
-
|
|
201
|
+
const height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, (content, top) => {
|
|
211
202
|
this.painter.fillText(content, 0, top)
|
|
212
203
|
this.painter.strokeText(content, 0, top)
|
|
213
204
|
})
|
|
@@ -6,7 +6,7 @@ export default function (normal: boolean, x: number, y: number, z: number, radiu
|
|
|
6
6
|
|
|
7
7
|
let beginX: number, beginZ: number
|
|
8
8
|
if (num == 4) {
|
|
9
|
-
|
|
9
|
+
const temp = radius / 1.414
|
|
10
10
|
beginX = x + temp
|
|
11
11
|
beginZ = z + temp
|
|
12
12
|
|
|
@@ -15,7 +15,9 @@ export default function (normal: boolean, x: number, y: number, z: number, radiu
|
|
|
15
15
|
beginZ = z
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
let point = [beginX, beginZ]
|
|
18
|
+
let point = [beginX, beginZ]
|
|
19
|
+
const points = []
|
|
20
|
+
const deg = Math.PI * 2 / num
|
|
19
21
|
for (let i = 0; i < num; i++) {
|
|
20
22
|
|
|
21
23
|
points.push(x, y, z)
|