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.
Files changed (85) hide show
  1. package/CHANGELOG +8 -3
  2. package/README.md +20 -1
  3. package/lib/Buffer/index.umd.js +2 -2
  4. package/lib/Buffer/index.umd.min.js +2 -2
  5. package/lib/Canvas/index.umd.js +4 -4
  6. package/lib/Canvas/index.umd.min.js +3 -3
  7. package/lib/Cardinal/index.umd.js +2 -2
  8. package/lib/Cardinal/index.umd.min.js +2 -2
  9. package/lib/Eoap/index.umd.js +2 -2
  10. package/lib/Eoap/index.umd.min.js +2 -2
  11. package/lib/Geometry/index.umd.js +69 -8
  12. package/lib/Geometry/index.umd.min.js +3 -3
  13. package/lib/Hermite/index.umd.js +2 -2
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +2 -2
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +2 -2
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/OralCanvas/index.es.js +3 -3
  20. package/lib/OralCanvas/index.es.min.js +3 -3
  21. package/lib/OralWebGL/index.es.js +21 -18
  22. package/lib/OralWebGL/index.es.min.js +3 -3
  23. package/lib/SVG/index.umd.js +2 -2
  24. package/lib/SVG/index.umd.min.js +2 -2
  25. package/lib/Shader/index.umd.js +3 -2
  26. package/lib/Shader/index.umd.min.js +3 -3
  27. package/lib/Texture/index.umd.js +2 -2
  28. package/lib/Texture/index.umd.min.js +2 -2
  29. package/lib/TreeLayout/index.umd.js +13 -11
  30. package/lib/TreeLayout/index.umd.min.js +3 -3
  31. package/lib/WebGL/index.umd.js +22 -19
  32. package/lib/WebGL/index.umd.min.js +3 -3
  33. package/lib/animation/index.umd.js +2 -2
  34. package/lib/animation/index.umd.min.js +2 -2
  35. package/lib/formatColor/index.umd.js +2 -2
  36. package/lib/formatColor/index.umd.min.js +2 -2
  37. package/lib/getLoopColors/index.umd.js +2 -2
  38. package/lib/getLoopColors/index.umd.min.js +2 -2
  39. package/lib/getWebGLContext/index.umd.js +4 -4
  40. package/lib/getWebGLContext/index.umd.min.js +3 -3
  41. package/lib/index.umd.js +104 -38
  42. package/lib/index.umd.min.js +3 -3
  43. package/lib/move/index.umd.js +2 -2
  44. package/lib/move/index.umd.min.js +2 -2
  45. package/lib/resizeObserver/index.umd.js +2 -2
  46. package/lib/resizeObserver/index.umd.min.js +2 -2
  47. package/lib/rotate/index.umd.js +2 -2
  48. package/lib/rotate/index.umd.min.js +2 -2
  49. package/lib/ruler/index.umd.js +4 -4
  50. package/lib/ruler/index.umd.min.js +3 -3
  51. package/lib/scale/index.umd.js +2 -2
  52. package/lib/scale/index.umd.min.js +2 -2
  53. package/lib/throttle/index.umd.js +2 -2
  54. package/lib/throttle/index.umd.min.js +2 -2
  55. package/lib/viewHandler/index.umd.js +2 -2
  56. package/lib/viewHandler/index.umd.min.js +2 -2
  57. package/package.json +1 -1
  58. package/src/Canvas.ts +70 -70
  59. package/src/Geometry.ts +126 -82
  60. package/src/Matrix4/rotate.ts +15 -15
  61. package/src/Matrix4/transform.ts +64 -64
  62. package/src/WebGL.ts +66 -66
  63. package/src/common/assemble.ts +22 -22
  64. package/src/common/canvas/index.ts +177 -177
  65. package/src/common/canvas/painter.ts +419 -417
  66. package/src/common/geometry/prism-vertical.ts +40 -40
  67. package/src/common/geometry/tool/rotateLine.ts +36 -0
  68. package/src/common/setStyle.ts +5 -5
  69. package/src/common/svg/config.ts +190 -186
  70. package/src/common/svg/tool.ts +44 -44
  71. package/src/common/tree/toInnerTree.ts +59 -57
  72. package/src/common/tree/toPlainTree.ts +132 -132
  73. package/src/common/webgl/buffer.ts +79 -79
  74. package/src/common/webgl/doDraw.ts +108 -108
  75. package/src/common/webgl/getWebGLContext.ts +28 -28
  76. package/src/common/webgl/index.ts +226 -224
  77. package/src/common/webgl/shader.ts +75 -75
  78. package/src/common/webgl/texture.ts +97 -97
  79. package/src/layout/TreeLayout.ts +188 -186
  80. package/src/resizeObserver.ts +37 -37
  81. package/src/ruler.ts +209 -209
  82. package/src/viewHandler.ts +160 -158
  83. package/types/Canvas.d.ts +308 -308
  84. package/types/Geometry.d.ts +65 -40
  85. 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
+ }
@@ -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
  }
@@ -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
- }[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"] 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
+ }
@@ -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
  }