1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import * as go from '../release/go-module.js';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | export class BalloonLink extends go.Link {
|
24 | private _base: number = 10;
|
25 |
|
26 | |
27 |
|
28 |
|
29 | constructor() {
|
30 | super();
|
31 | this.layerName = 'Background';
|
32 | }
|
33 |
|
34 | |
35 |
|
36 |
|
37 | protected cloneProtected(copy: this): void {
|
38 | super.cloneProtected(copy);
|
39 | copy._base = this._base;
|
40 | }
|
41 |
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 | get base(): number { return this._base; }
|
48 | set base(value: number) { this._base = value; }
|
49 |
|
50 | |
51 |
|
52 |
|
53 |
|
54 | public makeGeometry(): go.Geometry {
|
55 | const fromnode = this.fromNode;
|
56 | const tonode = this.toNode;
|
57 | if (fromnode === null || tonode === null) return super.makeGeometry();
|
58 |
|
59 | const bb = fromnode.actualBounds;
|
60 | const nb = tonode.actualBounds;
|
61 |
|
62 | const p0 = bb.center;
|
63 | let pn = this.getPoint(this.pointsCount - 1);
|
64 | if (bb.intersectsRect(nb)) {
|
65 | pn = nb.center;
|
66 | }
|
67 | const pos = this.routeBounds;
|
68 |
|
69 |
|
70 | const ang = pn.directionPoint(p0);
|
71 | const L = new go.Point(this.base, 0).rotate(ang - 90).add(p0);
|
72 | const R = new go.Point(this.base, 0).rotate(ang + 90).add(p0);
|
73 | this.getLinkPointFromPoint(fromnode, fromnode, L, pn, true, L);
|
74 | this.getLinkPointFromPoint(fromnode, fromnode, R, pn, true, R);
|
75 |
|
76 |
|
77 | const fig = new go.PathFigure(pn.x - pos.x, pn.y - pos.y, true);
|
78 | fig.add(new go.PathSegment(go.PathSegment.Line, R.x - pos.x, R.y - pos.y));
|
79 | let side = 0;
|
80 | if (L.y >= bb.bottom || R.y >= bb.bottom) side = 2;
|
81 | else if (L.x <= bb.x && R.x <= bb.x) side = 1;
|
82 | else if (L.x >= bb.right && R.x >= bb.right) side = 3;
|
83 |
|
84 | this.pathToCorner(side, bb, fig, pos, L, R);
|
85 | this.pathToCorner(side + 1, bb, fig, pos, L, R);
|
86 | this.pathToCorner(side + 2, bb, fig, pos, L, R);
|
87 | this.pathToCorner(side + 3, bb, fig, pos, L, R);
|
88 | fig.add(new go.PathSegment(go.PathSegment.Line, L.x - pos.x, L.y - pos.y).close());
|
89 |
|
90 |
|
91 | return new go.Geometry().add(fig);
|
92 | }
|
93 |
|
94 | |
95 |
|
96 |
|
97 | public pathToCorner(side: number, bb: go.Rect, fig: go.PathFigure, pos: go.Rect, L: go.Point, R: go.Point): void {
|
98 | switch (side % 4) {
|
99 | case 0: if (!(L.y <= bb.y && R.x <= bb.x)) fig.add(new go.PathSegment(go.PathSegment.Line, bb.x - pos.x, bb.y - pos.y)); break;
|
100 | case 1: if (!(L.x <= bb.x && R.y >= bb.bottom)) fig.add(new go.PathSegment(go.PathSegment.Line, bb.x - pos.x, bb.bottom - pos.y)); break;
|
101 | case 2: if (!(L.y >= bb.bottom && R.x >= bb.right)) fig.add(new go.PathSegment(go.PathSegment.Line, bb.right - pos.x, bb.bottom - pos.y)); break;
|
102 | case 3: if (!(L.x >= bb.right && R.y <= bb.y)) fig.add(new go.PathSegment(go.PathSegment.Line, bb.right - pos.x, bb.y - pos.y)); break;
|
103 | }
|
104 | }
|
105 | }
|