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.
- package/CHANGELOG +266 -254
- package/lib/Buffer/index.es.js +1 -1
- package/lib/Buffer/index.es.min.js +1 -1
- package/lib/Canvas/index.es.js +16 -5
- package/lib/Canvas/index.es.min.js +2 -2
- package/lib/Cardinal/index.es.js +1 -1
- package/lib/Cardinal/index.es.min.js +1 -1
- package/lib/Eoap/index.es.js +1 -1
- package/lib/Eoap/index.es.min.js +1 -1
- package/lib/Hermite/index.es.js +1 -1
- package/lib/Hermite/index.es.min.js +1 -1
- package/lib/Matrix4/index.es.js +1 -1
- package/lib/Matrix4/index.es.min.js +1 -1
- package/lib/Mercator/index.es.js +1 -1
- package/lib/Mercator/index.es.min.js +1 -1
- package/lib/RawCanvas/index.es.js +15 -4
- package/lib/RawCanvas/index.es.min.js +2 -2
- package/lib/SVG/index.es.js +12 -8
- package/lib/SVG/index.es.min.js +2 -2
- package/lib/Shader/index.es.js +1 -1
- package/lib/Shader/index.es.min.js +1 -1
- package/lib/Texture/index.es.js +1 -1
- package/lib/Texture/index.es.min.js +1 -1
- package/lib/TreeLayout/index.es.js +38 -8
- package/lib/TreeLayout/index.es.min.js +2 -2
- package/lib/animation/index.es.js +38 -8
- package/lib/animation/index.es.min.js +2 -2
- package/lib/assemble/index.es.js +1 -1
- package/lib/assemble/index.es.min.js +1 -1
- package/lib/getLoopColors/index.es.js +1 -1
- package/lib/getLoopColors/index.es.min.js +1 -1
- package/lib/getWebGLContext/index.es.js +1 -1
- package/lib/getWebGLContext/index.es.min.js +1 -1
- package/lib/index.umd.js +88 -36
- package/lib/index.umd.min.js +2 -2
- package/lib/initOption/index.es.js +1 -1
- package/lib/initOption/index.es.min.js +1 -1
- package/lib/mergeOption/index.es.js +1 -1
- package/lib/mergeOption/index.es.min.js +1 -1
- package/lib/move/index.es.js +1 -1
- package/lib/move/index.es.min.js +1 -1
- package/lib/rotate/index.es.js +1 -1
- package/lib/rotate/index.es.min.js +1 -1
- package/lib/ruler/index.es.js +1 -1
- package/lib/ruler/index.es.min.js +1 -1
- package/lib/scale/index.es.js +1 -1
- package/lib/scale/index.es.min.js +1 -1
- package/lib/throttle/index.es.js +25 -25
- package/lib/throttle/index.es.min.js +2 -2
- package/miniprogram/ui-canvas/index.js +115 -115
- package/package/animation/index.ts +1 -1
- package/package/throttle/index.ts +1 -1
- package/package.json +7 -2
- package/src/Canvas.ts +84 -84
- package/src/common/canvas/gradient.ts +32 -24
- package/src/common/canvas/index.ts +182 -177
- package/src/common/canvas/painter.ts +9 -3
- package/src/common/svg/config.ts +194 -190
- package/src/common/svg/index.ts +350 -347
- package/src/common/svg/tool.ts +42 -44
- package/src/layout/TreeLayout.ts +1 -1
- package/types/Canvas.d.ts +10 -1
- package/types/CanvasConfig.d.ts +116 -106
- package/types/SVGConfig.d.ts +89 -79
- package/types/animation.d.ts +2 -6
- package/types/index.d.ts +160 -158
- package/types/painterConfig.d.ts +5 -3
- package/types/throttle.d.ts +2 -4
- package/types/throttleOption.d.ts +1 -22
- package/types/uni-canvas.d.ts +4 -0
- package/src/animation.ts +0 -99
- package/src/throttle.ts +0 -53
package/src/common/svg/index.ts
CHANGED
|
@@ -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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
private
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
private
|
|
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
|
-
context
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
if (
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
this
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
this
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
this
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
x
|
|
280
|
-
y
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
"
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|