-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathmodel.ts
64 lines (55 loc) · 1.49 KB
/
model.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import LogicFlow, { HtmlNodeModel, IHtmlNodeProperties } from '@logicflow/core'
import { cloneDeep, isNil } from 'lodash-es'
export interface VueCustomProperties extends IHtmlNodeProperties {
// 形状属性
width?: number
height?: number
radius?: number
// 文字位置属性
refX?: number
refY?: number
// 样式属性
style?: LogicFlow.CommonTheme
textStyle?: LogicFlow.TextNodeTheme
}
export class VueNodeModel<
P extends VueCustomProperties = VueCustomProperties,
> extends HtmlNodeModel<P> {
setAttributes() {
// DONE: 解决 width、height、radius 为 0 时的问题
const { width, height, radius } = this.properties
if (!isNil(width)) {
this.width = width
}
if (!isNil(height)) {
this.height = height
}
if (!isNil(radius)) {
this.radius = radius
}
}
getTextStyle(): LogicFlow.TextNodeTheme {
const { refX = 0, refY = 0, textStyle } = this.properties
const style = super.getTextStyle()
// 通过 transform 重新设置 text 的位置
return {
...style,
...(cloneDeep(textStyle) || {}),
transform: `matrix(1 0 0 1 ${refX} ${refY})`,
}
}
getNodeStyle(): LogicFlow.CommonTheme {
const style = super.getNodeStyle()
const {
style: customNodeStyle,
// radius = 0, // 第二种方式,设置圆角
} = this.properties
return {
...style,
...(cloneDeep(customNodeStyle) || {}),
// rx: radius,
// ry: radius,
}
}
}
export default VueNodeModel