vislite 1.2.0-alpha.2 → 1.2.0-alpha.4

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 (72) hide show
  1. package/CHANGELOG +266 -254
  2. package/lib/Buffer/index.es.js +1 -1
  3. package/lib/Buffer/index.es.min.js +1 -1
  4. package/lib/Canvas/index.es.js +16 -5
  5. package/lib/Canvas/index.es.min.js +2 -2
  6. package/lib/Cardinal/index.es.js +1 -1
  7. package/lib/Cardinal/index.es.min.js +1 -1
  8. package/lib/Eoap/index.es.js +1 -1
  9. package/lib/Eoap/index.es.min.js +1 -1
  10. package/lib/Hermite/index.es.js +1 -1
  11. package/lib/Hermite/index.es.min.js +1 -1
  12. package/lib/Matrix4/index.es.js +1 -1
  13. package/lib/Matrix4/index.es.min.js +1 -1
  14. package/lib/Mercator/index.es.js +1 -1
  15. package/lib/Mercator/index.es.min.js +1 -1
  16. package/lib/RawCanvas/index.es.js +15 -4
  17. package/lib/RawCanvas/index.es.min.js +2 -2
  18. package/lib/SVG/index.es.js +12 -8
  19. package/lib/SVG/index.es.min.js +2 -2
  20. package/lib/Shader/index.es.js +1 -1
  21. package/lib/Shader/index.es.min.js +1 -1
  22. package/lib/Texture/index.es.js +1 -1
  23. package/lib/Texture/index.es.min.js +1 -1
  24. package/lib/TreeLayout/index.es.js +38 -8
  25. package/lib/TreeLayout/index.es.min.js +2 -2
  26. package/lib/animation/index.es.js +38 -8
  27. package/lib/animation/index.es.min.js +2 -2
  28. package/lib/assemble/index.es.js +1 -1
  29. package/lib/assemble/index.es.min.js +1 -1
  30. package/lib/getLoopColors/index.es.js +1 -1
  31. package/lib/getLoopColors/index.es.min.js +1 -1
  32. package/lib/getWebGLContext/index.es.js +1 -1
  33. package/lib/getWebGLContext/index.es.min.js +1 -1
  34. package/lib/index.umd.js +88 -36
  35. package/lib/index.umd.min.js +2 -2
  36. package/lib/initOption/index.es.js +1 -1
  37. package/lib/initOption/index.es.min.js +1 -1
  38. package/lib/mergeOption/index.es.js +1 -1
  39. package/lib/mergeOption/index.es.min.js +1 -1
  40. package/lib/move/index.es.js +1 -1
  41. package/lib/move/index.es.min.js +1 -1
  42. package/lib/rotate/index.es.js +1 -1
  43. package/lib/rotate/index.es.min.js +1 -1
  44. package/lib/ruler/index.es.js +1 -1
  45. package/lib/ruler/index.es.min.js +1 -1
  46. package/lib/scale/index.es.js +1 -1
  47. package/lib/scale/index.es.min.js +1 -1
  48. package/lib/throttle/index.es.js +25 -25
  49. package/lib/throttle/index.es.min.js +2 -2
  50. package/miniprogram/ui-canvas/index.js +115 -115
  51. package/package/animation/index.ts +1 -1
  52. package/package/throttle/index.ts +1 -1
  53. package/package.json +7 -2
  54. package/src/Canvas.ts +84 -84
  55. package/src/common/canvas/gradient.ts +32 -24
  56. package/src/common/canvas/index.ts +182 -177
  57. package/src/common/canvas/painter.ts +9 -3
  58. package/src/common/svg/config.ts +194 -190
  59. package/src/common/svg/index.ts +350 -347
  60. package/src/common/svg/tool.ts +42 -44
  61. package/src/layout/TreeLayout.ts +1 -1
  62. package/types/Canvas.d.ts +10 -1
  63. package/types/CanvasConfig.d.ts +116 -106
  64. package/types/SVGConfig.d.ts +89 -79
  65. package/types/animation.d.ts +2 -6
  66. package/types/index.d.ts +160 -158
  67. package/types/painterConfig.d.ts +5 -3
  68. package/types/throttle.d.ts +2 -4
  69. package/types/throttleOption.d.ts +1 -22
  70. package/types/uni-canvas.d.ts +4 -0
  71. package/src/animation.ts +0 -99
  72. package/src/throttle.ts +0 -53
