vislite 0.6.0-alpha.2 → 0.6.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/.eslintrc.js +3 -1
- package/CHANGELOG +1 -1
- package/README.md +11 -3
- 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.json +1 -1
- package/src/Canvas.ts +70 -70
- package/src/Eoap.ts +66 -66
- package/src/Geometry.ts +82 -82
- package/src/Matrix4/move.ts +12 -12
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/transform.ts +64 -64
- package/src/Mercator.ts +27 -27
- package/src/SVG.ts +24 -24
- package/src/WebGL.ts +66 -66
- package/src/animation.ts +98 -98
- package/src/common/assemble.ts +22 -22
- package/src/common/canvas/arc.ts +51 -51
- package/src/common/canvas/config.ts +158 -158
- package/src/common/canvas/gradient.ts +29 -29
- package/src/common/canvas/painter.ts +417 -417
- package/src/common/geometry/prism-horizontal.ts +35 -35
- package/src/common/geometry/prism-vertical.ts +40 -40
- package/src/common/geometry/sphere-fragment.ts +40 -40
- package/src/common/geometry/tool/circle.ts +11 -11
- package/src/common/mergeOption.ts +6 -6
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +186 -186
- package/src/common/svg/gradient.ts +63 -63
- package/src/common/svg/index.ts +356 -356
- package/src/common/svg/tool.ts +44 -44
- package/src/common/tree/toInnerTree.ts +57 -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/getColorFactory.ts +26 -26
- package/src/common/webgl/getShader.ts +48 -48
- package/src/common/webgl/getTexture.ts +11 -11
- package/src/common/webgl/getWebGLContext.ts +28 -28
- package/src/common/webgl/index.ts +224 -224
- package/src/common/webgl/shader.ts +75 -75
- package/src/common/webgl/texture.ts +97 -97
- package/src/formatColor.ts +44 -44
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +110 -110
- package/src/interpolation/Hermite.ts +65 -65
- package/src/move.ts +7 -7
- package/src/resizeObserver.ts +37 -37
- package/src/rotate.ts +7 -7
- package/src/throttle.ts +52 -52
- package/src/viewHandler.ts +158 -158
- package/types/CanvasOption.d.ts +8 -8
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import rotate from '../../rotate'
|
|
2
|
-
|
|
3
|
-
// 棱柱水平部分
|
|
4
|
-
|
|
5
|
-
export default function (normal: boolean, x: number, y: number, z: number, radius: number, num: number, d: number) {
|
|
6
|
-
|
|
7
|
-
let beginX: number, beginZ: number
|
|
8
|
-
if (num == 4) {
|
|
9
|
-
const temp = radius / 1.414
|
|
10
|
-
beginX = x + temp
|
|
11
|
-
beginZ = z + temp
|
|
12
|
-
|
|
13
|
-
} else {
|
|
14
|
-
beginX = x + radius
|
|
15
|
-
beginZ = z
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let point = [beginX, beginZ]
|
|
19
|
-
const points = []
|
|
20
|
-
const deg = Math.PI * 2 / num
|
|
21
|
-
for (let i = 0; i < num; i++) {
|
|
22
|
-
|
|
23
|
-
points.push(x, y, z)
|
|
24
|
-
if (normal) points.push(0, d, 0)
|
|
25
|
-
|
|
26
|
-
points.push(point[0], y, point[1])
|
|
27
|
-
if (normal) points.push(0, d, 0)
|
|
28
|
-
|
|
29
|
-
point = rotate(x, z, deg * (i + 1), beginX, beginZ)
|
|
30
|
-
points.push(point[0], y, point[1])
|
|
31
|
-
if (normal) points.push(0, d, 0)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return points
|
|
35
|
-
}
|
|
1
|
+
import rotate from '../../rotate'
|
|
2
|
+
|
|
3
|
+
// 棱柱水平部分
|
|
4
|
+
|
|
5
|
+
export default function (normal: boolean, x: number, y: number, z: number, radius: number, num: number, d: number) {
|
|
6
|
+
|
|
7
|
+
let beginX: number, beginZ: number
|
|
8
|
+
if (num == 4) {
|
|
9
|
+
const temp = radius / 1.414
|
|
10
|
+
beginX = x + temp
|
|
11
|
+
beginZ = z + temp
|
|
12
|
+
|
|
13
|
+
} else {
|
|
14
|
+
beginX = x + radius
|
|
15
|
+
beginZ = z
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let point = [beginX, beginZ]
|
|
19
|
+
const points = []
|
|
20
|
+
const deg = Math.PI * 2 / num
|
|
21
|
+
for (let i = 0; i < num; i++) {
|
|
22
|
+
|
|
23
|
+
points.push(x, y, z)
|
|
24
|
+
if (normal) points.push(0, d, 0)
|
|
25
|
+
|
|
26
|
+
points.push(point[0], y, point[1])
|
|
27
|
+
if (normal) points.push(0, d, 0)
|
|
28
|
+
|
|
29
|
+
point = rotate(x, z, deg * (i + 1), beginX, beginZ)
|
|
30
|
+
points.push(point[0], y, point[1])
|
|
31
|
+
if (normal) points.push(0, d, 0)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return points
|
|
35
|
+
}
|
|
@@ -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 = []
|
|
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,40 +1,40 @@
|
|
|
1
|
-
import rotate from '../../rotate'
|
|
2
|
-
|
|
3
|
-
// 球体中的一瓣子
|
|
4
|
-
|
|
5
|
-
export default function (normal: boolean, cx: number, cy: number, cz: number, radius: number, num: number, index: number) {
|
|
6
|
-
const points = [cx, cy + radius, cz], deg = Math.PI * 2 / num
|
|
7
|
-
let point: [number, number]
|
|
8
|
-
|
|
9
|
-
if (normal) points.push(0, radius, 0)
|
|
10
|
-
|
|
11
|
-
const copy2 = () => {
|
|
12
|
-
points.push(...points.slice(points.length - (normal ? 12 : 6)))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
for (let i = 1; i < num * 0.5; i++) {
|
|
16
|
-
point = rotate(cx, cy, deg * i, cx, cy + radius)
|
|
17
|
-
|
|
18
|
-
if (i > 1) copy2()
|
|
19
|
-
|
|
20
|
-
// 第一个点
|
|
21
|
-
const point1 = rotate(cx, cz, deg * index, point[0], cz)
|
|
22
|
-
points.push(point1[0], point[1], point1[1])
|
|
23
|
-
|
|
24
|
-
if (normal) points.push(point1[0] - cx, point[1] - cy, point1[1] - cz)
|
|
25
|
-
|
|
26
|
-
if (i > 1) copy2()
|
|
27
|
-
|
|
28
|
-
// 下一个点
|
|
29
|
-
const point2 = rotate(cx, cz, deg * (index + 1), point[0], cz)
|
|
30
|
-
points.push(point2[0], point[1], point2[1])
|
|
31
|
-
|
|
32
|
-
if (normal) points.push(point2[0] - cx, point2[1] - cy, point2[1] - cz)
|
|
33
|
-
}
|
|
34
|
-
copy2()
|
|
35
|
-
points.push(cx, cy - radius, cz)
|
|
36
|
-
|
|
37
|
-
if (normal) points.push(0, - radius, 0)
|
|
38
|
-
|
|
39
|
-
return points
|
|
40
|
-
}
|
|
1
|
+
import rotate from '../../rotate'
|
|
2
|
+
|
|
3
|
+
// 球体中的一瓣子
|
|
4
|
+
|
|
5
|
+
export default function (normal: boolean, cx: number, cy: number, cz: number, radius: number, num: number, index: number) {
|
|
6
|
+
const points = [cx, cy + radius, cz], deg = Math.PI * 2 / num
|
|
7
|
+
let point: [number, number]
|
|
8
|
+
|
|
9
|
+
if (normal) points.push(0, radius, 0)
|
|
10
|
+
|
|
11
|
+
const copy2 = () => {
|
|
12
|
+
points.push(...points.slice(points.length - (normal ? 12 : 6)))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
for (let i = 1; i < num * 0.5; i++) {
|
|
16
|
+
point = rotate(cx, cy, deg * i, cx, cy + radius)
|
|
17
|
+
|
|
18
|
+
if (i > 1) copy2()
|
|
19
|
+
|
|
20
|
+
// 第一个点
|
|
21
|
+
const point1 = rotate(cx, cz, deg * index, point[0], cz)
|
|
22
|
+
points.push(point1[0], point[1], point1[1])
|
|
23
|
+
|
|
24
|
+
if (normal) points.push(point1[0] - cx, point[1] - cy, point1[1] - cz)
|
|
25
|
+
|
|
26
|
+
if (i > 1) copy2()
|
|
27
|
+
|
|
28
|
+
// 下一个点
|
|
29
|
+
const point2 = rotate(cx, cz, deg * (index + 1), point[0], cz)
|
|
30
|
+
points.push(point2[0], point[1], point2[1])
|
|
31
|
+
|
|
32
|
+
if (normal) points.push(point2[0] - cx, point2[1] - cy, point2[1] - cz)
|
|
33
|
+
}
|
|
34
|
+
copy2()
|
|
35
|
+
points.push(cx, cy - radius, cz)
|
|
36
|
+
|
|
37
|
+
if (normal) points.push(0, - radius, 0)
|
|
38
|
+
|
|
39
|
+
return points
|
|
40
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// 计算切割份数
|
|
2
|
-
export const splitNum = function (precision: number, radius: number) {
|
|
3
|
-
|
|
4
|
-
// 根据切割弧度得出切割块数目
|
|
5
|
-
const num = Math.ceil(Math.PI * 2 /
|
|
6
|
-
|
|
7
|
-
// 为了满足最小精度而得出的切割弧度
|
|
8
|
-
Math.asin(precision / radius) * 2)
|
|
9
|
-
|
|
10
|
-
return (isNaN(num) || num < 12) ? 12 : num
|
|
11
|
-
|
|
1
|
+
// 计算切割份数
|
|
2
|
+
export const splitNum = function (precision: number, radius: number) {
|
|
3
|
+
|
|
4
|
+
// 根据切割弧度得出切割块数目
|
|
5
|
+
const num = Math.ceil(Math.PI * 2 /
|
|
6
|
+
|
|
7
|
+
// 为了满足最小精度而得出的切割弧度
|
|
8
|
+
Math.asin(precision / radius) * 2)
|
|
9
|
+
|
|
10
|
+
return (isNaN(num) || num < 12) ? 12 : num
|
|
11
|
+
|
|
12
12
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export default function (option: any, defaultOption: any) {
|
|
2
|
-
for (const key in option) {
|
|
3
|
-
defaultOption[key] = option[key]
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
return defaultOption
|
|
1
|
+
export default function (option: any, defaultOption: any) {
|
|
2
|
+
for (const key in option) {
|
|
3
|
+
defaultOption[key] = option[key]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return defaultOption
|
|
7
7
|
}
|
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] = styles[key]
|
|
5
|
+
}
|
|
6
6
|
}
|
package/src/common/svg/config.ts
CHANGED
|
@@ -1,186 +1,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"] * 0.5,
|
|
35
|
-
middle: 0,
|
|
36
|
-
bottom: -config["fontSize"] * 0.5,
|
|
37
|
-
}[config.textBaseline]
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
setStyle(el, {
|
|
41
|
-
// 文字对齐方式
|
|
42
|
-
"text-anchor": {
|
|
43
|
-
left: "start",
|
|
44
|
-
right: "end",
|
|
45
|
-
center: "middle",
|
|
46
|
-
}[config.textAlign],
|
|
47
|
-
"dominant-baseline": "central",
|
|
48
|
-
|
|
49
|
-
// 文字大小和字体设置
|
|
50
|
-
"font-size": config["fontSize"] + "px",
|
|
51
|
-
"font-family": config["fontFamily"],
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
// 位置
|
|
55
|
-
setAttribute(el, "x", x)
|
|
56
|
-
setAttribute(el, "y", y)
|
|
57
|
-
|
|
58
|
-
// 旋转
|
|
59
|
-
if (typeof deg == "number") {
|
|
60
|
-
deg = deg % 360
|
|
61
|
-
setAttribute(el, "transform", "rotate(" + deg + "," + x + "," + y + ")")
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// 画圆统一设置方法
|
|
66
|
-
export const initCircle = (el: SVGElement, cx: number, cy: number, r: number) => {
|
|
67
|
-
if (el.nodeName.toLowerCase() !== "circle")
|
|
68
|
-
throw new Error("Need a <circle> !")
|
|
69
|
-
setAttribute(el, "cx", cx)
|
|
70
|
-
setAttribute(el, "cy", cy)
|
|
71
|
-
setAttribute(el, "r", r)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 路径统一设置方法
|
|
75
|
-
export const initPath = (el: SVGElement, path: string) => {
|
|
76
|
-
if (el.nodeName.toLowerCase() !== "path") throw new Error("Need a <path> !")
|
|
77
|
-
setAttribute(el, "d", path)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// 画矩形统一设置方法
|
|
81
|
-
export const initRect = (
|
|
82
|
-
el: SVGElement,
|
|
83
|
-
x: number,
|
|
84
|
-
y: number,
|
|
85
|
-
width: number,
|
|
86
|
-
height: number
|
|
87
|
-
) => {
|
|
88
|
-
if (el.nodeName.toLowerCase() !== "rect") throw new Error("Need a <rect> !")
|
|
89
|
-
|
|
90
|
-
// 由于高和宽不可以是负数,校对一下
|
|
91
|
-
if (height < 0) {
|
|
92
|
-
height *= -1
|
|
93
|
-
y -= height
|
|
94
|
-
}
|
|
95
|
-
if (width < 0) {
|
|
96
|
-
width *= -1
|
|
97
|
-
x -= width
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
setAttribute(el, "x", x)
|
|
101
|
-
setAttribute(el, "y", y)
|
|
102
|
-
setAttribute(el, "width", width)
|
|
103
|
-
setAttribute(el, "height", height)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// 画弧统一设置方法
|
|
107
|
-
export const initArc = (
|
|
108
|
-
el: SVGElement,
|
|
109
|
-
config: SVGConfigType,
|
|
110
|
-
cx: number,
|
|
111
|
-
cy: number,
|
|
112
|
-
r1: number,
|
|
113
|
-
r2: number,
|
|
114
|
-
beginDeg: number,
|
|
115
|
-
deg: number
|
|
116
|
-
) => {
|
|
117
|
-
if (el.nodeName.toLowerCase() !== "path") throw new Error("Need a <path> !")
|
|
118
|
-
|
|
119
|
-
beginDeg = (beginDeg / 180) * Math.PI
|
|
120
|
-
deg = (deg / 180) * Math.PI
|
|
121
|
-
|
|
122
|
-
beginDeg = beginDeg % (Math.PI * 2)
|
|
123
|
-
|
|
124
|
-
if (r1 > r2) {
|
|
125
|
-
const temp = r1
|
|
126
|
-
r1 = r2
|
|
127
|
-
r2 = temp
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// 当|deg|>=2π的时候都认为是一个圆环
|
|
131
|
-
if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
|
|
132
|
-
deg = Math.PI * 1.999999
|
|
133
|
-
} else {
|
|
134
|
-
deg = deg % (Math.PI * 2)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
arc(
|
|
138
|
-
beginDeg,
|
|
139
|
-
deg,
|
|
140
|
-
cx,
|
|
141
|
-
cy,
|
|
142
|
-
r1,
|
|
143
|
-
r2,
|
|
144
|
-
function (
|
|
145
|
-
beginA: number,
|
|
146
|
-
endA: number,
|
|
147
|
-
begInnerX: number,
|
|
148
|
-
begInnerY: number,
|
|
149
|
-
begOuterX: number,
|
|
150
|
-
begOuterY: number,
|
|
151
|
-
endInnerX: number,
|
|
152
|
-
endInnerY: number,
|
|
153
|
-
endOuterX: number,
|
|
154
|
-
endOuterY: number,
|
|
155
|
-
r: number
|
|
156
|
-
) {
|
|
157
|
-
const f = endA - beginA > Math.PI ? 1 : 0
|
|
158
|
-
let d = "M" + begInnerX + " " + begInnerY
|
|
159
|
-
if (r < 0) r = -r
|
|
160
|
-
|
|
161
|
-
d +=
|
|
162
|
-
// 横半径 竖半径 x轴偏移角度 0小弧/1大弧 0逆时针/1顺时针 终点x 终点y
|
|
163
|
-
"A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY
|
|
164
|
-
|
|
165
|
-
// 结尾
|
|
166
|
-
if (config.arcEndCap == "round")
|
|
167
|
-
d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY
|
|
168
|
-
else if (config.arcEndCap == "-round")
|
|
169
|
-
d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY
|
|
170
|
-
else d += "L" + endOuterX + " " + endOuterY
|
|
171
|
-
d +=
|
|
172
|
-
"A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY
|
|
173
|
-
|
|
174
|
-
// 开头
|
|
175
|
-
if (config.arcStartCap == "round")
|
|
176
|
-
d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY
|
|
177
|
-
else if (config.arcStartCap == "-round")
|
|
178
|
-
d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY
|
|
179
|
-
else d += "L" + begInnerX + " " + begInnerY
|
|
180
|
-
|
|
181
|
-
if (config.arcStartCap == "butt") d += "Z"
|
|
182
|
-
|
|
183
|
-
setAttribute(el, "d", d)
|
|
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"] * 0.5,
|
|
35
|
+
middle: 0,
|
|
36
|
+
bottom: -config["fontSize"] * 0.5,
|
|
37
|
+
}[config.textBaseline]
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
setStyle(el, {
|
|
41
|
+
// 文字对齐方式
|
|
42
|
+
"text-anchor": {
|
|
43
|
+
left: "start",
|
|
44
|
+
right: "end",
|
|
45
|
+
center: "middle",
|
|
46
|
+
}[config.textAlign],
|
|
47
|
+
"dominant-baseline": "central",
|
|
48
|
+
|
|
49
|
+
// 文字大小和字体设置
|
|
50
|
+
"font-size": config["fontSize"] + "px",
|
|
51
|
+
"font-family": config["fontFamily"],
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// 位置
|
|
55
|
+
setAttribute(el, "x", x)
|
|
56
|
+
setAttribute(el, "y", y)
|
|
57
|
+
|
|
58
|
+
// 旋转
|
|
59
|
+
if (typeof deg == "number") {
|
|
60
|
+
deg = deg % 360
|
|
61
|
+
setAttribute(el, "transform", "rotate(" + deg + "," + x + "," + y + ")")
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 画圆统一设置方法
|
|
66
|
+
export const initCircle = (el: SVGElement, cx: number, cy: number, r: number) => {
|
|
67
|
+
if (el.nodeName.toLowerCase() !== "circle")
|
|
68
|
+
throw new Error("Need a <circle> !")
|
|
69
|
+
setAttribute(el, "cx", cx)
|
|
70
|
+
setAttribute(el, "cy", cy)
|
|
71
|
+
setAttribute(el, "r", r)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 路径统一设置方法
|
|
75
|
+
export const initPath = (el: SVGElement, path: string) => {
|
|
76
|
+
if (el.nodeName.toLowerCase() !== "path") throw new Error("Need a <path> !")
|
|
77
|
+
setAttribute(el, "d", path)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 画矩形统一设置方法
|
|
81
|
+
export const initRect = (
|
|
82
|
+
el: SVGElement,
|
|
83
|
+
x: number,
|
|
84
|
+
y: number,
|
|
85
|
+
width: number,
|
|
86
|
+
height: number
|
|
87
|
+
) => {
|
|
88
|
+
if (el.nodeName.toLowerCase() !== "rect") throw new Error("Need a <rect> !")
|
|
89
|
+
|
|
90
|
+
// 由于高和宽不可以是负数,校对一下
|
|
91
|
+
if (height < 0) {
|
|
92
|
+
height *= -1
|
|
93
|
+
y -= height
|
|
94
|
+
}
|
|
95
|
+
if (width < 0) {
|
|
96
|
+
width *= -1
|
|
97
|
+
x -= width
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
setAttribute(el, "x", x)
|
|
101
|
+
setAttribute(el, "y", y)
|
|
102
|
+
setAttribute(el, "width", width)
|
|
103
|
+
setAttribute(el, "height", height)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 画弧统一设置方法
|
|
107
|
+
export const initArc = (
|
|
108
|
+
el: SVGElement,
|
|
109
|
+
config: SVGConfigType,
|
|
110
|
+
cx: number,
|
|
111
|
+
cy: number,
|
|
112
|
+
r1: number,
|
|
113
|
+
r2: number,
|
|
114
|
+
beginDeg: number,
|
|
115
|
+
deg: number
|
|
116
|
+
) => {
|
|
117
|
+
if (el.nodeName.toLowerCase() !== "path") throw new Error("Need a <path> !")
|
|
118
|
+
|
|
119
|
+
beginDeg = (beginDeg / 180) * Math.PI
|
|
120
|
+
deg = (deg / 180) * Math.PI
|
|
121
|
+
|
|
122
|
+
beginDeg = beginDeg % (Math.PI * 2)
|
|
123
|
+
|
|
124
|
+
if (r1 > r2) {
|
|
125
|
+
const temp = r1
|
|
126
|
+
r1 = r2
|
|
127
|
+
r2 = temp
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 当|deg|>=2π的时候都认为是一个圆环
|
|
131
|
+
if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
|
|
132
|
+
deg = Math.PI * 1.999999
|
|
133
|
+
} else {
|
|
134
|
+
deg = deg % (Math.PI * 2)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
arc(
|
|
138
|
+
beginDeg,
|
|
139
|
+
deg,
|
|
140
|
+
cx,
|
|
141
|
+
cy,
|
|
142
|
+
r1,
|
|
143
|
+
r2,
|
|
144
|
+
function (
|
|
145
|
+
beginA: number,
|
|
146
|
+
endA: number,
|
|
147
|
+
begInnerX: number,
|
|
148
|
+
begInnerY: number,
|
|
149
|
+
begOuterX: number,
|
|
150
|
+
begOuterY: number,
|
|
151
|
+
endInnerX: number,
|
|
152
|
+
endInnerY: number,
|
|
153
|
+
endOuterX: number,
|
|
154
|
+
endOuterY: number,
|
|
155
|
+
r: number
|
|
156
|
+
) {
|
|
157
|
+
const f = endA - beginA > Math.PI ? 1 : 0
|
|
158
|
+
let d = "M" + begInnerX + " " + begInnerY
|
|
159
|
+
if (r < 0) r = -r
|
|
160
|
+
|
|
161
|
+
d +=
|
|
162
|
+
// 横半径 竖半径 x轴偏移角度 0小弧/1大弧 0逆时针/1顺时针 终点x 终点y
|
|
163
|
+
"A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY
|
|
164
|
+
|
|
165
|
+
// 结尾
|
|
166
|
+
if (config.arcEndCap == "round")
|
|
167
|
+
d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY
|
|
168
|
+
else if (config.arcEndCap == "-round")
|
|
169
|
+
d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY
|
|
170
|
+
else d += "L" + endOuterX + " " + endOuterY
|
|
171
|
+
d +=
|
|
172
|
+
"A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY
|
|
173
|
+
|
|
174
|
+
// 开头
|
|
175
|
+
if (config.arcStartCap == "round")
|
|
176
|
+
d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY
|
|
177
|
+
else if (config.arcStartCap == "-round")
|
|
178
|
+
d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY
|
|
179
|
+
else d += "L" + begInnerX + " " + begInnerY
|
|
180
|
+
|
|
181
|
+
if (config.arcStartCap == "butt") d += "Z"
|
|
182
|
+
|
|
183
|
+
setAttribute(el, "d", d)
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
}
|