vislite 0.7.0-alpha.0 → 0.7.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 +8 -3
- package/README.md +20 -1
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +4 -4
- 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 +69 -8
- package/lib/Geometry/index.umd.min.js +3 -3
- 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 +3 -3
- package/lib/OralCanvas/index.es.min.js +3 -3
- package/lib/OralWebGL/index.es.js +21 -18
- package/lib/OralWebGL/index.es.min.js +3 -3
- package/lib/SVG/index.umd.js +2 -2
- package/lib/SVG/index.umd.min.js +2 -2
- package/lib/Shader/index.umd.js +3 -2
- package/lib/Shader/index.umd.min.js +3 -3
- package/lib/Texture/index.umd.js +2 -2
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +13 -11
- package/lib/TreeLayout/index.umd.min.js +3 -3
- package/lib/WebGL/index.umd.js +22 -19
- package/lib/WebGL/index.umd.min.js +3 -3
- 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 +4 -4
- package/lib/getWebGLContext/index.umd.min.js +3 -3
- package/lib/index.umd.js +104 -38
- 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 +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 +4 -4
- package/lib/ruler/index.umd.min.js +3 -3
- 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.json +1 -1
- package/src/Canvas.ts +70 -70
- package/src/Geometry.ts +126 -82
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/transform.ts +64 -64
- package/src/WebGL.ts +66 -66
- package/src/common/assemble.ts +22 -22
- package/src/common/canvas/index.ts +177 -177
- package/src/common/canvas/painter.ts +419 -417
- package/src/common/geometry/prism-vertical.ts +40 -40
- package/src/common/geometry/tool/rotateLine.ts +36 -0
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +190 -186
- package/src/common/svg/tool.ts +44 -44
- package/src/common/tree/toInnerTree.ts +59 -57
- package/src/common/tree/toPlainTree.ts +132 -132
- package/src/common/webgl/buffer.ts +79 -79
- package/src/common/webgl/doDraw.ts +108 -108
- package/src/common/webgl/getWebGLContext.ts +28 -28
- package/src/common/webgl/index.ts +226 -224
- package/src/common/webgl/shader.ts +75 -75
- package/src/common/webgl/texture.ts +97 -97
- package/src/layout/TreeLayout.ts +188 -186
- package/src/resizeObserver.ts +37 -37
- package/src/ruler.ts +209 -209
- package/src/viewHandler.ts +160 -158
- package/types/Canvas.d.ts +308 -308
- package/types/Geometry.d.ts +65 -40
- package/types/TreeConfig.d.ts +36 -24
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import rotate from '../../rotate'
|
|
2
|
-
|
|
3
|
-
// 棱柱垂直部分
|
|
4
|
-
|
|
5
|
-
export default function (normal: boolean, x: number, y: number, z: number, radius: number, height: number, num: number) {
|
|
6
|
-
const points = []
|
|
7
|
-
let beginPosition: [number, number]
|
|
8
|
-
|
|
9
|
-
if (num == 4) {
|
|
10
|
-
beginPosition = rotate(x, z, Math.PI * 0.25, x - radius, z)
|
|
11
|
-
} else {
|
|
12
|
-
beginPosition = [x + radius, z]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const deg = Math.PI * 2 / num, degHalf = Math.PI * 2 / (num * 2)
|
|
16
|
-
|
|
17
|
-
let endPosition: [number, number], normalPosition = []
|
|
18
|
-
for (let i = 0; i < num; i++) {
|
|
19
|
-
|
|
20
|
-
endPosition = rotate(x, z, deg, ...beginPosition)
|
|
21
|
-
|
|
22
|
-
if (normal) {
|
|
23
|
-
const halfPosition = rotate(x, z, degHalf, ...beginPosition)
|
|
24
|
-
normalPosition = [halfPosition[0], 0, halfPosition[1]]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
28
|
-
points.push(beginPosition[0], y + height, beginPosition[1], ...normalPosition)
|
|
29
|
-
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
30
|
-
|
|
31
|
-
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
32
|
-
points.push(endPosition[0], y, endPosition[1], ...normalPosition)
|
|
33
|
-
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
beginPosition = endPosition
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return points
|
|
40
|
-
}
|
|
1
|
+
import rotate from '../../rotate'
|
|
2
|
+
|
|
3
|
+
// 棱柱垂直部分
|
|
4
|
+
|
|
5
|
+
export default function (normal: boolean, x: number, y: number, z: number, radius: number, height: number, num: number) {
|
|
6
|
+
const points = []
|
|
7
|
+
let beginPosition: [number, number]
|
|
8
|
+
|
|
9
|
+
if (num == 4) {
|
|
10
|
+
beginPosition = rotate(x, z, Math.PI * 0.25, x - radius, z)
|
|
11
|
+
} else {
|
|
12
|
+
beginPosition = [x + radius, z]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const deg = Math.PI * 2 / num, degHalf = Math.PI * 2 / (num * 2)
|
|
16
|
+
|
|
17
|
+
let endPosition: [number, number], normalPosition: [number, number, number] | [] = []
|
|
18
|
+
for (let i = 0; i < num; i++) {
|
|
19
|
+
|
|
20
|
+
endPosition = rotate(x, z, deg, ...beginPosition)
|
|
21
|
+
|
|
22
|
+
if (normal) {
|
|
23
|
+
const halfPosition = rotate(x, z, degHalf, ...beginPosition)
|
|
24
|
+
normalPosition = [halfPosition[0], 0, halfPosition[1]]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
28
|
+
points.push(beginPosition[0], y + height, beginPosition[1], ...normalPosition)
|
|
29
|
+
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
30
|
+
|
|
31
|
+
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
32
|
+
points.push(endPosition[0], y, endPosition[1], ...normalPosition)
|
|
33
|
+
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
beginPosition = endPosition
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return points
|
|
40
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export default function (x: number, y: number, z: number, x2: number, y2: number, z2: number) {
|
|
2
|
+
return (x0: number, y0: number, z0: number, isNormal: boolean) => {
|
|
3
|
+
let sin: number, cos: number, temp: Array<number>
|
|
4
|
+
|
|
5
|
+
// 第一步:归零化
|
|
6
|
+
let _x0 = x0 - (isNormal ? 0 : x), _y0 = y0 - (isNormal ? 0 : y), _z0 = z0 - (isNormal ? 0 : z) // 法向量起点本来就是原点
|
|
7
|
+
const _x2 = x2 - x, _y2 = y2 - y, _z2 = z2 - z
|
|
8
|
+
|
|
9
|
+
// 第二步:围绕OZ轴旋转
|
|
10
|
+
|
|
11
|
+
const __d = Math.sqrt(_x2 * _x2 + _z2 * _z2)
|
|
12
|
+
cos = _x2 / __d
|
|
13
|
+
sin = _z2 / __d
|
|
14
|
+
|
|
15
|
+
const _x2N = _z2 * sin + _x2 * cos
|
|
16
|
+
|
|
17
|
+
const d = Math.sqrt(_y2 * _y2 + _x2N * _x2N)
|
|
18
|
+
cos = _y2 / d
|
|
19
|
+
sin = _x2N / d
|
|
20
|
+
|
|
21
|
+
temp = [_y0, _x0]
|
|
22
|
+
_y0 = temp[0] * cos - temp[1] * sin
|
|
23
|
+
_x0 = temp[0] * sin + temp[1] * cos
|
|
24
|
+
|
|
25
|
+
// 第三步:围绕0Y轴旋转
|
|
26
|
+
cos = _x2 / __d
|
|
27
|
+
sin = _z2 / __d
|
|
28
|
+
|
|
29
|
+
temp = [_x0, _z0]
|
|
30
|
+
_x0 = temp[0] * cos - temp[1] * sin
|
|
31
|
+
_z0 = temp[0] * sin + temp[1] * cos
|
|
32
|
+
|
|
33
|
+
// 第四步:去零化(直接返回)
|
|
34
|
+
return [_x0 + (isNormal ? 0 : x), _y0 + (isNormal ? 0 : y), _z0 + (isNormal ? 0 : z)]
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/common/setStyle.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// 修改样式
|
|
2
|
-
export default function (el: HTMLElement | SVGElement, styles: any) {
|
|
3
|
-
for (const key in styles) {
|
|
4
|
-
el.style[key] = styles[key]
|
|
5
|
-
}
|
|
1
|
+
// 修改样式
|
|
2
|
+
export default function (el: HTMLElement | SVGElement, styles: any) {
|
|
3
|
+
for (const key in styles) {
|
|
4
|
+
el.style[key as any] = styles[key]
|
|
5
|
+
}
|
|
6
6
|
}
|
package/src/common/svg/config.ts
CHANGED
|
@@ -1,186 +1,190 @@
|
|
|
1
|
-
import type SVGConfigType from "../../../types/SVGConfig"
|
|
2
|
-
|
|
3
|
-
import { setAttribute } from "./tool"
|
|
4
|
-
import setStyle from "../setStyle"
|
|
5
|
-
import arc from "../canvas/arc"
|
|
6
|
-
import { toNode } from "./tool"
|
|
7
|
-
|
|
8
|
-
export const initDefs = (el: SVGElement) => {
|
|
9
|
-
const defs = el.getElementsByTagName('defs')
|
|
10
|
-
if (defs.length <= 0) {
|
|
11
|
-
const newDefs = toNode("defs")
|
|
12
|
-
el.appendChild(newDefs)
|
|
13
|
-
return newDefs
|
|
14
|
-
} else {
|
|
15
|
-
return defs[0]
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// 文字统一设置方法
|
|
20
|
-
export const initText = (
|
|
21
|
-
el: SVGElement,
|
|
22
|
-
config: SVGConfigType,
|
|
23
|
-
x: number,
|
|
24
|
-
y: number,
|
|
25
|
-
deg: number
|
|
26
|
-
) => {
|
|
27
|
-
if (el.nodeName.toLowerCase() !== "text") throw new Error("Need a <text> !")
|
|
28
|
-
|
|
29
|
-
// 垂直对齐采用dy实现
|
|
30
|
-
setAttribute(
|
|
31
|
-
el,
|
|
32
|
-
"dy",
|
|
33
|
-
{
|
|
34
|
-
top: config["fontSize"] * 0.5,
|
|
35
|
-
middle: 0,
|
|
36
|
-
bottom: -config["fontSize"] * 0.5,
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (config.arcStartCap == "
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
1
|
+
import type SVGConfigType from "../../../types/SVGConfig"
|
|
2
|
+
|
|
3
|
+
import { setAttribute } from "./tool"
|
|
4
|
+
import setStyle from "../setStyle"
|
|
5
|
+
import arc from "../canvas/arc"
|
|
6
|
+
import { toNode } from "./tool"
|
|
7
|
+
|
|
8
|
+
export const initDefs = (el: SVGElement) => {
|
|
9
|
+
const defs = el.getElementsByTagName('defs')
|
|
10
|
+
if (defs.length <= 0) {
|
|
11
|
+
const newDefs = toNode("defs")
|
|
12
|
+
el.appendChild(newDefs)
|
|
13
|
+
return newDefs
|
|
14
|
+
} else {
|
|
15
|
+
return defs[0]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 文字统一设置方法
|
|
20
|
+
export const initText = (
|
|
21
|
+
el: SVGElement,
|
|
22
|
+
config: SVGConfigType,
|
|
23
|
+
x: number,
|
|
24
|
+
y: number,
|
|
25
|
+
deg: number
|
|
26
|
+
) => {
|
|
27
|
+
if (el.nodeName.toLowerCase() !== "text") throw new Error("Need a <text> !")
|
|
28
|
+
|
|
29
|
+
// 垂直对齐采用dy实现
|
|
30
|
+
setAttribute(
|
|
31
|
+
el,
|
|
32
|
+
"dy",
|
|
33
|
+
({
|
|
34
|
+
top: (config["fontSize"] as number) * 0.5,
|
|
35
|
+
middle: 0,
|
|
36
|
+
bottom: -(config["fontSize"] as number) * 0.5,
|
|
37
|
+
} as {
|
|
38
|
+
[key: string]: number
|
|
39
|
+
})[config.textBaseline as string]
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
setStyle(el, {
|
|
43
|
+
// 文字对齐方式
|
|
44
|
+
"text-anchor": ({
|
|
45
|
+
left: "start",
|
|
46
|
+
right: "end",
|
|
47
|
+
center: "middle",
|
|
48
|
+
} as {
|
|
49
|
+
[key: string]: string
|
|
50
|
+
})[config.textAlign as string],
|
|
51
|
+
"dominant-baseline": "central",
|
|
52
|
+
|
|
53
|
+
// 文字大小和字体设置
|
|
54
|
+
"font-size": config["fontSize"] + "px",
|
|
55
|
+
"font-family": config["fontFamily"],
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// 位置
|
|
59
|
+
setAttribute(el, "x", x)
|
|
60
|
+
setAttribute(el, "y", y)
|
|
61
|
+
|
|
62
|
+
// 旋转
|
|
63
|
+
if (typeof deg == "number") {
|
|
64
|
+
deg = deg % 360
|
|
65
|
+
setAttribute(el, "transform", "rotate(" + deg + "," + x + "," + y + ")")
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 画圆统一设置方法
|
|
70
|
+
export const initCircle = (el: SVGElement, cx: number, cy: number, r: number) => {
|
|
71
|
+
if (el.nodeName.toLowerCase() !== "circle")
|
|
72
|
+
throw new Error("Need a <circle> !")
|
|
73
|
+
setAttribute(el, "cx", cx)
|
|
74
|
+
setAttribute(el, "cy", cy)
|
|
75
|
+
setAttribute(el, "r", r)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 路径统一设置方法
|
|
79
|
+
export const initPath = (el: SVGElement, path: string) => {
|
|
80
|
+
if (el.nodeName.toLowerCase() !== "path") throw new Error("Need a <path> !")
|
|
81
|
+
setAttribute(el, "d", path)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 画矩形统一设置方法
|
|
85
|
+
export const initRect = (
|
|
86
|
+
el: SVGElement,
|
|
87
|
+
x: number,
|
|
88
|
+
y: number,
|
|
89
|
+
width: number,
|
|
90
|
+
height: number
|
|
91
|
+
) => {
|
|
92
|
+
if (el.nodeName.toLowerCase() !== "rect") throw new Error("Need a <rect> !")
|
|
93
|
+
|
|
94
|
+
// 由于高和宽不可以是负数,校对一下
|
|
95
|
+
if (height < 0) {
|
|
96
|
+
height *= -1
|
|
97
|
+
y -= height
|
|
98
|
+
}
|
|
99
|
+
if (width < 0) {
|
|
100
|
+
width *= -1
|
|
101
|
+
x -= width
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
setAttribute(el, "x", x)
|
|
105
|
+
setAttribute(el, "y", y)
|
|
106
|
+
setAttribute(el, "width", width)
|
|
107
|
+
setAttribute(el, "height", height)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 画弧统一设置方法
|
|
111
|
+
export const initArc = (
|
|
112
|
+
el: SVGElement,
|
|
113
|
+
config: SVGConfigType,
|
|
114
|
+
cx: number,
|
|
115
|
+
cy: number,
|
|
116
|
+
r1: number,
|
|
117
|
+
r2: number,
|
|
118
|
+
beginDeg: number,
|
|
119
|
+
deg: number
|
|
120
|
+
) => {
|
|
121
|
+
if (el.nodeName.toLowerCase() !== "path") throw new Error("Need a <path> !")
|
|
122
|
+
|
|
123
|
+
beginDeg = (beginDeg / 180) * Math.PI
|
|
124
|
+
deg = (deg / 180) * Math.PI
|
|
125
|
+
|
|
126
|
+
beginDeg = beginDeg % (Math.PI * 2)
|
|
127
|
+
|
|
128
|
+
if (r1 > r2) {
|
|
129
|
+
const temp = r1
|
|
130
|
+
r1 = r2
|
|
131
|
+
r2 = temp
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 当|deg|>=2π的时候都认为是一个圆环
|
|
135
|
+
if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
|
|
136
|
+
deg = Math.PI * 1.999999
|
|
137
|
+
} else {
|
|
138
|
+
deg = deg % (Math.PI * 2)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
arc(
|
|
142
|
+
beginDeg,
|
|
143
|
+
deg,
|
|
144
|
+
cx,
|
|
145
|
+
cy,
|
|
146
|
+
r1,
|
|
147
|
+
r2,
|
|
148
|
+
function (
|
|
149
|
+
beginA: number,
|
|
150
|
+
endA: number,
|
|
151
|
+
begInnerX: number,
|
|
152
|
+
begInnerY: number,
|
|
153
|
+
begOuterX: number,
|
|
154
|
+
begOuterY: number,
|
|
155
|
+
endInnerX: number,
|
|
156
|
+
endInnerY: number,
|
|
157
|
+
endOuterX: number,
|
|
158
|
+
endOuterY: number,
|
|
159
|
+
r: number
|
|
160
|
+
) {
|
|
161
|
+
const f = endA - beginA > Math.PI ? 1 : 0
|
|
162
|
+
let d = "M" + begInnerX + " " + begInnerY
|
|
163
|
+
if (r < 0) r = -r
|
|
164
|
+
|
|
165
|
+
d +=
|
|
166
|
+
// 横半径 竖半径 x轴偏移角度 0小弧/1大弧 0逆时针/1顺时针 终点x 终点y
|
|
167
|
+
"A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY
|
|
168
|
+
|
|
169
|
+
// 结尾
|
|
170
|
+
if (config.arcEndCap == "round")
|
|
171
|
+
d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY
|
|
172
|
+
else if (config.arcEndCap == "-round")
|
|
173
|
+
d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY
|
|
174
|
+
else d += "L" + endOuterX + " " + endOuterY
|
|
175
|
+
d +=
|
|
176
|
+
"A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY
|
|
177
|
+
|
|
178
|
+
// 开头
|
|
179
|
+
if (config.arcStartCap == "round")
|
|
180
|
+
d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY
|
|
181
|
+
else if (config.arcStartCap == "-round")
|
|
182
|
+
d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY
|
|
183
|
+
else d += "L" + begInnerX + " " + begInnerY
|
|
184
|
+
|
|
185
|
+
if (config.arcStartCap == "butt") d += "Z"
|
|
186
|
+
|
|
187
|
+
setAttribute(el, "d", d)
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
}
|
package/src/common/svg/tool.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import type SVGConfigType from '../../../types/SVGConfig'
|
|
2
|
-
|
|
3
|
-
import { XLINK_ATTRIBUTE } from "./dictionary"
|
|
4
|
-
|
|
5
|
-
// 新建节点
|
|
6
|
-
export function toNode(tagname: string) {
|
|
7
|
-
return document.createElementNS('http://www.w3.org/2000/svg', tagname)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// 设置属性
|
|
11
|
-
const _setAttribute = function (el: SVGElement, key: string, value: string | number) {
|
|
12
|
-
|
|
13
|
-
// 需要使用xlink命名空间的xml属性
|
|
14
|
-
if (XLINK_ATTRIBUTE.indexOf(key) > -1) {
|
|
15
|
-
el.setAttributeNS("http://www.w3.org/1999/xlink", 'xlink:' + key, value + "")
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// 否则
|
|
19
|
-
else {
|
|
20
|
-
el.setAttribute(key, value + "")
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export const setAttribute = _setAttribute
|
|
24
|
-
|
|
25
|
-
// 获取属性
|
|
26
|
-
export function getAttribute(el: SVGElement, key: string) {
|
|
27
|
-
if (XLINK_ATTRIBUTE.indexOf(key) > -1) key = 'xlink:' + key
|
|
28
|
-
return el.getAttribute(key)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function full(el: SVGElement, config: SVGConfigType) {
|
|
32
|
-
_setAttribute(el, "stroke", config.strokeStyle)
|
|
33
|
-
_setAttribute(el, "fill", config.fillStyle)
|
|
34
|
-
_setAttribute(el, "stroke-dasharray", config.lineDash.join(','))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function fill(el: SVGElement, config: SVGConfigType) {
|
|
38
|
-
_setAttribute(el, "fill", config.fillStyle)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function stroke(el: SVGElement, config: SVGConfigType) {
|
|
42
|
-
_setAttribute(el, "stroke", config.strokeStyle)
|
|
43
|
-
_setAttribute(el, "fill", "none")
|
|
44
|
-
_setAttribute(el, "stroke-dasharray", config.lineDash.join(','))
|
|
1
|
+
import type SVGConfigType from '../../../types/SVGConfig'
|
|
2
|
+
|
|
3
|
+
import { XLINK_ATTRIBUTE } from "./dictionary"
|
|
4
|
+
|
|
5
|
+
// 新建节点
|
|
6
|
+
export function toNode(tagname: string) {
|
|
7
|
+
return document.createElementNS('http://www.w3.org/2000/svg', tagname)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// 设置属性
|
|
11
|
+
const _setAttribute = function (el: SVGElement, key: string, value: string | number) {
|
|
12
|
+
|
|
13
|
+
// 需要使用xlink命名空间的xml属性
|
|
14
|
+
if (XLINK_ATTRIBUTE.indexOf(key) > -1) {
|
|
15
|
+
el.setAttributeNS("http://www.w3.org/1999/xlink", 'xlink:' + key, value + "")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 否则
|
|
19
|
+
else {
|
|
20
|
+
el.setAttribute(key, value + "")
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export const setAttribute = _setAttribute
|
|
24
|
+
|
|
25
|
+
// 获取属性
|
|
26
|
+
export function getAttribute(el: SVGElement, key: string) {
|
|
27
|
+
if (XLINK_ATTRIBUTE.indexOf(key) > -1) key = 'xlink:' + key
|
|
28
|
+
return el.getAttribute(key)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function full(el: SVGElement, config: SVGConfigType) {
|
|
32
|
+
_setAttribute(el, "stroke", config.strokeStyle as string)
|
|
33
|
+
_setAttribute(el, "fill", config.fillStyle as string)
|
|
34
|
+
_setAttribute(el, "stroke-dasharray", (config.lineDash as Array<number>).join(','))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function fill(el: SVGElement, config: SVGConfigType) {
|
|
38
|
+
_setAttribute(el, "fill", config.fillStyle as string)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function stroke(el: SVGElement, config: SVGConfigType) {
|
|
42
|
+
_setAttribute(el, "stroke", config.strokeStyle as string)
|
|
43
|
+
_setAttribute(el, "fill", "none")
|
|
44
|
+
_setAttribute(el, "stroke-dasharray", (config.lineDash as Array<number>).join(','))
|
|
45
45
|
}
|