@antv/g6 5.0.0-alpha.8 → 5.0.0-alpha.9
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/dist/g6.min.js +6 -19
- package/esm/index.d.ts +26 -6
- package/esm/item/combo.d.ts +72 -2
- package/esm/item/combo.js +122 -2
- package/esm/item/combo.js.map +1 -1
- package/esm/item/edge.d.ts +3 -3
- package/esm/item/edge.js +4 -5
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.d.ts +4 -4
- package/esm/item/item.js +38 -9
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.d.ts +20 -16
- package/esm/item/node.js +14 -8
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/data.d.ts +12 -4
- package/esm/runtime/controller/data.js +354 -62
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/interaction.js +16 -4
- package/esm/runtime/controller/interaction.js.map +1 -1
- package/esm/runtime/controller/item.d.ts +11 -2
- package/esm/runtime/controller/item.js +344 -52
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/controller/layout.js +19 -5
- package/esm/runtime/controller/layout.js.map +1 -1
- package/esm/runtime/graph.d.ts +54 -17
- package/esm/runtime/graph.js +165 -34
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/click-select.d.ts +3 -0
- package/esm/stdlib/behavior/click-select.js +13 -1
- package/esm/stdlib/behavior/click-select.js.map +1 -1
- package/esm/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
- package/esm/stdlib/behavior/collapse-expand-combo.js +35 -0
- package/esm/stdlib/behavior/collapse-expand-combo.js.map +1 -0
- package/esm/stdlib/behavior/drag-combo.d.ts +99 -0
- package/esm/stdlib/behavior/drag-combo.js +341 -0
- package/esm/stdlib/behavior/drag-combo.js.map +1 -0
- package/esm/stdlib/behavior/drag-node.d.ts +14 -10
- package/esm/stdlib/behavior/drag-node.js +134 -37
- package/esm/stdlib/behavior/drag-node.js.map +1 -1
- package/esm/stdlib/behavior/hover-activate.d.ts +3 -1
- package/esm/stdlib/behavior/hover-activate.js +3 -1
- package/esm/stdlib/behavior/hover-activate.js.map +1 -1
- package/esm/stdlib/behavior/orbit-canvas-3d.js +1 -1
- package/esm/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
- package/esm/stdlib/behavior/track-canvas-3d.js +1 -1
- package/esm/stdlib/behavior/track-canvas-3d.js.map +1 -1
- package/esm/stdlib/index.d.ts +25 -3
- package/esm/stdlib/index.js +25 -3
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/combo/circle.d.ts +29 -0
- package/esm/stdlib/item/combo/circle.js +56 -0
- package/esm/stdlib/item/combo/circle.js.map +1 -0
- package/esm/stdlib/item/edge/base.d.ts +2 -2
- package/esm/stdlib/item/edge/base.js +3 -0
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/edge/cubic-horizon.d.ts +37 -0
- package/esm/stdlib/item/edge/cubic-horizon.js +71 -0
- package/esm/stdlib/item/edge/cubic-horizon.js.map +1 -0
- package/esm/stdlib/item/edge/cubic-vertical.d.ts +37 -0
- package/esm/stdlib/item/edge/cubic-vertical.js +71 -0
- package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -0
- package/esm/stdlib/item/edge/cubic.d.ts +60 -0
- package/esm/stdlib/item/edge/cubic.js +99 -0
- package/esm/stdlib/item/edge/cubic.js.map +1 -0
- package/esm/stdlib/item/edge/index.d.ts +1 -0
- package/esm/stdlib/item/edge/index.js +1 -0
- package/esm/stdlib/item/edge/index.js.map +1 -1
- package/esm/stdlib/item/edge/line.d.ts +1 -1
- package/esm/stdlib/item/edge/quadratic.d.ts +41 -0
- package/esm/stdlib/item/edge/quadratic.js +66 -0
- package/esm/stdlib/item/edge/quadratic.js.map +1 -0
- package/esm/stdlib/item/node/base.d.ts +38 -37
- package/esm/stdlib/item/node/base.js +4 -4
- package/esm/stdlib/item/node/base.js.map +1 -1
- package/esm/stdlib/item/node/index.d.ts +1 -0
- package/esm/stdlib/item/node/index.js +1 -0
- package/esm/stdlib/item/node/index.js.map +1 -1
- package/esm/stdlib/item/node/rect.d.ts +31 -0
- package/esm/stdlib/item/node/rect.js +59 -0
- package/esm/stdlib/item/node/rect.js.map +1 -0
- package/esm/stdlib/plugin/fisheye/index.d.ts +102 -0
- package/esm/stdlib/plugin/fisheye/index.js +487 -0
- package/esm/stdlib/plugin/fisheye/index.js.map +1 -0
- package/esm/stdlib/plugin/menu/index.d.ts +42 -0
- package/esm/stdlib/plugin/menu/index.js +236 -0
- package/esm/stdlib/plugin/menu/index.js.map +1 -0
- package/esm/stdlib/plugin/tooltip/index.d.ts +75 -0
- package/esm/stdlib/plugin/tooltip/index.js +377 -0
- package/esm/stdlib/plugin/tooltip/index.js.map +1 -0
- package/esm/stdlib/theme/dark.js +4 -0
- package/esm/stdlib/theme/dark.js.map +1 -1
- package/esm/stdlib/theme/light.js +54 -9
- package/esm/stdlib/theme/light.js.map +1 -1
- package/esm/types/combo.d.ts +52 -3
- package/esm/types/data.d.ts +4 -4
- package/esm/types/edge.d.ts +2 -3
- package/esm/types/event.d.ts +9 -1
- package/esm/types/event.js +8 -8
- package/esm/types/event.js.map +1 -1
- package/esm/types/graph.d.ts +49 -13
- package/esm/types/hook.d.ts +8 -1
- package/esm/types/item.d.ts +4 -4
- package/esm/types/node.d.ts +4 -5
- package/esm/types/theme.d.ts +1 -1
- package/esm/util/animate.js.map +1 -1
- package/esm/util/canvas.js +8 -0
- package/esm/util/canvas.js.map +1 -1
- package/esm/util/data.d.ts +65 -0
- package/esm/util/data.js +150 -0
- package/esm/util/data.js.map +1 -0
- package/esm/util/event.d.ts +8 -0
- package/esm/util/event.js +16 -0
- package/esm/util/event.js.map +1 -1
- package/esm/util/item.d.ts +2 -1
- package/esm/util/item.js +36 -13
- package/esm/util/item.js.map +1 -1
- package/esm/util/shape.d.ts +39 -4
- package/esm/util/shape.js +101 -1
- package/esm/util/shape.js.map +1 -1
- package/esm/util/zoom.d.ts +2 -2
- package/lib/index.d.ts +26 -6
- package/lib/item/combo.d.ts +72 -2
- package/lib/item/combo.js +122 -2
- package/lib/item/combo.js.map +1 -1
- package/lib/item/edge.d.ts +3 -3
- package/lib/item/edge.js +4 -5
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.d.ts +4 -4
- package/lib/item/item.js +37 -8
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.d.ts +20 -16
- package/lib/item/node.js +14 -8
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/data.d.ts +12 -4
- package/lib/runtime/controller/data.js +353 -61
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/interaction.js +15 -3
- package/lib/runtime/controller/interaction.js.map +1 -1
- package/lib/runtime/controller/item.d.ts +11 -2
- package/lib/runtime/controller/item.js +342 -50
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/controller/layout.js +19 -5
- package/lib/runtime/controller/layout.js.map +1 -1
- package/lib/runtime/graph.d.ts +54 -17
- package/lib/runtime/graph.js +165 -34
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/click-select.d.ts +3 -0
- package/lib/stdlib/behavior/click-select.js +13 -1
- package/lib/stdlib/behavior/click-select.js.map +1 -1
- package/lib/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
- package/lib/stdlib/behavior/collapse-expand-combo.js +38 -0
- package/lib/stdlib/behavior/collapse-expand-combo.js.map +1 -0
- package/lib/stdlib/behavior/drag-combo.d.ts +99 -0
- package/lib/stdlib/behavior/drag-combo.js +344 -0
- package/lib/stdlib/behavior/drag-combo.js.map +1 -0
- package/lib/stdlib/behavior/drag-node.d.ts +14 -10
- package/lib/stdlib/behavior/drag-node.js +134 -37
- package/lib/stdlib/behavior/drag-node.js.map +1 -1
- package/lib/stdlib/behavior/hover-activate.d.ts +3 -1
- package/lib/stdlib/behavior/hover-activate.js +3 -2
- package/lib/stdlib/behavior/hover-activate.js.map +1 -1
- package/lib/stdlib/behavior/orbit-canvas-3d.js +1 -1
- package/lib/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
- package/lib/stdlib/behavior/track-canvas-3d.js +1 -1
- package/lib/stdlib/behavior/track-canvas-3d.js.map +1 -1
- package/lib/stdlib/index.d.ts +25 -3
- package/lib/stdlib/index.js +25 -3
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/combo/circle.d.ts +29 -0
- package/lib/stdlib/item/combo/circle.js +60 -0
- package/lib/stdlib/item/combo/circle.js.map +1 -0
- package/lib/stdlib/item/edge/base.d.ts +2 -2
- package/lib/stdlib/item/edge/base.js +3 -0
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/edge/cubic-horizon.d.ts +37 -0
- package/lib/stdlib/item/edge/cubic-horizon.js +75 -0
- package/lib/stdlib/item/edge/cubic-horizon.js.map +1 -0
- package/lib/stdlib/item/edge/cubic-vertical.d.ts +37 -0
- package/lib/stdlib/item/edge/cubic-vertical.js +75 -0
- package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -0
- package/lib/stdlib/item/edge/cubic.d.ts +60 -0
- package/lib/stdlib/item/edge/cubic.js +103 -0
- package/lib/stdlib/item/edge/cubic.js.map +1 -0
- package/lib/stdlib/item/edge/index.d.ts +1 -0
- package/lib/stdlib/item/edge/index.js +1 -0
- package/lib/stdlib/item/edge/index.js.map +1 -1
- package/lib/stdlib/item/edge/line.d.ts +1 -1
- package/lib/stdlib/item/edge/quadratic.d.ts +41 -0
- package/lib/stdlib/item/edge/quadratic.js +70 -0
- package/lib/stdlib/item/edge/quadratic.js.map +1 -0
- package/lib/stdlib/item/node/base.d.ts +38 -37
- package/lib/stdlib/item/node/base.js +4 -4
- package/lib/stdlib/item/node/base.js.map +1 -1
- package/lib/stdlib/item/node/index.d.ts +1 -0
- package/lib/stdlib/item/node/index.js +1 -0
- package/lib/stdlib/item/node/index.js.map +1 -1
- package/lib/stdlib/item/node/rect.d.ts +31 -0
- package/lib/stdlib/item/node/rect.js +63 -0
- package/lib/stdlib/item/node/rect.js.map +1 -0
- package/lib/stdlib/plugin/fisheye/index.d.ts +102 -0
- package/lib/stdlib/plugin/fisheye/index.js +490 -0
- package/lib/stdlib/plugin/fisheye/index.js.map +1 -0
- package/lib/stdlib/plugin/menu/index.d.ts +42 -0
- package/lib/stdlib/plugin/menu/index.js +242 -0
- package/lib/stdlib/plugin/menu/index.js.map +1 -0
- package/lib/stdlib/plugin/tooltip/index.d.ts +75 -0
- package/lib/stdlib/plugin/tooltip/index.js +383 -0
- package/lib/stdlib/plugin/tooltip/index.js.map +1 -0
- package/lib/stdlib/theme/dark.js +4 -0
- package/lib/stdlib/theme/dark.js.map +1 -1
- package/lib/stdlib/theme/light.js +54 -9
- package/lib/stdlib/theme/light.js.map +1 -1
- package/lib/types/combo.d.ts +52 -3
- package/lib/types/data.d.ts +4 -4
- package/lib/types/edge.d.ts +2 -3
- package/lib/types/event.d.ts +9 -1
- package/lib/types/event.js +10 -10
- package/lib/types/event.js.map +1 -1
- package/lib/types/graph.d.ts +49 -13
- package/lib/types/hook.d.ts +8 -1
- package/lib/types/item.d.ts +4 -4
- package/lib/types/item.js +1 -1
- package/lib/types/item.js.map +1 -1
- package/lib/types/node.d.ts +4 -5
- package/lib/types/theme.d.ts +1 -1
- package/lib/util/animate.js.map +1 -1
- package/lib/util/canvas.js +8 -0
- package/lib/util/canvas.js.map +1 -1
- package/lib/util/data.d.ts +65 -0
- package/lib/util/data.js +161 -0
- package/lib/util/data.js.map +1 -0
- package/lib/util/event.d.ts +8 -0
- package/lib/util/event.js +18 -1
- package/lib/util/event.js.map +1 -1
- package/lib/util/item.d.ts +2 -1
- package/lib/util/item.js +36 -13
- package/lib/util/item.js.map +1 -1
- package/lib/util/shape.d.ts +39 -4
- package/lib/util/shape.js +105 -2
- package/lib/util/shape.js.map +1 -1
- package/lib/util/zoom.d.ts +2 -2
- package/package.json +13 -13
- package/src/item/combo.ts +220 -2
- package/src/item/edge.ts +7 -8
- package/src/item/item.ts +58 -15
- package/src/item/node.ts +47 -24
- package/src/runtime/controller/data.ts +390 -68
- package/src/runtime/controller/interaction.ts +23 -3
- package/src/runtime/controller/item.ts +444 -64
- package/src/runtime/controller/layout.ts +24 -5
- package/src/runtime/graph.ts +225 -38
- package/src/stdlib/behavior/click-select.ts +15 -2
- package/src/stdlib/behavior/collapse-expand-combo.ts +59 -0
- package/src/stdlib/behavior/drag-combo.ts +533 -0
- package/src/stdlib/behavior/drag-node.ts +195 -62
- package/src/stdlib/behavior/hover-activate.ts +4 -5
- package/src/stdlib/behavior/orbit-canvas-3d.ts +1 -1
- package/src/stdlib/behavior/track-canvas-3d.ts +1 -1
- package/src/stdlib/index.ts +25 -3
- package/src/stdlib/item/combo/circle.ts +113 -0
- package/src/stdlib/item/edge/base.ts +5 -2
- package/src/stdlib/item/edge/cubic-horizon.ts +114 -0
- package/src/stdlib/item/edge/cubic-vertical.ts +116 -0
- package/src/stdlib/item/edge/cubic.ts +198 -0
- package/src/stdlib/item/edge/index.ts +1 -0
- package/src/stdlib/item/edge/quadratic.ts +136 -0
- package/src/stdlib/item/node/base.ts +79 -41
- package/src/stdlib/item/node/index.ts +1 -0
- package/src/stdlib/item/node/rect.ts +124 -0
- package/src/stdlib/plugin/fisheye/index.ts +578 -0
- package/src/stdlib/plugin/menu/index.ts +260 -0
- package/src/stdlib/plugin/tooltip/index.ts +424 -0
- package/src/stdlib/theme/dark.ts +4 -0
- package/src/stdlib/theme/light.ts +77 -9
- package/src/types/combo.ts +61 -3
- package/src/types/data.ts +6 -4
- package/src/types/edge.ts +2 -2
- package/src/types/event.ts +8 -8
- package/src/types/graph.ts +73 -16
- package/src/types/hook.ts +8 -1
- package/src/types/item.ts +10 -9
- package/src/types/node.ts +4 -4
- package/src/types/theme.ts +1 -1
- package/src/util/animate.ts +2 -3
- package/src/util/canvas.ts +10 -0
- package/src/util/data.ts +178 -0
- package/src/util/event.ts +29 -0
- package/src/util/item.ts +75 -12
- package/src/util/shape.ts +142 -5
- package/src/util/zoom.ts +2 -2
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { IPoint } from '@antv/g6';
|
|
2
|
+
import { vec2 } from '@antv/matrix-util';
|
|
3
|
+
import { Point } from '../../../types/common';
|
|
4
|
+
import { CubicEdge } from './cubic';
|
|
5
|
+
|
|
6
|
+
export class CubicHorizonEdge extends CubicEdge {
|
|
7
|
+
public type = 'cubic-horizon-edge';
|
|
8
|
+
|
|
9
|
+
public defaultStyles = {
|
|
10
|
+
keyShape: {
|
|
11
|
+
x1: 0,
|
|
12
|
+
y1: 0,
|
|
13
|
+
z1: 0,
|
|
14
|
+
x2: 0,
|
|
15
|
+
y2: 0,
|
|
16
|
+
z2: 0,
|
|
17
|
+
isBillboard: true,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(props);
|
|
22
|
+
// suggest to merge default styles like this to avoid style value missing
|
|
23
|
+
// this.defaultStyles = mergeStyles([this.baseDefaultStyles, this.defaultStyles]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* calculate the control points by curvePosition|controlPoints|curveOffset
|
|
28
|
+
* @param startPoint: source point position of edge
|
|
29
|
+
* @param endPoint target point position of edge
|
|
30
|
+
* @param percent the proportion of control points' in the segment, Range 0 to 1
|
|
31
|
+
* @param controlPoints the control point position
|
|
32
|
+
* @param offset the curveOffset
|
|
33
|
+
* @returns control points
|
|
34
|
+
*/
|
|
35
|
+
protected getControlPoints: (
|
|
36
|
+
startPoint: Point,
|
|
37
|
+
endPoint: Point,
|
|
38
|
+
percent: number,
|
|
39
|
+
controlPoints: number[],
|
|
40
|
+
offset: number,
|
|
41
|
+
) => [Point, Point] = (
|
|
42
|
+
startPoint: Point,
|
|
43
|
+
endPoint: Point,
|
|
44
|
+
percent = 0.5,
|
|
45
|
+
controlPoints,
|
|
46
|
+
offset = 20,
|
|
47
|
+
) => {
|
|
48
|
+
if ((startPoint.x - endPoint.x) * (startPoint.y - endPoint.y) < 0) {
|
|
49
|
+
offset = -offset;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const controlPoint1: IPoint = this.getControlPoint(
|
|
53
|
+
startPoint,
|
|
54
|
+
endPoint,
|
|
55
|
+
percent,
|
|
56
|
+
offset,
|
|
57
|
+
);
|
|
58
|
+
const controlPoint2: IPoint = this.getControlPoint(
|
|
59
|
+
startPoint,
|
|
60
|
+
endPoint,
|
|
61
|
+
percent,
|
|
62
|
+
-offset,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return [controlPoint1, controlPoint2];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* control point calculated according to startPoint, endPoint, percent, and offset
|
|
70
|
+
* @param {IPoint} startPoint source point position of edge (x, y)
|
|
71
|
+
* @param {IPoint} endPoint target point position of edge (x, y)
|
|
72
|
+
* @param {Number} percent the proportion of control points' in the segment, Range 0 to 1
|
|
73
|
+
* @param {Number} offset the curveOffset
|
|
74
|
+
* @return {IPoint} control point (x,y)
|
|
75
|
+
*/
|
|
76
|
+
protected getControlPoint: (
|
|
77
|
+
startPoint: IPoint,
|
|
78
|
+
endPoint: IPoint,
|
|
79
|
+
percent: number,
|
|
80
|
+
offset: number,
|
|
81
|
+
) => IPoint = (
|
|
82
|
+
startPoint: IPoint,
|
|
83
|
+
endPoint: IPoint,
|
|
84
|
+
percent = 0,
|
|
85
|
+
offset = 0,
|
|
86
|
+
) => {
|
|
87
|
+
const point: IPoint = {
|
|
88
|
+
x: (1 - percent) * startPoint.x + percent * endPoint.x,
|
|
89
|
+
y: 0,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
let tangent: vec2 = [0, 0];
|
|
93
|
+
vec2.normalize(tangent, [
|
|
94
|
+
endPoint.x - startPoint.x,
|
|
95
|
+
endPoint.y - startPoint.y,
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
if (!tangent || (!tangent[0] && !tangent[1])) {
|
|
99
|
+
tangent = [0, 0];
|
|
100
|
+
}
|
|
101
|
+
const perpendicular = [-tangent[1] * offset, tangent[0] * offset]; // Vertical vector
|
|
102
|
+
|
|
103
|
+
point.x += perpendicular[0];
|
|
104
|
+
point.y += perpendicular[1];
|
|
105
|
+
|
|
106
|
+
if (Math.abs(point.x - startPoint.x) < Math.abs(point.x - endPoint.x)) {
|
|
107
|
+
point.y += startPoint.y;
|
|
108
|
+
} else {
|
|
109
|
+
point.y += endPoint.y;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return point;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { IPoint } from '@antv/g6';
|
|
2
|
+
import { vec2 } from '@antv/matrix-util';
|
|
3
|
+
import { Point } from '../../../types/common';
|
|
4
|
+
import { CubicEdge } from './cubic';
|
|
5
|
+
|
|
6
|
+
export class CubicVerticalEdge extends CubicEdge {
|
|
7
|
+
public type = 'cubic-vertical-edge';
|
|
8
|
+
|
|
9
|
+
public defaultStyles = {
|
|
10
|
+
keyShape: {
|
|
11
|
+
x1: 0,
|
|
12
|
+
y1: 0,
|
|
13
|
+
z1: 0,
|
|
14
|
+
x2: 0,
|
|
15
|
+
y2: 0,
|
|
16
|
+
z2: 0,
|
|
17
|
+
isBillboard: true,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(props);
|
|
22
|
+
// suggest to merge default styles like this to avoid style value missing
|
|
23
|
+
// this.defaultStyles = mergeStyles([this.baseDefaultStyles, this.defaultStyles]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* control point calculated according to startPoint, endPoint, percent, and offset
|
|
28
|
+
* @param {IPoint} startPoint source point position of edge (x, y)
|
|
29
|
+
* @param {IPoint} endPoint target point position of edge (x, y)
|
|
30
|
+
* @param {Number} percent the proportion of control points' in the segment, Range 0 to 1
|
|
31
|
+
* @param {Number} offset the curveOffset
|
|
32
|
+
* @param controlPoints the control point position
|
|
33
|
+
* @returns control points
|
|
34
|
+
*/
|
|
35
|
+
protected getControlPoints: (
|
|
36
|
+
startPoint: Point,
|
|
37
|
+
endPoint: Point,
|
|
38
|
+
percent: number,
|
|
39
|
+
controlPoints: number[],
|
|
40
|
+
offset: number,
|
|
41
|
+
) => [Point, Point] = (
|
|
42
|
+
startPoint: Point,
|
|
43
|
+
endPoint: Point,
|
|
44
|
+
percent = 0.5,
|
|
45
|
+
controlPoints,
|
|
46
|
+
offset = 20,
|
|
47
|
+
) => {
|
|
48
|
+
if ((startPoint.x - endPoint.x) * (startPoint.y - endPoint.y) > 0) {
|
|
49
|
+
offset = -offset;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const controlPoint1: IPoint = this.getControlPoint(
|
|
53
|
+
startPoint,
|
|
54
|
+
endPoint,
|
|
55
|
+
percent,
|
|
56
|
+
offset,
|
|
57
|
+
);
|
|
58
|
+
const controlPoint2: IPoint = this.getControlPoint(
|
|
59
|
+
startPoint,
|
|
60
|
+
endPoint,
|
|
61
|
+
percent,
|
|
62
|
+
-offset,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return [controlPoint1, controlPoint2];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* control point calculated according to startPoint, endPoint, percent, and offset
|
|
70
|
+
* @param {IPoint} startPoint source point position of edge (x, y)
|
|
71
|
+
* @param {IPoint} endPoint target point position of edge (x, y)
|
|
72
|
+
* @param {Number} percent the proportion of control points' in the segment, Range 0 to 1
|
|
73
|
+
* @param {Number} offset the curveOffset
|
|
74
|
+
* @return {IPoint} control point (x,y)
|
|
75
|
+
*/
|
|
76
|
+
protected getControlPoint: (
|
|
77
|
+
startPoint: IPoint,
|
|
78
|
+
endPoint: IPoint,
|
|
79
|
+
percent: number,
|
|
80
|
+
offset: number,
|
|
81
|
+
) => IPoint = (
|
|
82
|
+
startPoint: IPoint,
|
|
83
|
+
endPoint: IPoint,
|
|
84
|
+
percent = 0,
|
|
85
|
+
offset = 0,
|
|
86
|
+
) => {
|
|
87
|
+
const point: IPoint = {
|
|
88
|
+
x: 0,
|
|
89
|
+
y: (1 - percent) * startPoint.y + percent * endPoint.y,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
let tangent: vec2 = [0, 0];
|
|
93
|
+
|
|
94
|
+
vec2.normalize(tangent, [
|
|
95
|
+
endPoint.x - startPoint.x,
|
|
96
|
+
endPoint.y - startPoint.y,
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
if (!tangent || (!tangent[0] && !tangent[1])) {
|
|
100
|
+
tangent = [0, 0];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const perpendicular = [-tangent[1] * offset, tangent[0] * offset]; // Vertical vector
|
|
104
|
+
|
|
105
|
+
point.x += perpendicular[0];
|
|
106
|
+
point.y += perpendicular[1];
|
|
107
|
+
|
|
108
|
+
if (Math.abs(point.y - startPoint.y) < Math.abs(point.y - endPoint.y)) {
|
|
109
|
+
point.x += startPoint.x;
|
|
110
|
+
} else {
|
|
111
|
+
point.x += endPoint.x;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return point;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { IPoint } from '@antv/g6';
|
|
3
|
+
import { vec2 } from '@antv/matrix-util';
|
|
4
|
+
import { State } from '../../../types/item';
|
|
5
|
+
import { EdgeModelData, EdgeShapeMap } from '../../../types/edge';
|
|
6
|
+
import { Point } from '../../../types/common';
|
|
7
|
+
import { EdgeDisplayModel } from '../../../types';
|
|
8
|
+
// eslint-disable-next-line import/namespace
|
|
9
|
+
import { BaseEdge } from './base';
|
|
10
|
+
|
|
11
|
+
export class CubicEdge extends BaseEdge {
|
|
12
|
+
public type = 'cubic-edge';
|
|
13
|
+
|
|
14
|
+
public defaultStyles = {
|
|
15
|
+
keyShape: {
|
|
16
|
+
x1: 0,
|
|
17
|
+
y1: 0,
|
|
18
|
+
z1: 0,
|
|
19
|
+
x2: 0,
|
|
20
|
+
y2: 0,
|
|
21
|
+
z2: 0,
|
|
22
|
+
isBillboard: true,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
constructor(props) {
|
|
26
|
+
super(props);
|
|
27
|
+
// suggest to merge default styles like this to avoid style value missing
|
|
28
|
+
// this.defaultStyles = mergeStyles([this.baseDefaultStyles, this.defaultStyles]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
draw(
|
|
32
|
+
model: EdgeDisplayModel,
|
|
33
|
+
sourcePoint: Point,
|
|
34
|
+
targetPoint: Point,
|
|
35
|
+
shapeMap: EdgeShapeMap,
|
|
36
|
+
diffData?: { previous: EdgeModelData; current: EdgeModelData },
|
|
37
|
+
diffState?: { previous: State[]; current: State[] },
|
|
38
|
+
): {
|
|
39
|
+
[otherShapeId: string]: DisplayObject<any, any>;
|
|
40
|
+
keyShape: DisplayObject<any, any>;
|
|
41
|
+
labelShape?: DisplayObject<any, any>;
|
|
42
|
+
iconShape?: DisplayObject<any, any>;
|
|
43
|
+
} {
|
|
44
|
+
const { data = {} } = model;
|
|
45
|
+
|
|
46
|
+
const shapes: EdgeShapeMap = { keyShape: undefined };
|
|
47
|
+
|
|
48
|
+
shapes.keyShape = this.drawKeyShape(
|
|
49
|
+
model,
|
|
50
|
+
sourcePoint,
|
|
51
|
+
targetPoint,
|
|
52
|
+
shapeMap,
|
|
53
|
+
diffData,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
if (data.haloShape) {
|
|
57
|
+
shapes.haloShape = this.drawHaloShape(model, shapeMap, diffData);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (data.labelShape) {
|
|
61
|
+
shapes.labelShape = this.drawLabelShape(model, shapeMap, diffData);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// labelBackgroundShape
|
|
65
|
+
if (data.labelBackgroundShape) {
|
|
66
|
+
shapes.labelBackgroundShape = this.drawLabelBackgroundShape(
|
|
67
|
+
model,
|
|
68
|
+
shapeMap,
|
|
69
|
+
diffData,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (data.iconShape) {
|
|
74
|
+
shapes.iconShape = this.drawIconShape(model, shapeMap, diffData);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// TODO: other shapes
|
|
78
|
+
return shapes;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public drawKeyShape(
|
|
82
|
+
model: EdgeDisplayModel,
|
|
83
|
+
sourcePoint: Point,
|
|
84
|
+
targetPoint: Point,
|
|
85
|
+
shapeMap: EdgeShapeMap,
|
|
86
|
+
diffData?: { previous: EdgeModelData; current: EdgeModelData },
|
|
87
|
+
diffState?: { previous: State[]; current: State[] },
|
|
88
|
+
) {
|
|
89
|
+
const { keyShape: keyShapeStyle } = this.mergedStyles as any;
|
|
90
|
+
|
|
91
|
+
const controlPoints = this.getControlPoints(
|
|
92
|
+
sourcePoint,
|
|
93
|
+
targetPoint,
|
|
94
|
+
keyShapeStyle.curvePosition,
|
|
95
|
+
keyShapeStyle.controlPoints,
|
|
96
|
+
keyShapeStyle.curveOffset,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return this.upsertShape(
|
|
100
|
+
'path',
|
|
101
|
+
'keyShape',
|
|
102
|
+
{
|
|
103
|
+
...keyShapeStyle,
|
|
104
|
+
path: [
|
|
105
|
+
['M', sourcePoint.x, sourcePoint.y],
|
|
106
|
+
[
|
|
107
|
+
'C',
|
|
108
|
+
controlPoints[0].x,
|
|
109
|
+
controlPoints[0].y,
|
|
110
|
+
controlPoints[1].x,
|
|
111
|
+
controlPoints[1].y,
|
|
112
|
+
targetPoint.x,
|
|
113
|
+
targetPoint.y,
|
|
114
|
+
],
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
shapeMap,
|
|
118
|
+
model,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* calculate the control points by curvePosition|controlPoints|curveOffset
|
|
124
|
+
* @param startPoint: source point position of edge
|
|
125
|
+
* @param endPoint target point position of edge
|
|
126
|
+
* @param percent the proportion of control points' in the segment, Range 0 to 1
|
|
127
|
+
* @param controlPoints the control point position
|
|
128
|
+
* @param offset the curveOffset
|
|
129
|
+
* @returns control points
|
|
130
|
+
*/
|
|
131
|
+
protected getControlPoints: (
|
|
132
|
+
startPoint: Point,
|
|
133
|
+
endPoint: Point,
|
|
134
|
+
percent: number,
|
|
135
|
+
controlPoints: number[],
|
|
136
|
+
offset: number,
|
|
137
|
+
) => [Point, Point] = (
|
|
138
|
+
startPoint: Point,
|
|
139
|
+
endPoint: Point,
|
|
140
|
+
percent = 0.5,
|
|
141
|
+
controlPoints,
|
|
142
|
+
offset = 20,
|
|
143
|
+
) => {
|
|
144
|
+
const controlPoint1: IPoint = this.getControlPoint(
|
|
145
|
+
startPoint,
|
|
146
|
+
endPoint,
|
|
147
|
+
percent,
|
|
148
|
+
offset,
|
|
149
|
+
);
|
|
150
|
+
const controlPoint2: IPoint = this.getControlPoint(
|
|
151
|
+
startPoint,
|
|
152
|
+
endPoint,
|
|
153
|
+
percent,
|
|
154
|
+
-offset,
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
return [controlPoint1, controlPoint2];
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* control point calculated according to startPoint, endPoint, percent, and offset
|
|
162
|
+
* @param {IPoint} startPoint source point position of edge (x, y)
|
|
163
|
+
* @param {IPoint} endPoint target point position of edge (x, y)
|
|
164
|
+
* @param {Number} percent the proportion of control points' in the segment, Range 0 to 1
|
|
165
|
+
* @param {Number} offset the curveOffset
|
|
166
|
+
* @return {IPoint} control point (x,y)
|
|
167
|
+
*/
|
|
168
|
+
protected getControlPoint: (
|
|
169
|
+
startPoint: IPoint,
|
|
170
|
+
endPoint: IPoint,
|
|
171
|
+
percent: number,
|
|
172
|
+
offset: number,
|
|
173
|
+
) => IPoint = (
|
|
174
|
+
startPoint: IPoint,
|
|
175
|
+
endPoint: IPoint,
|
|
176
|
+
percent = 0,
|
|
177
|
+
offset = 0,
|
|
178
|
+
) => {
|
|
179
|
+
const point: IPoint = {
|
|
180
|
+
x: (1 - percent) * startPoint.x + percent * endPoint.x,
|
|
181
|
+
y: (1 - percent) * startPoint.y + percent * endPoint.y,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
let tangent: vec2 = [0, 0];
|
|
185
|
+
vec2.normalize(tangent, [
|
|
186
|
+
endPoint.x - startPoint.x,
|
|
187
|
+
endPoint.y - startPoint.y,
|
|
188
|
+
]);
|
|
189
|
+
|
|
190
|
+
if (!tangent || (!tangent[0] && !tangent[1])) {
|
|
191
|
+
tangent = [0, 0];
|
|
192
|
+
}
|
|
193
|
+
const perpendicular = [-tangent[1] * offset, tangent[0] * offset]; // Vertical vector
|
|
194
|
+
point.x += perpendicular[0];
|
|
195
|
+
point.y += perpendicular[1];
|
|
196
|
+
return point;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Point } from '../../../types/common';
|
|
2
|
+
import {
|
|
3
|
+
EdgeDisplayModel,
|
|
4
|
+
EdgeModelData,
|
|
5
|
+
EdgeShapeMap,
|
|
6
|
+
} from '../../../types/edge';
|
|
7
|
+
import { State } from '../../../types/item';
|
|
8
|
+
import { BaseEdge } from './base';
|
|
9
|
+
|
|
10
|
+
export class Quadratic extends BaseEdge {
|
|
11
|
+
public type = 'line-edge';
|
|
12
|
+
public defaultStyles = {
|
|
13
|
+
keyShape: {
|
|
14
|
+
controlPoints: [0, 0], //precise x-axis, y-axis coordinates of control points
|
|
15
|
+
curvePosition: 0, //control point coordinates described by percentage,range 0 to 1
|
|
16
|
+
curveOffset: [0, 0], //a point coordinate that quadratic curve to
|
|
17
|
+
stroke: '#000000',
|
|
18
|
+
isBillboard: true,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
constructor(props) {
|
|
22
|
+
super(props);
|
|
23
|
+
// suggest to merge default styles like this to avoid style value missing
|
|
24
|
+
// this.defaultStyles = mergeStyles([this.baseDefaultStyles, this.defaultStyles]);
|
|
25
|
+
}
|
|
26
|
+
public draw(
|
|
27
|
+
model: EdgeDisplayModel,
|
|
28
|
+
sourcePoint: Point,
|
|
29
|
+
targetPoint: Point,
|
|
30
|
+
shapeMap: EdgeShapeMap,
|
|
31
|
+
diffData?: { previous: EdgeModelData; current: EdgeModelData },
|
|
32
|
+
diffState?: { previous: State[]; current: State[] },
|
|
33
|
+
): EdgeShapeMap {
|
|
34
|
+
const { data = {} } = model;
|
|
35
|
+
|
|
36
|
+
const shapes: EdgeShapeMap = { keyShape: undefined };
|
|
37
|
+
|
|
38
|
+
shapes.keyShape = this.drawKeyShape(
|
|
39
|
+
model,
|
|
40
|
+
sourcePoint,
|
|
41
|
+
targetPoint,
|
|
42
|
+
shapeMap,
|
|
43
|
+
diffData,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (data.haloShape) {
|
|
47
|
+
shapes.haloShape = this.drawHaloShape(model, shapeMap, diffData);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (data.labelShape) {
|
|
51
|
+
shapes.labelShape = this.drawLabelShape(model, shapeMap, diffData);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// labelBackgroundShape
|
|
55
|
+
if (data.labelBackgroundShape) {
|
|
56
|
+
shapes.labelBackgroundShape = this.drawLabelBackgroundShape(
|
|
57
|
+
model,
|
|
58
|
+
shapeMap,
|
|
59
|
+
diffData,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (data.iconShape) {
|
|
64
|
+
shapes.iconShape = this.drawIconShape(model, shapeMap, diffData);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// TODO: other shapes
|
|
68
|
+
return shapes;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public drawKeyShape(
|
|
72
|
+
model: EdgeDisplayModel,
|
|
73
|
+
sourcePoint: Point,
|
|
74
|
+
targetPoint: Point,
|
|
75
|
+
shapeMap: EdgeShapeMap,
|
|
76
|
+
diffData?: { previous: EdgeModelData; current: EdgeModelData },
|
|
77
|
+
diffState?: { previous: State[]; current: State[] },
|
|
78
|
+
) {
|
|
79
|
+
const { keyShape: keyShapeStyle } = this.mergedStyles as any;
|
|
80
|
+
|
|
81
|
+
const controlPoint = this.getControlPoint(
|
|
82
|
+
sourcePoint,
|
|
83
|
+
targetPoint,
|
|
84
|
+
keyShapeStyle.curvePosition,
|
|
85
|
+
keyShapeStyle.controlPoints,
|
|
86
|
+
keyShapeStyle.curveOffset,
|
|
87
|
+
);
|
|
88
|
+
return this.upsertShape(
|
|
89
|
+
'path',
|
|
90
|
+
'keyShape',
|
|
91
|
+
{
|
|
92
|
+
...keyShapeStyle,
|
|
93
|
+
path: [
|
|
94
|
+
['M', sourcePoint.x, sourcePoint.y],
|
|
95
|
+
['Q', controlPoint.x, controlPoint.y, targetPoint.x, targetPoint.y],
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
shapeMap,
|
|
99
|
+
model,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* calculate the control point by curvePosition|controlPoints|curveOffset
|
|
105
|
+
* @param startPoint: source point position of edge
|
|
106
|
+
* @param endPoint target point position of edge
|
|
107
|
+
* @param percent the proportion of control points' in the segment, Range 0 to 1
|
|
108
|
+
* @param controlPoints the control point position
|
|
109
|
+
* @param offset the curveOffset
|
|
110
|
+
* @returns control points
|
|
111
|
+
*/
|
|
112
|
+
private getControlPoint: (
|
|
113
|
+
startPoint: Point,
|
|
114
|
+
endPoint: Point,
|
|
115
|
+
percent: number,
|
|
116
|
+
controlPoints: number[],
|
|
117
|
+
offset: number[],
|
|
118
|
+
) => Point = (
|
|
119
|
+
startPoint: Point,
|
|
120
|
+
endPoint: Point,
|
|
121
|
+
percent = 0,
|
|
122
|
+
controlPoints,
|
|
123
|
+
offset,
|
|
124
|
+
) => ({
|
|
125
|
+
x:
|
|
126
|
+
(1 - percent) * startPoint.x +
|
|
127
|
+
percent * endPoint.x +
|
|
128
|
+
controlPoints[0] +
|
|
129
|
+
offset[0],
|
|
130
|
+
y:
|
|
131
|
+
(1 - percent) * startPoint.y +
|
|
132
|
+
percent * endPoint.y +
|
|
133
|
+
controlPoints[1] +
|
|
134
|
+
offset[1],
|
|
135
|
+
});
|
|
136
|
+
}
|