vislite 0.6.0-alpha.2 → 0.7.0-alpha.0
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/CHANGELOG +10 -1
- package/README.md +12 -4
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +2 -2
- package/lib/Canvas/index.umd.min.js +2 -2
- 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 +2 -2
- 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 +2 -2
- package/lib/OralCanvas/index.es.min.js +2 -2
- package/lib/OralWebGL/index.es.js +2 -2
- package/lib/OralWebGL/index.es.min.js +2 -2
- package/lib/SVG/index.umd.js +2 -2
- 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 +2 -2
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +2 -2
- package/lib/TreeLayout/index.umd.min.js +2 -2
- package/lib/WebGL/index.umd.js +2 -2
- package/lib/WebGL/index.umd.min.js +2 -2
- package/lib/animation/index.umd.js +2 -2
- 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 +2 -2
- package/lib/getWebGLContext/index.umd.min.js +2 -2
- package/lib/index.umd.js +2 -2
- package/lib/index.umd.min.js +2 -2
- package/lib/move/index.umd.js +2 -2
- package/lib/move/index.umd.min.js +2 -2
- package/lib/resizeObserver/index.umd.js +2 -2
- 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 +2 -2
- package/lib/viewHandler/index.umd.min.js +2 -2
- package/package/TreeLayout/index.ts +2 -2
- package/package.json +1 -1
- package/src/Matrix4/index.ts +84 -84
- package/src/common/canvas/index.ts +177 -177
- package/src/common/svg/index.ts +356 -356
- package/src/layout/TreeLayout.ts +186 -186
- package/src/ruler.ts +209 -209
- package/types/Canvas.d.ts +308 -308
- package/types/CanvasOpts.d.ts +9 -9
- package/types/Matrix4.d.ts +47 -47
- package/types/SVGConfig.d.ts +79 -76
- package/uni-app/ui-canvas.vue +9 -31
- package/.editorconfig +0 -19
- package/.eslintrc.js +0 -24
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.7.0-alpha.0
|
|
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: Fri Dec 29 2023 22:39:54 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.
|
|
2
|
+
* VISLite JavaScript Library v0.7.0-alpha.0
|
|
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: Fri Dec 29 2023 22:39:54 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.
|
|
2
|
+
* VISLite JavaScript Library v0.7.0-alpha.0
|
|
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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
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();
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import TreeLayout from "../../src/layout/TreeLayout"
|
|
2
|
-
|
|
1
|
+
import TreeLayout from "../../src/layout/TreeLayout"
|
|
2
|
+
|
|
3
3
|
export default TreeLayout
|
package/package.json
CHANGED
package/src/Matrix4/index.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import type Matrix4Type from '../../types/Matrix4'
|
|
2
|
-
|
|
3
|
-
// 两个4x4矩阵相乘
|
|
4
|
-
// 或矩阵和齐次坐标相乘
|
|
5
|
-
const _multiply = function (matrix4: number[], param: number[]) {
|
|
6
|
-
const newParam: number[] = []
|
|
7
|
-
for (let i = 0; i < 4; i++)
|
|
8
|
-
for (let j = 0; j < param.length / 4; j++)
|
|
9
|
-
newParam[j * 4 + i] =
|
|
10
|
-
matrix4[i] * param[j * 4] +
|
|
11
|
-
matrix4[i + 4] * param[j * 4 + 1] +
|
|
12
|
-
matrix4[i + 8] * param[j * 4 + 2] +
|
|
13
|
-
matrix4[i + 12] * param[j * 4 + 3]
|
|
14
|
-
return newParam
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
import _move from './move'
|
|
18
|
-
import _rotate from './rotate'
|
|
19
|
-
import _scale from './scale'
|
|
20
|
-
import _transform from './transform'
|
|
21
|
-
|
|
22
|
-
// 列主序存储的4x4矩阵
|
|
23
|
-
|
|
24
|
-
const __initMatrix4 = [
|
|
25
|
-
1, 0, 0, 0,
|
|
26
|
-
0, 1, 0, 0,
|
|
27
|
-
0, 0, 1, 0,
|
|
28
|
-
0, 0, 0, 1
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
class Matrix4 implements Matrix4Type {
|
|
32
|
-
readonly name: string = 'Matrix4'
|
|
33
|
-
|
|
34
|
-
private __matrix4: number[]
|
|
35
|
-
|
|
36
|
-
constructor(initMatrix4: number[] = __initMatrix4) {
|
|
37
|
-
this.__matrix4 = initMatrix4
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 设置内置矩阵
|
|
41
|
-
setValue(initMatrix4: number[] = __initMatrix4) {
|
|
42
|
-
this.__matrix4 = initMatrix4
|
|
43
|
-
return this
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 移动
|
|
47
|
-
move(dis: number, a: number, b: number, c: number = 0) {
|
|
48
|
-
this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4)
|
|
49
|
-
return this
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 旋转
|
|
53
|
-
rotate(deg: number, a1: number, b1: number, c1?: number, a2?: number, b2?: number, c2?: number) {
|
|
54
|
-
const matrix4s = _transform(a1, b1, c1, a2, b2, c2)
|
|
55
|
-
this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4)
|
|
56
|
-
return this
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 缩放
|
|
60
|
-
scale(xTimes: number, yTimes: number, zTimes: number, cx: number = 0, cy: number = 0, cz: number = 0) {
|
|
61
|
-
this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4)
|
|
62
|
-
return this
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// 乘法
|
|
66
|
-
// 可以传入一个矩阵(matrix4,flag)
|
|
67
|
-
multiply(newMatrix4: number[], flag: boolean = false) {
|
|
68
|
-
this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4)
|
|
69
|
-
return this
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 对一个坐标应用变换
|
|
73
|
-
// 齐次坐标(x,y,z,w)
|
|
74
|
-
use(x: number, y: number, z: number = 0, w: number = 1): [number, number, number, number] {
|
|
75
|
-
// w为0表示点位于无穷远处,忽略
|
|
76
|
-
return _multiply(this.__matrix4, [x, y, z, w]) as [number, number, number, number]
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// 矩阵的值
|
|
80
|
-
value() {
|
|
81
|
-
return this.__matrix4
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
1
|
+
import type Matrix4Type from '../../types/Matrix4'
|
|
2
|
+
|
|
3
|
+
// 两个4x4矩阵相乘
|
|
4
|
+
// 或矩阵和齐次坐标相乘
|
|
5
|
+
const _multiply = function (matrix4: number[], param: number[]) {
|
|
6
|
+
const newParam: number[] = []
|
|
7
|
+
for (let i = 0; i < 4; i++)
|
|
8
|
+
for (let j = 0; j < param.length / 4; j++)
|
|
9
|
+
newParam[j * 4 + i] =
|
|
10
|
+
matrix4[i] * param[j * 4] +
|
|
11
|
+
matrix4[i + 4] * param[j * 4 + 1] +
|
|
12
|
+
matrix4[i + 8] * param[j * 4 + 2] +
|
|
13
|
+
matrix4[i + 12] * param[j * 4 + 3]
|
|
14
|
+
return newParam
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
import _move from './move'
|
|
18
|
+
import _rotate from './rotate'
|
|
19
|
+
import _scale from './scale'
|
|
20
|
+
import _transform from './transform'
|
|
21
|
+
|
|
22
|
+
// 列主序存储的4x4矩阵
|
|
23
|
+
|
|
24
|
+
const __initMatrix4 = [
|
|
25
|
+
1, 0, 0, 0,
|
|
26
|
+
0, 1, 0, 0,
|
|
27
|
+
0, 0, 1, 0,
|
|
28
|
+
0, 0, 0, 1
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
class Matrix4 implements Matrix4Type {
|
|
32
|
+
readonly name: string = 'Matrix4'
|
|
33
|
+
|
|
34
|
+
private __matrix4: number[]
|
|
35
|
+
|
|
36
|
+
constructor(initMatrix4: number[] = __initMatrix4) {
|
|
37
|
+
this.__matrix4 = initMatrix4
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 设置内置矩阵
|
|
41
|
+
setValue(initMatrix4: number[] = __initMatrix4) {
|
|
42
|
+
this.__matrix4 = initMatrix4
|
|
43
|
+
return this
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 移动
|
|
47
|
+
move(dis: number, a: number, b: number, c: number = 0) {
|
|
48
|
+
this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4)
|
|
49
|
+
return this
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 旋转
|
|
53
|
+
rotate(deg: number, a1: number, b1: number, c1?: number, a2?: number, b2?: number, c2?: number) {
|
|
54
|
+
const matrix4s = _transform(a1, b1, c1, a2, b2, c2)
|
|
55
|
+
this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4)
|
|
56
|
+
return this
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 缩放
|
|
60
|
+
scale(xTimes: number, yTimes: number, zTimes: number, cx: number = 0, cy: number = 0, cz: number = 0) {
|
|
61
|
+
this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4)
|
|
62
|
+
return this
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 乘法
|
|
66
|
+
// 可以传入一个矩阵(matrix4,flag)
|
|
67
|
+
multiply(newMatrix4: number[], flag: boolean = false) {
|
|
68
|
+
this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4)
|
|
69
|
+
return this
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 对一个坐标应用变换
|
|
73
|
+
// 齐次坐标(x,y,z,w)
|
|
74
|
+
use(x: number, y: number, z: number = 0, w: number = 1): [number, number, number, number] {
|
|
75
|
+
// w为0表示点位于无穷远处,忽略
|
|
76
|
+
return _multiply(this.__matrix4, [x, y, z, w]) as [number, number, number, number]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 矩阵的值
|
|
80
|
+
value() {
|
|
81
|
+
return this.__matrix4
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
85
|
export default Matrix4
|
|
@@ -1,177 +1,177 @@
|
|
|
1
|
-
import type CanvasConfigType from "../../../types/CanvasConfig"
|
|
2
|
-
import type CanvasOptsType from '../../../types/CanvasOpts'
|
|
3
|
-
|
|
4
|
-
import PainterRender from "./painter"
|
|
5
|
-
import assemble from "../assemble"
|
|
6
|
-
import { linearGradient, radialGradient } from "./gradient"
|
|
7
|
-
import { initText } from './config'
|
|
8
|
-
|
|
9
|
-
// 属性名向下兼容
|
|
10
|
-
const oldAttrName = {
|
|
11
|
-
"font-size": "fontSize",
|
|
12
|
-
"font-family": "fontFamily",
|
|
13
|
-
"font-weight": "fontWeight",
|
|
14
|
-
"font-style": "fontStyle",
|
|
15
|
-
"arc-start-cap": "arcStartCap",
|
|
16
|
-
"arc-end-cap": "arcEndCap",
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
class Canvas extends PainterRender {
|
|
20
|
-
readonly name: string = "Canvas"
|
|
21
|
-
|
|
22
|
-
private __regionList = {} //区域映射表
|
|
23
|
-
|
|
24
|
-
// 步长由1改为10是为了优化区域计算有时候出错问题
|
|
25
|
-
// 2023年7月6日 于南京
|
|
26
|
-
private __regionAssemble = assemble(0, 255, 10, 3)
|
|
27
|
-
|
|
28
|
-
constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement, opts: CanvasOptsType = {}) {
|
|
29
|
-
super(
|
|
30
|
-
ViewCanvas,
|
|
31
|
-
opts,
|
|
32
|
-
RegionCanvas ? new PainterRender(RegionCanvas, {
|
|
33
|
-
willReadFrequently: true,
|
|
34
|
-
}) : null, true
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
this.setRegion("")
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
config(configs: CanvasConfigType) {
|
|
41
|
-
for (const key in configs) {
|
|
42
|
-
const _key = oldAttrName[key] || key
|
|
43
|
-
this.useConfig(_key, configs[key])
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return this
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// 是否绘制的内容只需要进行区域记录
|
|
50
|
-
onlyRegion(flag: boolean) {
|
|
51
|
-
this.__onlyRegion = flag
|
|
52
|
-
return this
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// 设置当前绘制区域名称
|
|
56
|
-
setRegion(regionName: string | number) {
|
|
57
|
-
if (this.__region) {
|
|
58
|
-
if (regionName) {
|
|
59
|
-
if (this.__regionList[regionName] == void 0) {
|
|
60
|
-
const tempColor = this.__regionAssemble()
|
|
61
|
-
this.__regionList[regionName] =
|
|
62
|
-
"rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")"
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
|
|
66
|
-
this.__region.useConfig("strokeStyle", this.__regionList[regionName])
|
|
67
|
-
} else {
|
|
68
|
-
this.__region.useConfig("fillStyle", "#000000") &&
|
|
69
|
-
this.__region.useConfig("strokeStyle", "#000000")
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return this
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 获取当前事件触发的区域名称
|
|
76
|
-
getRegion(x: number, y: number): Promise<string> {
|
|
77
|
-
return new Promise((resolve) => {
|
|
78
|
-
const imgData = this.__region ? this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
|
|
79
|
-
data: [0, 0, 0, 0]
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// 获取点击点的颜色
|
|
83
|
-
let currentRGBA = imgData.data
|
|
84
|
-
|
|
85
|
-
const doit = () => {
|
|
86
|
-
if (this.__region) {
|
|
87
|
-
|
|
88
|
-
// 查找当前点击的区域
|
|
89
|
-
for (const key in this.__regionList) {
|
|
90
|
-
if (
|
|
91
|
-
"rgb(" +
|
|
92
|
-
currentRGBA[0] +
|
|
93
|
-
"," +
|
|
94
|
-
currentRGBA[1] +
|
|
95
|
-
"," +
|
|
96
|
-
currentRGBA[2] +
|
|
97
|
-
")" ==
|
|
98
|
-
this.__regionList[key]
|
|
99
|
-
) {
|
|
100
|
-
resolve(key)
|
|
101
|
-
break
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
resolve("")
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// 如果有值
|
|
110
|
-
if (currentRGBA) {
|
|
111
|
-
doit()
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// 否则就是在Promise中
|
|
115
|
-
else {
|
|
116
|
-
(imgData as any).then((data: Uint8ClampedArray) => {
|
|
117
|
-
currentRGBA = data
|
|
118
|
-
doit()
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
textWidth(text: string) {
|
|
125
|
-
this.painter.save()
|
|
126
|
-
|
|
127
|
-
initText(this.painter, this.__specialConfig, 0, 0, 0)
|
|
128
|
-
|
|
129
|
-
// 虽然我们限制了只可以输入字符串,可是不代表所有环境都可以保证,为了确保方法不失效,强转成字符串
|
|
130
|
-
const width = this.painter.measureText(text + "").width
|
|
131
|
-
|
|
132
|
-
this.painter.restore()
|
|
133
|
-
|
|
134
|
-
return width
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// 获取原始画笔
|
|
138
|
-
getContext(isRegion = false) {
|
|
139
|
-
return isRegion ? (this.__region ? this.__region.painter : null) : this.painter
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// 获取画布信息
|
|
143
|
-
getInfo() {
|
|
144
|
-
return {
|
|
145
|
-
width: this.painter.canvas.width,
|
|
146
|
-
height: this.painter.canvas.height
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// 线性渐变
|
|
151
|
-
createLinearGradient(x0: number, y0: number, x1: number, y1: number) {
|
|
152
|
-
return linearGradient(this.painter, x0, y0, x1, y1)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// 环形渐变
|
|
156
|
-
createRadialGradient(cx: number, cy: number, r: number) {
|
|
157
|
-
return radialGradient(this.painter, cx, cy, r)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// 获取指定位置颜色
|
|
161
|
-
getColor(x: number, y: number) {
|
|
162
|
-
const currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data
|
|
163
|
-
return (
|
|
164
|
-
"rgba(" +
|
|
165
|
-
currentRGBA[0] +
|
|
166
|
-
"," +
|
|
167
|
-
currentRGBA[1] +
|
|
168
|
-
"," +
|
|
169
|
-
currentRGBA[2] +
|
|
170
|
-
"," +
|
|
171
|
-
currentRGBA[3] +
|
|
172
|
-
")"
|
|
173
|
-
)
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export default Canvas
|
|
1
|
+
import type CanvasConfigType from "../../../types/CanvasConfig"
|
|
2
|
+
import type CanvasOptsType from '../../../types/CanvasOpts'
|
|
3
|
+
|
|
4
|
+
import PainterRender from "./painter"
|
|
5
|
+
import assemble from "../assemble"
|
|
6
|
+
import { linearGradient, radialGradient } from "./gradient"
|
|
7
|
+
import { initText } from './config'
|
|
8
|
+
|
|
9
|
+
// 属性名向下兼容
|
|
10
|
+
const oldAttrName = {
|
|
11
|
+
"font-size": "fontSize",
|
|
12
|
+
"font-family": "fontFamily",
|
|
13
|
+
"font-weight": "fontWeight",
|
|
14
|
+
"font-style": "fontStyle",
|
|
15
|
+
"arc-start-cap": "arcStartCap",
|
|
16
|
+
"arc-end-cap": "arcEndCap",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class Canvas extends PainterRender {
|
|
20
|
+
readonly name: string = "Canvas"
|
|
21
|
+
|
|
22
|
+
private __regionList = {} //区域映射表
|
|
23
|
+
|
|
24
|
+
// 步长由1改为10是为了优化区域计算有时候出错问题
|
|
25
|
+
// 2023年7月6日 于南京
|
|
26
|
+
private __regionAssemble = assemble(0, 255, 10, 3)
|
|
27
|
+
|
|
28
|
+
constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement, opts: CanvasOptsType = {}) {
|
|
29
|
+
super(
|
|
30
|
+
ViewCanvas,
|
|
31
|
+
opts,
|
|
32
|
+
RegionCanvas ? new PainterRender(RegionCanvas, {
|
|
33
|
+
willReadFrequently: true,
|
|
34
|
+
}) : null, true
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
this.setRegion("")
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
config(configs: CanvasConfigType) {
|
|
41
|
+
for (const key in configs) {
|
|
42
|
+
const _key = oldAttrName[key] || key
|
|
43
|
+
this.useConfig(_key, configs[key])
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return this
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 是否绘制的内容只需要进行区域记录
|
|
50
|
+
onlyRegion(flag: boolean) {
|
|
51
|
+
this.__onlyRegion = flag
|
|
52
|
+
return this
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 设置当前绘制区域名称
|
|
56
|
+
setRegion(regionName: string | number) {
|
|
57
|
+
if (this.__region) {
|
|
58
|
+
if (regionName) {
|
|
59
|
+
if (this.__regionList[regionName] == void 0) {
|
|
60
|
+
const tempColor = this.__regionAssemble()
|
|
61
|
+
this.__regionList[regionName] =
|
|
62
|
+
"rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")"
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
|
|
66
|
+
this.__region.useConfig("strokeStyle", this.__regionList[regionName])
|
|
67
|
+
} else {
|
|
68
|
+
this.__region.useConfig("fillStyle", "#000000") &&
|
|
69
|
+
this.__region.useConfig("strokeStyle", "#000000")
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return this
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 获取当前事件触发的区域名称
|
|
76
|
+
getRegion(x: number, y: number): Promise<string> {
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
const imgData = this.__region ? this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
|
|
79
|
+
data: [0, 0, 0, 0]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 获取点击点的颜色
|
|
83
|
+
let currentRGBA = imgData.data
|
|
84
|
+
|
|
85
|
+
const doit = () => {
|
|
86
|
+
if (this.__region) {
|
|
87
|
+
|
|
88
|
+
// 查找当前点击的区域
|
|
89
|
+
for (const key in this.__regionList) {
|
|
90
|
+
if (
|
|
91
|
+
"rgb(" +
|
|
92
|
+
currentRGBA[0] +
|
|
93
|
+
"," +
|
|
94
|
+
currentRGBA[1] +
|
|
95
|
+
"," +
|
|
96
|
+
currentRGBA[2] +
|
|
97
|
+
")" ==
|
|
98
|
+
this.__regionList[key]
|
|
99
|
+
) {
|
|
100
|
+
resolve(key)
|
|
101
|
+
break
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
resolve("")
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// 如果有值
|
|
110
|
+
if (currentRGBA) {
|
|
111
|
+
doit()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 否则就是在Promise中
|
|
115
|
+
else {
|
|
116
|
+
(imgData as any).then((data: Uint8ClampedArray) => {
|
|
117
|
+
currentRGBA = data
|
|
118
|
+
doit()
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
textWidth(text: string) {
|
|
125
|
+
this.painter.save()
|
|
126
|
+
|
|
127
|
+
initText(this.painter, this.__specialConfig, 0, 0, 0)
|
|
128
|
+
|
|
129
|
+
// 虽然我们限制了只可以输入字符串,可是不代表所有环境都可以保证,为了确保方法不失效,强转成字符串
|
|
130
|
+
const width = this.painter.measureText(text + "").width
|
|
131
|
+
|
|
132
|
+
this.painter.restore()
|
|
133
|
+
|
|
134
|
+
return width
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 获取原始画笔
|
|
138
|
+
getContext(isRegion = false) {
|
|
139
|
+
return isRegion ? (this.__region ? this.__region.painter : null) : this.painter
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 获取画布信息
|
|
143
|
+
getInfo() {
|
|
144
|
+
return {
|
|
145
|
+
width: this.painter.canvas.width,
|
|
146
|
+
height: this.painter.canvas.height
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 线性渐变
|
|
151
|
+
createLinearGradient(x0: number, y0: number, x1: number, y1: number) {
|
|
152
|
+
return linearGradient(this.painter, x0, y0, x1, y1)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 环形渐变
|
|
156
|
+
createRadialGradient(cx: number, cy: number, r: number) {
|
|
157
|
+
return radialGradient(this.painter, cx, cy, r)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 获取指定位置颜色
|
|
161
|
+
getColor(x: number, y: number) {
|
|
162
|
+
const currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data
|
|
163
|
+
return (
|
|
164
|
+
"rgba(" +
|
|
165
|
+
currentRGBA[0] +
|
|
166
|
+
"," +
|
|
167
|
+
currentRGBA[1] +
|
|
168
|
+
"," +
|
|
169
|
+
currentRGBA[2] +
|
|
170
|
+
"," +
|
|
171
|
+
currentRGBA[3] +
|
|
172
|
+
")"
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export default Canvas
|