vislite 0.4.1-alpha.2 → 0.4.1-beta.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/.editorconfig +19 -0
- package/CHANGELOG +17 -8
- package/README.md +16 -1
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +89 -10
- 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/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 +79 -8
- package/lib/OralCanvas/index.es.min.js +3 -3
- package/lib/OralWebGL/index.es.js +35 -10
- 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 +82 -3
- package/lib/Shader/index.umd.min.js +3 -3
- package/lib/Texture/index.umd.js +3 -5
- package/lib/Texture/index.umd.min.js +3 -3
- package/lib/TreeLayout/index.umd.js +427 -0
- package/lib/TreeLayout/index.umd.min.js +11 -0
- package/lib/WebGL/index.umd.js +45 -12
- package/lib/WebGL/index.umd.min.js +3 -3
- package/lib/animation/index.umd.js +3 -3
- package/lib/animation/index.umd.min.js +2 -2
- package/lib/formatColor/index.umd.js +59 -0
- package/lib/formatColor/index.umd.min.js +11 -0
- 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 +555 -23
- package/lib/index.umd.min.js +3 -3
- package/lib/resizeObserver/index.umd.js +48 -0
- package/lib/resizeObserver/index.umd.min.js +11 -0
- 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/throttle/index.umd.js +68 -0
- package/lib/throttle/index.umd.min.js +11 -0
- package/lib/viewHandler/index.umd.js +2 -2
- package/lib/viewHandler/index.umd.min.js +2 -2
- package/package/Buffer/index.ts +1 -0
- package/package/Canvas/index.ts +1 -0
- package/package/OralCanvas/index.ts +1 -0
- package/package/OralWebGL/index.ts +1 -0
- package/package/Shader/index.ts +39 -1
- package/package/Texture/index.ts +1 -0
- package/package/TreeLayout/index.ts +3 -0
- package/package/WebGL/index.ts +1 -0
- package/package/formatColor/index.ts +3 -0
- package/package/index.ts +12 -1
- package/package/resizeObserver/index.ts +3 -0
- package/package/throttle/index.ts +3 -0
- package/package.json +1 -1
- package/src/Canvas.ts +7 -3
- package/src/Eoap.ts +1 -1
- package/src/Matrix4/index.ts +1 -1
- package/src/Mercator.ts +1 -1
- package/src/SVG.ts +2 -1
- package/src/TreeLayout/index.ts +186 -0
- package/src/WebGL.ts +7 -3
- package/src/animation.ts +2 -3
- package/src/common/canvas/config.ts +2 -1
- package/src/common/canvas/index.ts +10 -3
- package/src/common/canvas/painter.ts +74 -5
- package/src/common/mergeOption.ts +7 -0
- package/src/common/svg/config.ts +2 -1
- package/src/common/svg/index.ts +2 -1
- package/src/common/svg/tool.ts +2 -1
- package/src/common/tree/index.ts +26 -0
- package/src/common/tree/toInnerTree.ts +57 -0
- package/src/common/tree/toPlainTree.ts +132 -0
- package/src/common/webgl/doDraw.ts +2 -0
- package/src/common/webgl/getShader.ts +25 -52
- package/src/common/webgl/index.ts +4 -3
- package/src/common/webgl/texture.ts +2 -5
- package/src/formatColor.ts +45 -0
- package/src/interpolation/Cardinal.ts +2 -1
- package/src/interpolation/Hermite.ts +1 -1
- package/src/resizeObserver.ts +37 -0
- package/src/ruler.ts +1 -1
- package/src/shader/fsColor.c +8 -0
- package/src/shader/fsColors.c +8 -0
- package/src/shader/fsCube.c +9 -0
- package/src/shader/fsImage.c +9 -0
- package/src/shader/vsColor.c +18 -0
- package/src/shader/vsColors.c +14 -0
- package/src/shader/vsCube.c +14 -0
- package/src/shader/vsImage.c +14 -0
- package/src/throttle.ts +50 -0
- package/src/viewHandler.ts +1 -1
- package/types/Canvas.d.ts +12 -0
- package/types/CanvasOption.d.ts +2 -2
- package/types/Shader.d.ts +6 -0
- package/types/Tree.d.ts +38 -0
- package/types/TreeConfig.d.ts +25 -0
- package/types/TreeLayout.d.ts +49 -0
- package/types/TreeOption.d.ts +46 -0
- package/types/formatColor.d.ts +3 -0
- package/types/index.d.ts +24 -1
- package/types/resizeObserver.d.ts +3 -0
- package/types/throttle.d.ts +5 -0
- package/types/throttleOption.d.ts +20 -0
package/src/Canvas.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import CanvasType from '../types/Canvas'
|
|
1
|
+
import type CanvasType from '../types/Canvas'
|
|
2
|
+
import type CanvasOptionType from '../types/CanvasOption'
|
|
3
|
+
|
|
2
4
|
import OralCanvas from './common/canvas/index'
|
|
3
|
-
import
|
|
5
|
+
import mergeOption from './common/mergeOption'
|
|
4
6
|
|
|
5
7
|
class Canvas extends OralCanvas implements CanvasType {
|
|
6
8
|
private __canvas: HTMLCanvasElement
|
|
@@ -9,7 +11,9 @@ class Canvas extends OralCanvas implements CanvasType {
|
|
|
9
11
|
throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.")
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
option = mergeOption(option, {
|
|
15
|
+
region: true
|
|
16
|
+
})
|
|
13
17
|
|
|
14
18
|
let width = el.clientWidth, height = el.clientHeight
|
|
15
19
|
|
package/src/Eoap.ts
CHANGED
package/src/Matrix4/index.ts
CHANGED
package/src/Mercator.ts
CHANGED
package/src/SVG.ts
CHANGED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type TreeLayoutType from '../../types/TreeLayout'
|
|
2
|
+
import type { TreeResultType } from '../../types/Tree'
|
|
3
|
+
import type TreeOptionType from '../../types/TreeOption'
|
|
4
|
+
|
|
5
|
+
import Tree from '../common/tree/index'
|
|
6
|
+
import mergeOption from '../common/mergeOption'
|
|
7
|
+
import animation from '../animation'
|
|
8
|
+
import rotate from '../rotate'
|
|
9
|
+
|
|
10
|
+
class TreeLayout extends Tree implements TreeLayoutType {
|
|
11
|
+
readonly name: string = 'TreeLayout'
|
|
12
|
+
|
|
13
|
+
private __option: TreeOptionType = {
|
|
14
|
+
offsetX: 0,
|
|
15
|
+
offsetY: 0,
|
|
16
|
+
duration: 500,
|
|
17
|
+
type: "plain",
|
|
18
|
+
direction: "LR",
|
|
19
|
+
x: 100,
|
|
20
|
+
y: 100,
|
|
21
|
+
width: 100,
|
|
22
|
+
height: 100,
|
|
23
|
+
radius: 100
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private __rback: (tree: TreeResultType) => void
|
|
27
|
+
private __oralTree: any
|
|
28
|
+
private __preTree: TreeResultType
|
|
29
|
+
|
|
30
|
+
private __noOpens = {}
|
|
31
|
+
|
|
32
|
+
setOption(option: TreeOptionType) {
|
|
33
|
+
mergeOption(option, this.__option)
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
use(initTree: any, noOpens?: {}) {
|
|
38
|
+
let tree = super.use(initTree, noOpens)
|
|
39
|
+
|
|
40
|
+
// 校对偏差
|
|
41
|
+
if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
|
|
42
|
+
for (let key in tree.node) {
|
|
43
|
+
if (!tree.node[key].show) {
|
|
44
|
+
|
|
45
|
+
let deep = 0, pid = key
|
|
46
|
+
do {
|
|
47
|
+
pid = tree.node[pid].pid
|
|
48
|
+
deep++
|
|
49
|
+
} while (!tree.node[pid].show)
|
|
50
|
+
|
|
51
|
+
tree.node[key].left += this.__option.offsetX * deep
|
|
52
|
+
tree.node[key].top += this.__option.offsetY * deep
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.__option.type == 'rect') {
|
|
58
|
+
if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
|
|
59
|
+
|
|
60
|
+
let perW = this.__option.height / tree.size
|
|
61
|
+
let perD = this.__option.width / (tree.deep - 1)
|
|
62
|
+
|
|
63
|
+
let balanceW = this.__option.y - this.__option.height * 0.5
|
|
64
|
+
let flag = this.__option.direction == 'LR' ? 1 : -1
|
|
65
|
+
|
|
66
|
+
for (let key in tree.node) {
|
|
67
|
+
if (tree.deep == 1) {
|
|
68
|
+
tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag
|
|
69
|
+
tree.node[key].top = this.__option.y
|
|
70
|
+
} else {
|
|
71
|
+
tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag
|
|
72
|
+
tree.node[key].top = tree.node[key].top * perW + balanceW
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
|
|
76
|
+
|
|
77
|
+
let perW = this.__option.width / tree.size
|
|
78
|
+
let perD = this.__option.height / (tree.deep - 1)
|
|
79
|
+
|
|
80
|
+
let balanceW = this.__option.x - this.__option.width * 0.5
|
|
81
|
+
let flag = this.__option.direction == 'TB' ? 1 : -1
|
|
82
|
+
|
|
83
|
+
for (let key in tree.node) {
|
|
84
|
+
if (tree.deep == 1) {
|
|
85
|
+
tree.node[key].left = this.__option.x
|
|
86
|
+
tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag
|
|
87
|
+
} else {
|
|
88
|
+
let left = tree.node[key].left
|
|
89
|
+
|
|
90
|
+
tree.node[key].left = tree.node[key].top * perW + balanceW
|
|
91
|
+
tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
} else if (this.__option.type == 'circle') {
|
|
98
|
+
let cx = this.__option.x, cy = this.__option.y
|
|
99
|
+
let deg = Math.PI * 2 / tree.size
|
|
100
|
+
let per = this.__option.radius / (tree.deep - 1)
|
|
101
|
+
|
|
102
|
+
for (let key in tree.node) {
|
|
103
|
+
if (tree.node[key].left == 0.5) {
|
|
104
|
+
tree.node[key].left = cx
|
|
105
|
+
tree.node[key].top = cy
|
|
106
|
+
} else {
|
|
107
|
+
let position = rotate(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy)
|
|
108
|
+
|
|
109
|
+
tree.node[key].left = position[0]
|
|
110
|
+
tree.node[key].top = position[1]
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return tree
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
bind(initTree: any, renderBack: (tree: TreeResultType) => void) {
|
|
119
|
+
this.__rback = renderBack
|
|
120
|
+
this.__oralTree = initTree
|
|
121
|
+
|
|
122
|
+
this.__preTree = this.use(this.__oralTree)
|
|
123
|
+
this.__rback(this.__preTree)
|
|
124
|
+
|
|
125
|
+
return this
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
unbind() {
|
|
129
|
+
this.__rback = null
|
|
130
|
+
this.__oralTree = null
|
|
131
|
+
this.__preTree = null
|
|
132
|
+
this.__noOpens = {}
|
|
133
|
+
return this
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private doUpdate() {
|
|
137
|
+
let newTree = this.use(this.__oralTree, this.__noOpens)
|
|
138
|
+
|
|
139
|
+
let cacheTree = JSON.parse(JSON.stringify(newTree))
|
|
140
|
+
|
|
141
|
+
animation((deep) => {
|
|
142
|
+
|
|
143
|
+
for (let key in cacheTree.node) {
|
|
144
|
+
if (newTree.node[key].show || this.__preTree.node[key].show) {
|
|
145
|
+
cacheTree.node[key].show = true
|
|
146
|
+
|
|
147
|
+
cacheTree.node[key].left = this.__preTree.node[key].left + (newTree.node[key].left - this.__preTree.node[key].left) * deep
|
|
148
|
+
cacheTree.node[key].top = this.__preTree.node[key].top + (newTree.node[key].top - this.__preTree.node[key].top) * deep
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
this.__rback(cacheTree)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
}, this.__option.duration, () => {
|
|
155
|
+
this.__preTree = newTree
|
|
156
|
+
this.__rback(this.__preTree)
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
closeNode(id: string) {
|
|
161
|
+
if (!this.__preTree) return
|
|
162
|
+
this.__noOpens[id] = true
|
|
163
|
+
|
|
164
|
+
this.doUpdate()
|
|
165
|
+
return this
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
openNode(id: string) {
|
|
169
|
+
if (!this.__preTree) return
|
|
170
|
+
this.__noOpens[id] = false
|
|
171
|
+
|
|
172
|
+
this.doUpdate()
|
|
173
|
+
return this
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
toggleNode(id: string) {
|
|
177
|
+
if (!this.__preTree) return
|
|
178
|
+
this.__noOpens[id] = !this.__noOpens[id]
|
|
179
|
+
|
|
180
|
+
this.doUpdate()
|
|
181
|
+
return this
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export default TreeLayout
|
package/src/WebGL.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type WebGLOptionType from '../types/WebGLOption'
|
|
2
|
+
import type WebGLType from '../types/WebGL'
|
|
3
|
+
|
|
2
4
|
import OralWebGL from './common/webgl/index'
|
|
3
|
-
import
|
|
5
|
+
import mergeOption from './common/mergeOption'
|
|
4
6
|
|
|
5
7
|
class WebGL extends OralWebGL implements WebGLType {
|
|
6
8
|
constructor(el: HTMLElement | null, option: WebGLOptionType = {}) {
|
|
@@ -8,7 +10,9 @@ class WebGL extends OralWebGL implements WebGLType {
|
|
|
8
10
|
throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.")
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
option = mergeOption(option, {
|
|
14
|
+
region: true
|
|
15
|
+
})
|
|
12
16
|
|
|
13
17
|
let width = el.clientWidth, height = el.clientHeight
|
|
14
18
|
|
package/src/animation.ts
CHANGED
|
@@ -15,7 +15,6 @@ let $timerId: any
|
|
|
15
15
|
*/
|
|
16
16
|
export default function (doback: (deep: number) => void, duration: number = 400, callback: (deep: number) => void = () => { }): Function {
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
let clock = {
|
|
20
19
|
//把tick函数推入堆栈
|
|
21
20
|
"timer": function (tick: (deep: number) => void, duration: number, callback: (deep: number) => void) {
|
|
@@ -78,7 +77,7 @@ export default function (doback: (deep: number) => void, duration: number = 400,
|
|
|
78
77
|
$timerId = null
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
|
-
}
|
|
80
|
+
}
|
|
82
81
|
|
|
83
82
|
let id = clock.timer(function (deep: number) {
|
|
84
83
|
//其中deep为0-1,表示改变的程度
|
|
@@ -91,7 +90,7 @@ export default function (doback: (deep: number) => void, duration: number = 400,
|
|
|
91
90
|
let i: string
|
|
92
91
|
for (i in $timers) {
|
|
93
92
|
if ($timers[i].id == id) {
|
|
94
|
-
$timers[i].id =
|
|
93
|
+
$timers[i].id = void 0
|
|
95
94
|
return
|
|
96
95
|
}
|
|
97
96
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import CanvasConfigType from "../../../types/CanvasConfig"
|
|
1
|
+
import type CanvasConfigType from "../../../types/CanvasConfig"
|
|
2
|
+
|
|
2
3
|
import PainterRender from "./painter"
|
|
3
4
|
import assemble from "../assemble"
|
|
4
5
|
import { linearGradient, radialGradient } from "./gradient"
|
|
@@ -29,7 +30,7 @@ class Canvas extends PainterRender {
|
|
|
29
30
|
{},
|
|
30
31
|
RegionCanvas ? new PainterRender(RegionCanvas, {
|
|
31
32
|
willReadFrequently: true,
|
|
32
|
-
}) : null
|
|
33
|
+
}) : null, true
|
|
33
34
|
)
|
|
34
35
|
|
|
35
36
|
this.setRegion("")
|
|
@@ -44,11 +45,17 @@ class Canvas extends PainterRender {
|
|
|
44
45
|
return this
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
// 是否绘制的内容只需要进行区域记录
|
|
49
|
+
onlyRegion(flag: boolean) {
|
|
50
|
+
this.__onlyRegion = flag
|
|
51
|
+
return this
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
// 设置当前绘制区域名称
|
|
48
55
|
setRegion(regionName: string | number) {
|
|
49
56
|
if (this.__region) {
|
|
50
57
|
if (regionName) {
|
|
51
|
-
if (this.__regionList[regionName] ==
|
|
58
|
+
if (this.__regionList[regionName] == void 0) {
|
|
52
59
|
let tempColor = this.__regionAssemble()
|
|
53
60
|
this.__regionList[regionName] =
|
|
54
61
|
"rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")"
|
|
@@ -16,9 +16,12 @@ class Painter {
|
|
|
16
16
|
painter: CanvasRenderingContext2D
|
|
17
17
|
__region: Painter | null | undefined = null
|
|
18
18
|
|
|
19
|
+
__onlyRegion: boolean = false
|
|
20
|
+
__isPainter: boolean
|
|
21
|
+
|
|
19
22
|
// 用于记录配置
|
|
20
23
|
// 因为部分配置的设置比较特殊,只先记录意图
|
|
21
|
-
|
|
24
|
+
__specialConfig = {
|
|
22
25
|
|
|
23
26
|
// 文字大小
|
|
24
27
|
"fontSize": 16,
|
|
@@ -67,9 +70,10 @@ class Painter {
|
|
|
67
70
|
|
|
68
71
|
}
|
|
69
72
|
|
|
70
|
-
constructor(canvas: HTMLCanvasElement, opts: OptsType = {}, region?: Painter) {
|
|
73
|
+
constructor(canvas: HTMLCanvasElement, opts: OptsType = {}, region?: Painter, isPainter = false) {
|
|
71
74
|
this.painter = canvas.getContext("2d", opts) as CanvasRenderingContext2D
|
|
72
75
|
this.__region = region
|
|
76
|
+
this.__isPainter = isPainter
|
|
73
77
|
|
|
74
78
|
// 默认配置canvas2D对象已经存在的属性
|
|
75
79
|
this.painter.textBaseline = 'middle'
|
|
@@ -83,6 +87,8 @@ class Painter {
|
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
|
|
90
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
91
|
+
|
|
86
92
|
/**
|
|
87
93
|
* -----------------------------
|
|
88
94
|
* 特殊的设置开始
|
|
@@ -127,6 +133,8 @@ class Painter {
|
|
|
127
133
|
fillText(text: string, x: number, y: number, deg: number = 0) {
|
|
128
134
|
if (this.__region) this.__region.fillText(text, x, y, deg)
|
|
129
135
|
|
|
136
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
137
|
+
|
|
130
138
|
this.painter.save()
|
|
131
139
|
initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0)
|
|
132
140
|
this.painter.restore()
|
|
@@ -135,6 +143,8 @@ class Painter {
|
|
|
135
143
|
strokeText(text: string, x: number, y: number, deg: number = 0) {
|
|
136
144
|
if (this.__region) this.__region.strokeText(text, x, y, deg)
|
|
137
145
|
|
|
146
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
147
|
+
|
|
138
148
|
this.painter.save()
|
|
139
149
|
initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0)
|
|
140
150
|
this.painter.restore()
|
|
@@ -143,6 +153,8 @@ class Painter {
|
|
|
143
153
|
fullText(text: string, x: number, y: number, deg: number = 0) {
|
|
144
154
|
if (this.__region) this.__region.fullText(text, x, y, deg)
|
|
145
155
|
|
|
156
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
157
|
+
|
|
146
158
|
this.painter.save()
|
|
147
159
|
initText(this.painter, this.__specialConfig, x, y, deg)
|
|
148
160
|
this.painter.fillText(text, 0, 0)
|
|
@@ -153,7 +165,10 @@ class Painter {
|
|
|
153
165
|
|
|
154
166
|
// 多行文字
|
|
155
167
|
fillTexts(contents: string, x: number, y: number, width: number, lineHeight: number = 1.2, deg: number = 0) {
|
|
156
|
-
|
|
168
|
+
let h = 0
|
|
169
|
+
if (this.__region) h = this.__region.fillTexts(contents, x, y, width, lineHeight)
|
|
170
|
+
|
|
171
|
+
if (this.__isPainter && this.__onlyRegion) return h
|
|
157
172
|
|
|
158
173
|
this.painter.save()
|
|
159
174
|
initText(this.painter, this.__specialConfig, x, y, deg)
|
|
@@ -166,7 +181,10 @@ class Painter {
|
|
|
166
181
|
return height
|
|
167
182
|
}
|
|
168
183
|
strokeTexts(contents: string, x: number, y: number, width: number, lineHeight: number = 1.2, deg: number = 0) {
|
|
169
|
-
|
|
184
|
+
let h = 0
|
|
185
|
+
if (this.__region) h = this.__region.fillTexts(contents, x, y, width, lineHeight)
|
|
186
|
+
|
|
187
|
+
if (this.__isPainter && this.__onlyRegion) return h
|
|
170
188
|
|
|
171
189
|
this.painter.save()
|
|
172
190
|
initText(this.painter, this.__specialConfig, x, y, deg)
|
|
@@ -179,7 +197,10 @@ class Painter {
|
|
|
179
197
|
return height
|
|
180
198
|
}
|
|
181
199
|
fullTexts(contents: string, x: number, y: number, width: number, lineHeight: number = 1.2, deg: number = 0) {
|
|
182
|
-
|
|
200
|
+
let h = 0
|
|
201
|
+
if (this.__region) h = this.__region.fillTexts(contents, x, y, width, lineHeight)
|
|
202
|
+
|
|
203
|
+
if (this.__isPainter && this.__onlyRegion) return h
|
|
183
204
|
|
|
184
205
|
this.painter.save()
|
|
185
206
|
initText(this.painter, this.__specialConfig, x, y, deg)
|
|
@@ -197,18 +218,24 @@ class Painter {
|
|
|
197
218
|
beginPath() {
|
|
198
219
|
if (this.__region) this.__region.beginPath()
|
|
199
220
|
|
|
221
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
222
|
+
|
|
200
223
|
this.painter.beginPath()
|
|
201
224
|
return this
|
|
202
225
|
}
|
|
203
226
|
closePath() {
|
|
204
227
|
if (this.__region) this.__region.closePath()
|
|
205
228
|
|
|
229
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
230
|
+
|
|
206
231
|
this.painter.closePath()
|
|
207
232
|
return this
|
|
208
233
|
}
|
|
209
234
|
moveTo(x: number, y: number) {
|
|
210
235
|
if (this.__region) this.__region.moveTo(x, y)
|
|
211
236
|
|
|
237
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
238
|
+
|
|
212
239
|
// 解决1px模糊问题,别的地方类似原因
|
|
213
240
|
this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5)
|
|
214
241
|
return this
|
|
@@ -216,30 +243,40 @@ class Painter {
|
|
|
216
243
|
lineTo(x: number, y: number) {
|
|
217
244
|
if (this.__region) this.__region.lineTo(x, y)
|
|
218
245
|
|
|
246
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
247
|
+
|
|
219
248
|
this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5)
|
|
220
249
|
return this
|
|
221
250
|
}
|
|
222
251
|
arc(x: number, y: number, r: number, beginDeg: number, deg: number) {
|
|
223
252
|
if (this.__region) this.__region.arc(x, y, r, beginDeg, deg)
|
|
224
253
|
|
|
254
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
255
|
+
|
|
225
256
|
this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0)
|
|
226
257
|
return this
|
|
227
258
|
}
|
|
228
259
|
fill() {
|
|
229
260
|
if (this.__region) this.__region.fill()
|
|
230
261
|
|
|
262
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
263
|
+
|
|
231
264
|
this.painter.fill()
|
|
232
265
|
return this
|
|
233
266
|
}
|
|
234
267
|
stroke() {
|
|
235
268
|
if (this.__region) this.__region.stroke()
|
|
236
269
|
|
|
270
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
271
|
+
|
|
237
272
|
this.painter.stroke()
|
|
238
273
|
return this
|
|
239
274
|
}
|
|
240
275
|
full() {
|
|
241
276
|
if (this.__region) this.__region.full()
|
|
242
277
|
|
|
278
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
279
|
+
|
|
243
280
|
this.painter.fill()
|
|
244
281
|
this.painter.stroke()
|
|
245
282
|
return this
|
|
@@ -248,18 +285,24 @@ class Painter {
|
|
|
248
285
|
save() {
|
|
249
286
|
if (this.__region) this.__region.save()
|
|
250
287
|
|
|
288
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
289
|
+
|
|
251
290
|
this.painter.save()
|
|
252
291
|
return this
|
|
253
292
|
}
|
|
254
293
|
restore() {
|
|
255
294
|
if (this.__region) this.__region.restore()
|
|
256
295
|
|
|
296
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
297
|
+
|
|
257
298
|
this.painter.restore()
|
|
258
299
|
return this
|
|
259
300
|
}
|
|
260
301
|
clip() {
|
|
261
302
|
if (this.__region) this.__region.clip()
|
|
262
303
|
|
|
304
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
305
|
+
|
|
263
306
|
this.painter.clip()
|
|
264
307
|
return this
|
|
265
308
|
}
|
|
@@ -268,12 +311,16 @@ class Painter {
|
|
|
268
311
|
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number) {
|
|
269
312
|
if (this.__region) this.__region.quadraticCurveTo(cpx, cpy, x, y)
|
|
270
313
|
|
|
314
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
315
|
+
|
|
271
316
|
this.painter.quadraticCurveTo(cpx, cpy, x, y)
|
|
272
317
|
return this
|
|
273
318
|
}
|
|
274
319
|
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number) {
|
|
275
320
|
if (this.__region) this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
|
|
276
321
|
|
|
322
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
323
|
+
|
|
277
324
|
this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
|
|
278
325
|
return this
|
|
279
326
|
}
|
|
@@ -282,6 +329,8 @@ class Painter {
|
|
|
282
329
|
clearRect(x: number, y: number, w: number, h: number) {
|
|
283
330
|
if (this.__region) this.__region.clearRect(x, y, w, h)
|
|
284
331
|
|
|
332
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
333
|
+
|
|
285
334
|
this.painter.clearRect(x, y, w, h)
|
|
286
335
|
return this
|
|
287
336
|
}
|
|
@@ -290,18 +339,24 @@ class Painter {
|
|
|
290
339
|
fillArc(cx: number, cy: number, r1: number, r2: number, beginDeg: number, deg: number) {
|
|
291
340
|
if (this.__region) this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg)
|
|
292
341
|
|
|
342
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
343
|
+
|
|
293
344
|
initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill()
|
|
294
345
|
return this
|
|
295
346
|
}
|
|
296
347
|
strokeArc(cx: number, cy: number, r1: number, r2: number, beginDeg: number, deg: number) {
|
|
297
348
|
if (this.__region) this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg)
|
|
298
349
|
|
|
350
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
351
|
+
|
|
299
352
|
initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke()
|
|
300
353
|
return this
|
|
301
354
|
}
|
|
302
355
|
fullArc(cx: number, cy: number, r1: number, r2: number, beginDeg: number, deg: number) {
|
|
303
356
|
if (this.__region) this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg)
|
|
304
357
|
|
|
358
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
359
|
+
|
|
305
360
|
initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg)
|
|
306
361
|
this.painter.fill()
|
|
307
362
|
this.painter.stroke()
|
|
@@ -312,18 +367,24 @@ class Painter {
|
|
|
312
367
|
fillCircle(cx: number, cy: number, r: number) {
|
|
313
368
|
if (this.__region) this.__region.fillCircle(cx, cy, r)
|
|
314
369
|
|
|
370
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
371
|
+
|
|
315
372
|
initCircle(this.painter, cx, cy, r).fill()
|
|
316
373
|
return this
|
|
317
374
|
}
|
|
318
375
|
strokeCircle(cx: number, cy: number, r: number) {
|
|
319
376
|
if (this.__region) this.__region.strokeCircle(cx, cy, r)
|
|
320
377
|
|
|
378
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
379
|
+
|
|
321
380
|
initCircle(this.painter, cx, cy, r).stroke()
|
|
322
381
|
return this
|
|
323
382
|
}
|
|
324
383
|
fullCircle(cx: number, cy: number, r: number) {
|
|
325
384
|
if (this.__region) this.__region.fullCircle(cx, cy, r)
|
|
326
385
|
|
|
386
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
387
|
+
|
|
327
388
|
initCircle(this.painter, cx, cy, r)
|
|
328
389
|
this.painter.fill()
|
|
329
390
|
this.painter.stroke()
|
|
@@ -334,23 +395,31 @@ class Painter {
|
|
|
334
395
|
fillRect(x: number, y: number, width: number, height: number) {
|
|
335
396
|
if (this.__region) this.__region.fillRect(x, y, width, height)
|
|
336
397
|
|
|
398
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
399
|
+
|
|
337
400
|
initRect(this.painter, x, y, width, height).fill()
|
|
338
401
|
return this
|
|
339
402
|
}
|
|
340
403
|
strokeRect(x: number, y: number, width: number, height: number) {
|
|
341
404
|
if (this.__region) this.__region.strokeRect(x, y, width, height)
|
|
342
405
|
|
|
406
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
407
|
+
|
|
343
408
|
initRect(this.painter, x, y, width, height).stroke()
|
|
344
409
|
return this
|
|
345
410
|
}
|
|
346
411
|
fullRect(x: number, y: number, width: number, height: number) {
|
|
347
412
|
if (this.__region) this.__region.fullRect(x, y, width, height)
|
|
348
413
|
|
|
414
|
+
if (this.__isPainter && this.__onlyRegion) return this
|
|
415
|
+
|
|
349
416
|
initRect(this.painter, x, y, width, height)
|
|
350
417
|
this.painter.fill()
|
|
351
418
|
this.painter.stroke()
|
|
352
419
|
return this
|
|
353
420
|
}
|
|
421
|
+
|
|
422
|
+
draw() { }
|
|
354
423
|
}
|
|
355
424
|
|
|
356
425
|
export default Painter
|
package/src/common/svg/config.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type SVGConfigType from "../../../types/SVGConfig"
|
|
2
|
+
|
|
1
3
|
import { setAttribute } from "./tool"
|
|
2
4
|
import setStyle from "../setStyle"
|
|
3
5
|
import arc from "../canvas/arc"
|
|
4
|
-
import SVGConfigType from "../../../types/SVGConfig"
|
|
5
6
|
|
|
6
7
|
// 文字统一设置方法
|
|
7
8
|
export let initText = (
|
package/src/common/svg/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type SVGConfigType from "../../../types/SVGConfig"
|
|
2
|
+
|
|
1
3
|
import { initText, initCircle, initPath, initRect, initArc } from "./config"
|
|
2
4
|
import { toNode, setAttribute, getAttribute, full, fill, stroke } from "./tool"
|
|
3
5
|
import rotate from "../../rotate"
|
|
4
|
-
import SVGConfigType from "../../../types/SVGConfig"
|
|
5
6
|
|
|
6
7
|
// 属性名向下兼容
|
|
7
8
|
let oldAttrName = {
|
package/src/common/svg/tool.ts
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type TreeConfigType from '../../../types/TreeConfig'
|
|
2
|
+
import type { TreeResultType } from '../../../types/Tree'
|
|
3
|
+
|
|
4
|
+
import toPlainTree from './toPlainTree'
|
|
5
|
+
import mergeOption from '../mergeOption'
|
|
6
|
+
|
|
7
|
+
class Tree {
|
|
8
|
+
readonly name: string = 'Tree'
|
|
9
|
+
|
|
10
|
+
private __config: TreeConfigType
|
|
11
|
+
|
|
12
|
+
constructor(config: TreeConfigType = {}) {
|
|
13
|
+
this.__config = mergeOption(config, {
|
|
14
|
+
root: (initTree: any) => initTree,
|
|
15
|
+
children: (parentTree: any) => parentTree.children,
|
|
16
|
+
id: (treedata: any) => treedata.name
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
use(initTree: any, noOpens = {}): TreeResultType {
|
|
21
|
+
return toPlainTree(initTree, this.__config, noOpens)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default Tree
|