@@ -1,347 +1,350 @@
1
- import type { default as SVGConfigType, svgElType, svgBoardType } from "../../../types/SVGConfig"
2
- import type { arcCapType, textAlignType, textBaselineType } from "../../../types/painterConfig"
3
-
4
- import { initText, initCircle, initPath, initRect, initArc } from "./config"
5
- import { toNode, setAttribute, getAttribute, full, fill, stroke } from "./tool"
6
- import rotate from "../../rotate"
7
- import { linearGradient, radialGradient } from "./gradient"
8
-
9
- class SVG {
10
- readonly name: string = "SVG"
11
-
12
- // 用于记录配置
13
- private __config = {
14
- // 基本设置
15
- fillStyle: "#000",
16
- strokeStyle: "#000",
17
- lineWidth: 1,
18
-
19
- // 文字对齐方式
20
- textAlign: <textAlignType>"left",
21
- textBaseline: <textBaselineType>"middle",
22
-
23
- // 文字设置
24
- "fontSize": 16,
25
- "fontFamily": "sans-serif",
26
-
27
- // arc二端闭合方式['butt':直线闭合,'round':圆帽闭合]
28
- "arcStartCap": <arcCapType>"butt",
29
- "arcEndCap": <arcCapType>"butt",
30
-
31
- // 虚线设置
32
- lineDash: [],
33
- }
34
-
35
- // 作用的节点
36
- private __useEl: SVGElement
37
-
38
- // 路径(和canvas2D的类似)
39
- private __path: string = ""
40
- private __currentPosition: number[] = []
41
-
42
- private __svg: SVGElement
43
- constructor(svg: SVGElement) {
44
- this.__svg = svg
45
- }
46
-
47
- // 属性设置或获取
48
- config(params: SVGConfigType) {
49
- if (typeof params !== "object") {
50
- return this.__config[params]
51
- } else {
52
- for (const key in params) {
53
- this.__config[key] = params[key]
54
- }
55
- }
56
- return this
57
- }
58
-
59
- /**
60
- * 基础方法
61
- * ---------------------------------
62
- */
63
-
64
- // 标记应用节点
65
- // 也就是后续操作都会作用在此节点
66
- useEl(el: SVGElement) {
67
- this.__useEl = el
68
- return this
69
- }
70
-
71
- // 获取当前应用的节点
72
- getEl() {
73
- return this.__useEl
74
- }
75
-
76
- // 追加节点
77
- // el可以是结点或字符串,字符串的话表示节点名称
78
- // context可选,表示追加位置,可选,默认根svg
79
- // 此外,和appendBoard等操作一样,执行后新加入的结点会自动变成应用节点
80
- appendEl(el: svgElType, context?: SVGElement) {
81
- context = context || this.__svg
82
-
83
- if (typeof el == "string") el = toNode(el)
84
- context.appendChild(el as SVGElement)
85
-
86
- this.__useEl = el as SVGElement
87
- return this
88
- }
89
-
90
- // 追加绘制板
91
- // 参数和appendEl类似,只是el如果是字符串的话,表示需要绘制对应什么内容,
92
- // 比如el = “arc”,表示画弧(不是路径arc),那么我们会创建path节点,因为我们是使用path实现的
93
- appendBoard(el: svgBoardType, context?: SVGElement) {
94
- let _el: svgBoardType | string = el
95
-
96
- if (typeof el == "string")
97
- _el =
98
- {
99
- text: "text",
100
- path: "path",
101
- arc: "path",
102
- circle: "circle",
103
- rect: "rect",
104
- }[el] || ""
105
-
106
- if (_el == "") throw new Error("Unsupported drawing method:" + el)
107
- return this.appendEl(_el as svgElType, context)
108
- }
109
-
110
- // 删除当前维护的节点
111
- remove() {
112
- if (!this.__useEl) {
113
- throw new Error("Currently, no node can be deleted.")
114
- } else {
115
- ((this.__useEl as SVGElement).parentNode as SVGElement).removeChild(
116
- this.__useEl
117
- )
118
- }
119
- return this
120
- }
121
-
122
- // 设置或获取节点属性
123
- attr(params: any) {
124
- if (!this.__useEl)
125
- throw new Error("Currently, no node can be modified or viewed.")
126
-
127
- if (typeof params !== "object") {
128
- return getAttribute(this.__useEl, params)
129
- } else {
130
- for (const key in params) {
131
- setAttribute(this.__useEl, key, params[key])
132
- }
133
- return this
134
- }
135
- }
136
-
137
- /**
138
- * 绘制方法
139
- * ---------------------------------
140
- */
141
-
142
- // 文字
143
- // deg表示文字旋转角度,是角度值,不是弧度
144
- fillText(text: string, x: number, y: number, deg: number = 0) {
145
- initText(this.__useEl, this.__config, x, y, deg)
146
- this.__useEl.textContent = text
147
- fill(this.__useEl, this.__config)
148
- return this
149
- }
150
- strokeText(text: string, x: number, y: number, deg: number = 0) {
151
- initText(this.__useEl, this.__config, x, y, deg)
152
- this.__useEl.textContent = text
153
- stroke(this.__useEl, this.__config)
154
- return this
155
- }
156
- fullText(text: string, x: number, y: number, deg: number = 0) {
157
- initText(this.__useEl, this.__config, x, y, deg)
158
- this.__useEl.textContent = text
159
- full(this.__useEl, this.__config)
160
- return this
161
- }
162
-
163
- // 弧
164
- fillArc(
165
- cx: number,
166
- cy: number,
167
- r1: number,
168
- r2: number,
169
- beginDeg: number,
170
- deg: number
171
- ) {
172
- initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg)
173
- fill(this.__useEl, this.__config)
174
- return this
175
- }
176
- strokeArc(
177
- cx: number,
178
- cy: number,
179
- r1: number,
180
- r2: number,
181
- beginDeg: number,
182
- deg: number
183
- ) {
184
- initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg)
185
- stroke(this.__useEl, this.__config)
186
- return this
187
- }
188
- fullArc(
189
- cx: number,
190
- cy: number,
191
- r1: number,
192
- r2: number,
193
- beginDeg: number,
194
- deg: number
195
- ) {
196
- initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg)
197
- full(this.__useEl, this.__config)
198
- return this
199
- }
200
-
201
- // 圆形
202
- fillCircle(cx: number, cy: number, r: number) {
203
- initCircle(this.__useEl, cx, cy, r)
204
- fill(this.__useEl, this.__config)
205
- return this
206
- }
207
- strokeCircle(cx: number, cy: number, r: number) {
208
- initCircle(this.__useEl, cx, cy, r)
209
- stroke(this.__useEl, this.__config)
210
- return this
211
- }
212
- fullCircle(cx: number, cy: number, r: number) {
213
- initCircle(this.__useEl, cx, cy, r)
214
- full(this.__useEl, this.__config)
215
- return this
216
- }
217
-
218
- // 矩形
219
- fillRect(x: number, y: number, width: number, height: number) {
220
- initRect(this.__useEl, x, y, width, height)
221
- fill(this.__useEl, this.__config)
222
- return this
223
- }
224
- strokeRect(x: number, y: number, width: number, height: number) {
225
- initRect(this.__useEl, x, y, width, height)
226
- stroke(this.__useEl, this.__config)
227
- return this
228
- }
229
- fullRect(x: number, y: number, width: number, height: number) {
230
- initRect(this.__useEl, x, y, width, height)
231
- full(this.__useEl, this.__config)
232
- return this
233
- }
234
-
235
- // 路径
236
- beginPath() {
237
- this.__currentPosition = []
238
- this.__path = ""
239
- return this
240
- }
241
- closePath() {
242
- this.__path += "Z"
243
- return this
244
- }
245
- moveTo(x: number, y: number) {
246
- this.__currentPosition = [x, y]
247
-
248
- this.__path += "M" + x + " " + y
249
- return this
250
- }
251
- lineTo(x: number, y: number) {
252
- this.__currentPosition = [x, y]
253
-
254
- this.__path += (this.__path == "" ? "M" : "L") + x + " " + y
255
- return this
256
- }
257
- fill() {
258
- initPath(this.__useEl, this.__path)
259
- fill(this.__useEl, this.__config)
260
- return this
261
- }
262
- stroke() {
263
- initPath(this.__useEl, this.__path)
264
- stroke(this.__useEl, this.__config)
265
- return this
266
- }
267
- full() {
268
- initPath(this.__useEl, this.__path);
269
- full(this.__useEl, this.__config)
270
- return this
271
- }
272
-
273
- arc(x: number, y: number, r: number, beginDeg: number, deg: number) {
274
- const begPosition = rotate(x, y, (beginDeg / 180) * Math.PI, x + r, y)
275
- const endPosition = rotate(
276
- x,
277
- y,
278
- ((beginDeg + deg) / 180) * Math.PI,
279
- x + r,
280
- y
281
- )
282
- // 如果当前没有路径,说明是开始的,就移动到正确位置
283
- if (this.__path == "") {
284
- this.__path += "M" + begPosition[0] + "," + begPosition[1]
285
- }
286
- // 如果当前有路径,位置不正确,应该画到正确位置(和canvas保持一致)
287
- else if (
288
- begPosition[0] != this.__currentPosition[0] ||
289
- begPosition[1] != this.__currentPosition[1]
290
- ) {
291
- this.__path += "L" + begPosition[0] + "," + begPosition[1]
292
- }
293
- this.__path +=
294
- "A" +
295
- r +
296
- "," +
297
- r +
298
- " 0 " +
299
- (deg > 180 || deg < -180 ? 1 : 0) +
300
- "," +
301
- (deg > 0 ? 1 : 0) +
302
- " " +
303
- endPosition[0] +
304
- "," +
305
- endPosition[1]
306
- return this
307
- }
308
-
309
- // 路径 - 贝塞尔曲线
310
- quadraticCurveTo(cpx: number, cpy: number, x: number, y: number) {
311
- this.__path += "Q" + cpx + " " + cpy + "," + x + " " + y
312
- return this
313
- }
314
- bezierCurveTo(
315
- cp1x: number,
316
- cp1y: number,
317
- cp2x: number,
318
- cp2y: number,
319
- x: number,
320
- y: number
321
- ) {
322
- this.__path +=
323
- "C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y
324
- return this
325
- }
326
-
327
- // 绑定事件
328
- bind(eventType: string, callback: (event: Event, target: SVGElement) => void) {
329
- this.__useEl.addEventListener(eventType, function (event: Event) {
330
- callback.call(this, event, this)
331
- }, false)
332
- return this
333
- }
334
-
335
-
336
- // 线性渐变
337
- createLinearGradient(x0: number, y0: number, x1: number, y1: number) {
338
- return linearGradient(this.__svg, x0, y0, x1, y1)
339
- }
340
-
341
- // 环形渐变
342
- createRadialGradient(cx: number, cy: number, r: number) {
343
- return radialGradient(this.__svg, cx, cy, r)
344
- }
345
- }
346
-
347
- export default SVG
1
+ import type { default as SVGConfigType, svgElType, svgBoardType } from "../../../types/SVGConfig"
2
+ import type { arcCapType, textAlignType, textBaselineType, lineCapType, lineJoinType } from "../../../types/painterConfig"
3
+
4
+ import { initText, initCircle, initPath, initRect, initArc } from "./config"
5
+ import { toNode, setAttribute, getAttribute, full, fill, stroke } from "./tool"
6
+ import rotate from "../../rotate"
7
+ import { linearGradient, radialGradient } from "./gradient"
8
+
9
+ class SVG {
10
+ readonly name: string = "SVG"
11
+
12
+ // 用于记录配置
13
+ private __config = {
14
+
15
+ // 颜色
16
+ fillStyle: "#000",
17
+ strokeStyle: "#000",
18
+
19
+ // 文字对齐方式
20
+ textAlign: <textAlignType>"left",
21
+ textBaseline: <textBaselineType>"middle",
22
+
23
+ // 文字
24
+ "fontSize": 16,
25
+ "fontFamily": "sans-serif",
26
+
27
+ // arc二端闭合方式['butt':直线闭合,'round':圆帽闭合]
28
+ "arcStartCap": <arcCapType>"butt",
29
+ "arcEndCap": <arcCapType>"butt",
30
+
31
+ // 线条
32
+ lineDash: [],
33
+ lineWidth: 1,
34
+ lineCap: <lineCapType>"butt",
35
+ lineJoin: <lineJoinType>"miter"
36
+ }
37
+
38
+ // 作用的节点
39
+ private __useEl: SVGElement
40
+
41
+ // 路径(和canvas2D的类似)
42
+ private __path: string = ""
43
+ private __currentPosition: number[] = []
44
+
45
+ private __svg: SVGElement
46
+ constructor(svg: SVGElement) {
47
+ this.__svg = svg
48
+ }
49
+
50
+ // 属性设置或获取
51
+ config(params: SVGConfigType) {
52
+ if (typeof params !== "object") {
53
+ return this.__config[params]
54
+ } else {
55
+ for (const key in params) {
56
+ this.__config[key] = params[key]
57
+ }
58
+ }
59
+ return this
60
+ }
61
+
62
+ /**
63
+ * 基础方法
64
+ * ---------------------------------
65
+ */
66
+
67
+ // 标记应用节点
68
+ // 也就是后续操作都会作用在此节点
69
+ useEl(el: SVGElement) {
70
+ this.__useEl = el
71
+ return this
72
+ }
73
+
74
+ // 获取当前应用的节点
75
+ getEl() {
76
+ return this.__useEl
77
+ }
78
+
79
+ // 追加节点
80
+ // el可以是结点或字符串,字符串的话表示节点名称
81
+ // context可选,表示追加位置,可选,默认根svg
82
+ // 此外,和appendBoard等操作一样,执行后新加入的结点会自动变成应用节点
83
+ appendEl(el: svgElType, context?: SVGElement) {
84
+ context = context || this.__svg
85
+
86
+ if (typeof el == "string") el = toNode(el)
87
+ context.appendChild(el as SVGElement)
88
+
89
+ this.__useEl = el as SVGElement
90
+ return this
91
+ }
92
+
93
+ // 追加绘制板
94
+ // 参数和appendEl类似,只是el如果是字符串的话,表示需要绘制对应什么内容,
95
+ // 比如el = “arc”,表示画弧(不是路径arc),那么我们会创建path节点,因为我们是使用path实现的
96
+ appendBoard(el: svgBoardType, context?: SVGElement) {
97
+ let _el: svgBoardType | string = el
98
+
99
+ if (typeof el == "string")
100
+ _el =
101
+ {
102
+ text: "text",
103
+ path: "path",
104
+ arc: "path",
105
+ circle: "circle",
106
+ rect: "rect",
107
+ }[el] || ""
108
+
109
+ if (_el == "") throw new Error("Unsupported drawing method:" + el)
110
+ return this.appendEl(_el as svgElType, context)
111
+ }
112
+
113
+ // 删除当前维护的节点
114
+ remove() {
115
+ if (!this.__useEl) {
116
+ throw new Error("Currently, no node can be deleted.")
117
+ } else {
118
+ ((this.__useEl as SVGElement).parentNode as SVGElement).removeChild(
119
+ this.__useEl
120
+ )
121
+ }
122
+ return this
123
+ }
124
+
125
+ // 设置或获取节点属性
126
+ attr(params: any) {
127
+ if (!this.__useEl)
128
+ throw new Error("Currently, no node can be modified or viewed.")
129
+
130
+ if (typeof params !== "object") {
131
+ return getAttribute(this.__useEl, params)
132
+ } else {
133
+ for (const key in params) {
134
+ setAttribute(this.__useEl, key, params[key])
135
+ }
136
+ return this
137
+ }
138
+ }
139
+
140
+ /**
141
+ * 绘制方法
142
+ * ---------------------------------
143
+ */
144
+
145
+ // 文字
146
+ // deg表示文字旋转角度,是角度值,不是弧度
147
+ fillText(text: string, x: number, y: number, deg: number = 0) {
148
+ initText(this.__useEl, this.__config, x, y, deg)
149
+ this.__useEl.textContent = text
150
+ fill(this.__useEl, this.__config)
151
+ return this
152
+ }
153
+ strokeText(text: string, x: number, y: number, deg: number = 0) {
154
+ initText(this.__useEl, this.__config, x, y, deg)
155
+ this.__useEl.textContent = text
156
+ stroke(this.__useEl, this.__config)
157
+ return this
158
+ }
159
+ fullText(text: string, x: number, y: number, deg: number = 0) {
160
+ initText(this.__useEl, this.__config, x, y, deg)
161
+ this.__useEl.textContent = text
162
+ full(this.__useEl, this.__config)
163
+ return this
164
+ }
165
+
166
+ // 弧
167
+ fillArc(
168
+ cx: number,
169
+ cy: number,
170
+ r1: number,
171
+ r2: number,
172
+ beginDeg: number,
173
+ deg: number
174
+ ) {
175
+ initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg)
176
+ fill(this.__useEl, this.__config)
177
+ return this
178
+ }
179
+ strokeArc(
180
+ cx: number,
181
+ cy: number,
182
+ r1: number,
183
+ r2: number,
184
+ beginDeg: number,
185
+ deg: number
186
+ ) {
187
+ initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg)
188
+ stroke(this.__useEl, this.__config)
189
+ return this
190
+ }
191
+ fullArc(
192
+ cx: number,
193
+ cy: number,
194
+ r1: number,
195
+ r2: number,
196
+ beginDeg: number,
197
+ deg: number
198
+ ) {
199
+ initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg)
200
+ full(this.__useEl, this.__config)
201
+ return this
202
+ }
203
+
204
+ // 圆形
205
+ fillCircle(cx: number, cy: number, r: number) {
206
+ initCircle(this.__useEl, cx, cy, r)
207
+ fill(this.__useEl, this.__config)
208
+ return this
209
+ }
210
+ strokeCircle(cx: number, cy: number, r: number) {
211
+ initCircle(this.__useEl, cx, cy, r)
212
+ stroke(this.__useEl, this.__config)
213
+ return this
214
+ }
215
+ fullCircle(cx: number, cy: number, r: number) {
216
+ initCircle(this.__useEl, cx, cy, r)
217
+ full(this.__useEl, this.__config)
218
+ return this
219
+ }
220
+
221
+ // 矩形
222
+ fillRect(x: number, y: number, width: number, height: number) {
223
+ initRect(this.__useEl, x, y, width, height)
224
+ fill(this.__useEl, this.__config)
225
+ return this
226
+ }
227
+ strokeRect(x: number, y: number, width: number, height: number) {
228
+ initRect(this.__useEl, x, y, width, height)
229
+ stroke(this.__useEl, this.__config)
230
+ return this
231
+ }
232
+ fullRect(x: number, y: number, width: number, height: number) {
233
+ initRect(this.__useEl, x, y, width, height)
234
+ full(this.__useEl, this.__config)
235
+ return this
236
+ }
237
+
238
+ // 路径
239
+ beginPath() {
240
+ this.__currentPosition = []
241
+ this.__path = ""
242
+ return this
243
+ }
244
+ closePath() {
245
+ this.__path += "Z"
246
+ return this
247
+ }
248
+ moveTo(x: number, y: number) {
249
+ this.__currentPosition = [x, y]
250
+
251
+ this.__path += "M" + x + " " + y
252
+ return this
253
+ }
254
+ lineTo(x: number, y: number) {
255
+ this.__currentPosition = [x, y]
256
+
257
+ this.__path += (this.__path == "" ? "M" : "L") + x + " " + y
258
+ return this
259
+ }
260
+ fill() {
261
+ initPath(this.__useEl, this.__path, this.__config)
262
+ fill(this.__useEl, this.__config)
263
+ return this
264
+ }
265
+ stroke() {
266
+ initPath(this.__useEl, this.__path, this.__config)
267
+ stroke(this.__useEl, this.__config)
268
+ return this
269
+ }
270
+ full() {
271
+ initPath(this.__useEl, this.__path, this.__config);
272
+ full(this.__useEl, this.__config)
273
+ return this
274
+ }
275
+
276
+ arc(x: number, y: number, r: number, beginDeg: number, deg: number) {
277
+ const begPosition = rotate(x, y, (beginDeg / 180) * Math.PI, x + r, y)
278
+ const endPosition = rotate(
279
+ x,
280
+ y,
281
+ ((beginDeg + deg) / 180) * Math.PI,
282
+ x + r,
283
+ y
284
+ )
285
+ // 如果当前没有路径,说明是开始的,就移动到正确位置
286
+ if (this.__path == "") {
287
+ this.__path += "M" + begPosition[0] + "," + begPosition[1]
288
+ }
289
+ // 如果当前有路径,位置不正确,应该画到正确位置(和canvas保持一致)
290
+ else if (
291
+ begPosition[0] != this.__currentPosition[0] ||
292
+ begPosition[1] != this.__currentPosition[1]
293
+ ) {
294
+ this.__path += "L" + begPosition[0] + "," + begPosition[1]
295
+ }
296
+ this.__path +=
297
+ "A" +
298
+ r +
299
+ "," +
300
+ r +
301
+ " 0 " +
302
+ (deg > 180 || deg < -180 ? 1 : 0) +
303
+ "," +
304
+ (deg > 0 ? 1 : 0) +
305
+ " " +
306
+ endPosition[0] +
307
+ "," +
308
+ endPosition[1]
309
+ return this
310
+ }
311
+
312
+ // 路径 - 贝塞尔曲线
313
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number) {
314
+ this.__path += "Q" + cpx + " " + cpy + "," + x + " " + y
315
+ return this
316
+ }
317
+ bezierCurveTo(
318
+ cp1x: number,
319
+ cp1y: number,
320
+ cp2x: number,
321
+ cp2y: number,
322
+ x: number,
323
+ y: number
324
+ ) {
325
+ this.__path +=
326
+ "C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y
327
+ return this
328
+ }
329
+
330
+ // 绑定事件
331
+ bind(eventType: string, callback: (event: Event, target: SVGElement) => void) {
332
+ this.__useEl.addEventListener(eventType, function (event: Event) {
333
+ callback.call(this, event, this)
334
+ }, false)
335
+ return this
336
+ }
337
+
338
+
339
+ // 线性渐变
340
+ createLinearGradient(x0: number, y0: number, x1: number, y1: number) {
341
+ return linearGradient(this.__svg, x0, y0, x1, y1)
342
+ }
343
+
344
+ // 环形渐变
345
+ createRadialGradient(cx: number, cy: number, r: number) {
346
+ return radialGradient(this.__svg, cx, cy, r)
347
+ }
348
+ }
349
+
350
+ export default SVG