/
callout.ts
74 lines (67 loc) 路 1.66 KB
/
callout.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
65
66
67
68
69
70
71
72
73
74
import { getFactor } from './util'
import {
util,
State,
Shape,
Perimeter,
Point,
Rectangle,
SvgCanvas2D,
} from '@antv/x6'
export class CalloutShape extends Shape.Actor {
base = 20
factor = 30
position1 = 0.5
position2 = 0.5
isRoundable() {
return true
}
getLabelMargins() {
return new Rectangle(
0,
0,
0,
util.getNumber(this.style, 'factor', this.factor) * this.scale,
)
}
redrawPath(c: SvgCanvas2D, x: number, y: number, w: number, h: number) {
const arcSize = this.getLineArcSize()
const s = getFactor(this.style, this.factor, h)
const dx1 = getFactor(this.style, this.position1, w, 1, 'position')
const dx2 = getFactor(this.style, this.position2, w, 1, 'position2')
const base = getFactor(this.style, this.base, w, 1, 'base')
this.drawPoints(
c,
[
new Point(0, 0),
new Point(w, 0),
new Point(w, h - s),
new Point(Math.min(w, dx1 + base), h - s),
new Point(dx2, h),
new Point(Math.max(0, dx1), h - s),
new Point(0, h - s),
],
this.rounded,
arcSize,
true,
[4],
)
}
}
export function calloutPerimeter(
bounds: Rectangle,
state: State,
next: Point,
orthogonal: boolean,
) {
const factor = getFactor(
state.style,
CalloutShape.prototype.factor,
bounds.height,
)
const rect = new Rectangle(0, 0, 0, factor * state.view.scale)
const directedBounds = util.getDirectedBounds(bounds, rect, state.style)
return Perimeter.rectangle(directedBounds, state, next, orthogonal)
}
Shape.register('callout', CalloutShape)
Perimeter.register('calloutPerimeter', calloutPerimeter)