-
-
Notifications
You must be signed in to change notification settings - Fork 311
/
rounded-rectangle.js
58 lines (56 loc) · 1.53 KB
/
rounded-rectangle.js
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
/**
* Created by OXOYO on 2019/9/3.
*
* 圆角矩形
*/
import Global from '@antv/g6/src/global'
import Util from '@antv/g6/src/util'
import base from './base'
export default {
name: 'rounded-rectangle',
extendName: 'single-shape',
options: {
...base,
shapeType: 'path',
getShapeStyle (cfg) {
const size = this.getSize(cfg)
const width = size[0]
const height = size[1]
const x = 0 - width / 2
const y = 0 - height / 2
const r = 5
const path = [
// 左顶点
[ 'M', -width / 2, 0 ],
// 左上顶点
[ 'L', -width / 2, -height / 2 + r ],
// 左上弧
[ 'Q', -width / 2, -height / 2, -width / 2 + r, -height / 2 ],
// 右上顶点
[ 'L', width / 2 - r, -height / 2 ],
// 右上弧
[ 'Q', width / 2, -height / 2, width / 2, -height / 2 + r ],
// 右下顶点
[ 'L', width / 2, height / 2 - r ],
// 右下弧
[ 'Q', width / 2, height / 2, width / 2 - r, height / 2 ],
// 左下顶点
[ 'L', -width / 2 + r, height / 2 ],
// 左下弧
[ 'Q', -width / 2, height / 2, -width / 2, height / 2 - r ],
[ 'Z' ]
]
const color = cfg.color || Global.defaultNode.color
const style = Util.mix({}, Global.defaultNode.style, {
// 节点的位置在上层确定,所以这里仅使用相对位置即可
x,
y,
width,
height,
path,
stroke: color
}, cfg.style)
return style
}
}
}