@antv/g6 5.0.25 → 5.0.26
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 +2 -2
- package/dist/lib/behaviors/auto-adapt-label.d.ts +99 -0
- package/dist/lib/behaviors/fix-element-size.d.ts +63 -19
- package/dist/lib/behaviors/index.d.ts +2 -0
- package/dist/lib/behaviors/optimize-viewport-transform.d.ts +3 -3
- package/dist/lib/exports.d.ts +3 -3
- package/dist/lib/plugins/edge-bundling/index.d.ts +97 -0
- package/dist/lib/plugins/index.d.ts +2 -0
- package/dist/lib/runtime/data.d.ts +1 -1
- package/dist/lib/runtime/element.d.ts +1 -1
- package/dist/lib/runtime/viewport.d.ts +3 -1
- package/dist/lib/transforms/map-node-size.d.ts +12 -21
- package/dist/lib/transforms/process-parallel-edges.d.ts +4 -0
- package/dist/lib/transforms/utils.d.ts +9 -0
- package/dist/lib/types/centrality.d.ts +20 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/utils/animation.d.ts +1 -1
- package/dist/lib/utils/bbox.d.ts +9 -0
- package/dist/lib/utils/centrality.d.ts +53 -0
- package/dist/lib/utils/padding.d.ts +16 -0
- package/dist/lib/utils/transform.d.ts +0 -13
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/auto-adapt-label.d.ts +99 -0
- package/esm/behaviors/auto-adapt-label.js +167 -0
- package/esm/behaviors/auto-adapt-label.js.map +1 -0
- package/esm/behaviors/fix-element-size.d.ts +63 -19
- package/esm/behaviors/fix-element-size.js +142 -59
- package/esm/behaviors/fix-element-size.js.map +1 -1
- package/esm/behaviors/hover-activate.js +1 -2
- package/esm/behaviors/hover-activate.js.map +1 -1
- package/esm/behaviors/index.d.ts +2 -0
- package/esm/behaviors/index.js +1 -0
- package/esm/behaviors/index.js.map +1 -1
- package/esm/behaviors/optimize-viewport-transform.d.ts +3 -3
- package/esm/exports.d.ts +3 -3
- package/esm/exports.js +1 -1
- package/esm/exports.js.map +1 -1
- package/esm/plugins/edge-bundling/index.d.ts +97 -0
- package/esm/plugins/edge-bundling/index.js +252 -0
- package/esm/plugins/edge-bundling/index.js.map +1 -0
- package/esm/plugins/index.d.ts +2 -0
- package/esm/plugins/index.js +1 -0
- package/esm/plugins/index.js.map +1 -1
- package/esm/registry/build-in.js +4 -2
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/behavior.js +1 -1
- package/esm/runtime/behavior.js.map +1 -1
- package/esm/runtime/data.d.ts +1 -1
- package/esm/runtime/element.d.ts +1 -1
- package/esm/runtime/viewport.d.ts +3 -1
- package/esm/runtime/viewport.js +13 -4
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/transforms/collapse-expand-combo.js +0 -1
- package/esm/transforms/collapse-expand-combo.js.map +1 -1
- package/esm/transforms/map-node-size.d.ts +12 -21
- package/esm/transforms/map-node-size.js +34 -178
- package/esm/transforms/map-node-size.js.map +1 -1
- package/esm/transforms/process-parallel-edges.d.ts +4 -0
- package/esm/transforms/process-parallel-edges.js +41 -37
- package/esm/transforms/process-parallel-edges.js.map +1 -1
- package/esm/transforms/utils.d.ts +9 -0
- package/esm/transforms/utils.js +11 -0
- package/esm/transforms/utils.js.map +1 -1
- package/esm/types/centrality.d.ts +20 -0
- package/esm/types/centrality.js +2 -0
- package/esm/types/centrality.js.map +1 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/utils/animation.d.ts +1 -1
- package/esm/utils/bbox.d.ts +9 -0
- package/esm/utils/bbox.js +15 -0
- package/esm/utils/bbox.js.map +1 -1
- package/esm/utils/centrality.d.ts +53 -0
- package/esm/utils/centrality.js +177 -0
- package/esm/utils/centrality.js.map +1 -0
- package/esm/utils/padding.d.ts +16 -0
- package/esm/utils/padding.js +22 -0
- package/esm/utils/padding.js.map +1 -1
- package/esm/utils/transform.d.ts +0 -13
- package/esm/utils/transform.js +0 -23
- package/esm/utils/transform.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/auto-adapt-label.d.ts +99 -0
- package/lib/behaviors/auto-adapt-label.js +171 -0
- package/lib/behaviors/auto-adapt-label.js.map +1 -0
- package/lib/behaviors/fix-element-size.d.ts +63 -19
- package/lib/behaviors/fix-element-size.js +141 -58
- package/lib/behaviors/fix-element-size.js.map +1 -1
- package/lib/behaviors/hover-activate.js +1 -2
- package/lib/behaviors/hover-activate.js.map +1 -1
- package/lib/behaviors/index.d.ts +2 -0
- package/lib/behaviors/index.js +3 -1
- package/lib/behaviors/index.js.map +1 -1
- package/lib/behaviors/optimize-viewport-transform.d.ts +3 -3
- package/lib/exports.d.ts +3 -3
- package/lib/exports.js +3 -2
- package/lib/exports.js.map +1 -1
- package/lib/plugins/edge-bundling/index.d.ts +97 -0
- package/lib/plugins/edge-bundling/index.js +256 -0
- package/lib/plugins/edge-bundling/index.js.map +1 -0
- package/lib/plugins/index.d.ts +2 -0
- package/lib/plugins/index.js +3 -1
- package/lib/plugins/index.js.map +1 -1
- package/lib/registry/build-in.js +2 -0
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/behavior.js +1 -1
- package/lib/runtime/behavior.js.map +1 -1
- package/lib/runtime/data.d.ts +1 -1
- package/lib/runtime/element.d.ts +1 -1
- package/lib/runtime/viewport.d.ts +3 -1
- package/lib/runtime/viewport.js +12 -3
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/transforms/collapse-expand-combo.js +0 -1
- package/lib/transforms/collapse-expand-combo.js.map +1 -1
- package/lib/transforms/map-node-size.d.ts +12 -21
- package/lib/transforms/map-node-size.js +33 -177
- package/lib/transforms/map-node-size.js.map +1 -1
- package/lib/transforms/process-parallel-edges.d.ts +4 -0
- package/lib/transforms/process-parallel-edges.js +41 -37
- package/lib/transforms/process-parallel-edges.js.map +1 -1
- package/lib/transforms/utils.d.ts +9 -0
- package/lib/transforms/utils.js +12 -0
- package/lib/transforms/utils.js.map +1 -1
- package/lib/types/centrality.d.ts +20 -0
- package/lib/types/centrality.js +3 -0
- package/lib/types/centrality.js.map +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/utils/animation.d.ts +1 -1
- package/lib/utils/bbox.d.ts +9 -0
- package/lib/utils/bbox.js +16 -0
- package/lib/utils/bbox.js.map +1 -1
- package/lib/utils/centrality.d.ts +53 -0
- package/lib/utils/centrality.js +187 -0
- package/lib/utils/centrality.js.map +1 -0
- package/lib/utils/padding.d.ts +16 -0
- package/lib/utils/padding.js +24 -0
- package/lib/utils/padding.js.map +1 -1
- package/lib/utils/transform.d.ts +0 -13
- package/lib/utils/transform.js +0 -25
- package/lib/utils/transform.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/behaviors/auto-adapt-label.ts +255 -0
- package/src/behaviors/fix-element-size.ts +213 -83
- package/src/behaviors/hover-activate.ts +2 -3
- package/src/behaviors/index.ts +2 -0
- package/src/behaviors/optimize-viewport-transform.ts +3 -3
- package/src/exports.ts +3 -0
- package/src/plugins/edge-bundling/index.ts +373 -0
- package/src/plugins/index.ts +2 -0
- package/src/registry/build-in.ts +4 -0
- package/src/runtime/behavior.ts +1 -0
- package/src/runtime/viewport.ts +14 -4
- package/src/transforms/collapse-expand-combo.ts +0 -1
- package/src/transforms/map-node-size.ts +52 -209
- package/src/transforms/process-parallel-edges.ts +50 -41
- package/src/transforms/utils.ts +12 -0
- package/src/types/centrality.ts +8 -0
- package/src/types/index.ts +1 -0
- package/src/utils/bbox.ts +17 -0
- package/src/utils/centrality.ts +209 -0
- package/src/utils/padding.ts +24 -0
- package/src/utils/transform.ts +0 -32
- package/src/version.ts +1 -1
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { isEmpty } from '@antv/util';
|
|
2
|
+
import { GraphEvent } from '../../constants';
|
|
3
|
+
import type { RuntimeContext } from '../../runtime/types';
|
|
4
|
+
import type { EdgeData } from '../../spec';
|
|
5
|
+
import type { ID, Point } from '../../types';
|
|
6
|
+
import { getPolylinePath } from '../../utils/edge';
|
|
7
|
+
import { idOf } from '../../utils/id';
|
|
8
|
+
import { positionOf } from '../../utils/position';
|
|
9
|
+
import { add, distance, divide, dot, multiply, subtract, toVector2 } from '../../utils/vector';
|
|
10
|
+
import type { BasePluginOptions } from '../base-plugin';
|
|
11
|
+
import { BasePlugin } from '../base-plugin';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* <zh/> 边绑定插件的配置项
|
|
15
|
+
*
|
|
16
|
+
* <en/> Edge bundling options
|
|
17
|
+
*/
|
|
18
|
+
export interface EdgeBundlingOptions extends BasePluginOptions {
|
|
19
|
+
/**
|
|
20
|
+
* <zh/> 边的强度
|
|
21
|
+
*
|
|
22
|
+
* <en/> The strength of the edge
|
|
23
|
+
* @defaultValue 0.1
|
|
24
|
+
*/
|
|
25
|
+
K?: number;
|
|
26
|
+
/**
|
|
27
|
+
* <zh/> 初始步长。在后续的周期中,步长将双倍递增
|
|
28
|
+
*
|
|
29
|
+
* <en/> An initial step size. In subsequent cycles, the step size will double incrementally
|
|
30
|
+
* @defaultValue 0.1
|
|
31
|
+
*/
|
|
32
|
+
lambda?: number;
|
|
33
|
+
/**
|
|
34
|
+
* <zh/> 模拟周期数
|
|
35
|
+
*
|
|
36
|
+
* <en/> The number of simulation cycles
|
|
37
|
+
* @defaultValue 6
|
|
38
|
+
*/
|
|
39
|
+
cycles?: number;
|
|
40
|
+
/**
|
|
41
|
+
* <zh/> 初始切割点数。在后续的周期中,切割点数将根据 `divRate` 逐步递增
|
|
42
|
+
*
|
|
43
|
+
* <en/> An initial number of subdivision points for each edge. In subsequent cycles, the number of subdivision points will increase gradually according to `divRate`
|
|
44
|
+
* @defaultValue 1
|
|
45
|
+
*/
|
|
46
|
+
divisions?: number;
|
|
47
|
+
/**
|
|
48
|
+
* <zh/> 切割点数增长率
|
|
49
|
+
*
|
|
50
|
+
* <en/> The rate at which the number of subdivision points increases
|
|
51
|
+
* @defaultValue 2
|
|
52
|
+
*/
|
|
53
|
+
divRate?: number;
|
|
54
|
+
/**
|
|
55
|
+
* <zh/> 指定在第一个周期中执行的迭代次数。在后续的周期中,迭代次数将根据 `iterRate` 逐步递减
|
|
56
|
+
*
|
|
57
|
+
* <en/> The number of iteration steps during the first cycle. In subsequent cycles, the number of iterations will decrease gradually according to `iterRate`
|
|
58
|
+
* @defaultValue 90
|
|
59
|
+
*/
|
|
60
|
+
iterations?: number;
|
|
61
|
+
/**
|
|
62
|
+
* <zh/> 迭代次数递减率
|
|
63
|
+
*
|
|
64
|
+
* <en/> The rate at which the number of iterations decreases
|
|
65
|
+
* @defaultValue 2 / 3
|
|
66
|
+
*/
|
|
67
|
+
iterRate?: number;
|
|
68
|
+
/**
|
|
69
|
+
* <zh/> 边兼容性阈值,决定了哪些边应该被绑定在一起
|
|
70
|
+
*
|
|
71
|
+
* <en/> Edge compatibility threshold, which determines which edges should be bundled together
|
|
72
|
+
* @defaultValue 0.6
|
|
73
|
+
*/
|
|
74
|
+
bundleThreshold?: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* <zh/> 边绑定
|
|
79
|
+
*
|
|
80
|
+
* <en/> Edge bundling
|
|
81
|
+
* @remarks
|
|
82
|
+
* <zh/> 边绑定(Edge Bundling)是一种图可视化技术,用于减少复杂网络图中的视觉混乱,并揭示图中的高级别模式和结构。其思想是将相邻的边捆绑在一起。
|
|
83
|
+
*
|
|
84
|
+
* <zh/> G6 中提供的边绑定插件是基于 FEDB(Force-Directed Edge Bundling for Graph Visualization)一文的实现:将边建模为可以相互吸引的柔性弹簧,通过自组织的方式进行捆绑。
|
|
85
|
+
*
|
|
86
|
+
* <en/> Edge bundling is a graph visualization technique used to reduce visual clutter in complex network graphs and reveal high-level patterns and structures in the graph. The idea is to bundle adjacent edges together.
|
|
87
|
+
*
|
|
88
|
+
* <en/> The edge bundling plugin provided in G6 is based on the implementation of the paper FEDB (Force-Directed Edge Bundling for Graph Visualization): modeling edges as flexible springs that can attract each other and bundling them in a self-organizing way.
|
|
89
|
+
*/
|
|
90
|
+
export class EdgeBundling extends BasePlugin<EdgeBundlingOptions> {
|
|
91
|
+
static defaultOptions: Partial<EdgeBundlingOptions> = {
|
|
92
|
+
K: 0.1,
|
|
93
|
+
lambda: 0.1,
|
|
94
|
+
divisions: 1,
|
|
95
|
+
divRate: 2,
|
|
96
|
+
cycles: 6,
|
|
97
|
+
iterations: 90,
|
|
98
|
+
iterRate: 2 / 3,
|
|
99
|
+
bundleThreshold: 0.6,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
constructor(context: RuntimeContext, options?: EdgeBundlingOptions) {
|
|
103
|
+
super(context, Object.assign({}, EdgeBundling.defaultOptions, options));
|
|
104
|
+
this.bindEvents();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private edgeBundles: Record<ID, EdgeData[]> = {};
|
|
108
|
+
|
|
109
|
+
private edgePoints: Record<ID, Point[]> = {};
|
|
110
|
+
|
|
111
|
+
private get nodeMap(): Record<ID, Point> {
|
|
112
|
+
const nodes = this.context.model.getNodeData();
|
|
113
|
+
return Object.fromEntries(nodes.map((node) => [idOf(node), toVector2(positionOf(node))]));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private divideEdges(divisions: number) {
|
|
117
|
+
const edges = this.context.model.getEdgeData();
|
|
118
|
+
|
|
119
|
+
edges.forEach((edge) => {
|
|
120
|
+
const edgeId = idOf(edge);
|
|
121
|
+
this.edgePoints[edgeId] ||= [];
|
|
122
|
+
|
|
123
|
+
const source = this.nodeMap[edge.source];
|
|
124
|
+
const target = this.nodeMap[edge.target];
|
|
125
|
+
|
|
126
|
+
if (divisions === 1) {
|
|
127
|
+
this.edgePoints[edgeId].push(source);
|
|
128
|
+
this.edgePoints[edgeId].push(divide(add(source, target), 2));
|
|
129
|
+
this.edgePoints[edgeId].push(target);
|
|
130
|
+
} else {
|
|
131
|
+
const edgeLength =
|
|
132
|
+
this.edgePoints[edgeId].length === 0
|
|
133
|
+
? // edge is a straight line
|
|
134
|
+
distance(source, target)
|
|
135
|
+
: // edge is a polyline
|
|
136
|
+
getEdgeLength(this.edgePoints[edgeId]);
|
|
137
|
+
|
|
138
|
+
const divisionLength = edgeLength / (divisions + 1);
|
|
139
|
+
let currentDivisionLength = divisionLength;
|
|
140
|
+
|
|
141
|
+
const newEdgePoints: Point[] = [source];
|
|
142
|
+
|
|
143
|
+
for (let i = 1; i < this.edgePoints[edgeId].length; i++) {
|
|
144
|
+
const prevEp = this.edgePoints[edgeId][i - 1];
|
|
145
|
+
const ep = this.edgePoints[edgeId][i];
|
|
146
|
+
let oriDivisionLength = distance(ep, prevEp);
|
|
147
|
+
|
|
148
|
+
while (oriDivisionLength > currentDivisionLength) {
|
|
149
|
+
const ratio = currentDivisionLength / oriDivisionLength;
|
|
150
|
+
const edgePoint = add(prevEp, multiply(subtract(ep, prevEp), ratio));
|
|
151
|
+
newEdgePoints.push(edgePoint);
|
|
152
|
+
|
|
153
|
+
oriDivisionLength -= currentDivisionLength;
|
|
154
|
+
currentDivisionLength = divisionLength;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
currentDivisionLength -= oriDivisionLength;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
newEdgePoints.push(target);
|
|
161
|
+
this.edgePoints[edgeId] = newEdgePoints;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private getVectorPosition(edge: EdgeData): VectorPosition {
|
|
167
|
+
const source = this.nodeMap[edge.source];
|
|
168
|
+
const target = this.nodeMap[edge.target];
|
|
169
|
+
const [vx, vy] = subtract(target, source);
|
|
170
|
+
const length = distance(source, target);
|
|
171
|
+
return { source, target, vx, vy, length };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private measureEdgeCompatibility(edge1: EdgeData, edge2: EdgeData) {
|
|
175
|
+
const vector1 = this.getVectorPosition(edge1);
|
|
176
|
+
const vector2 = this.getVectorPosition(edge2);
|
|
177
|
+
|
|
178
|
+
const ac = getAngleCompatibility(vector1, vector2);
|
|
179
|
+
const sc = getScaleCompatibility(vector1, vector2);
|
|
180
|
+
const pc = getPositionCompatibility(vector1, vector2);
|
|
181
|
+
const vc = getVisibilityCompatibility(vector1, vector2);
|
|
182
|
+
|
|
183
|
+
return ac * sc * pc * vc;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private getEdgeBundles() {
|
|
187
|
+
const edgeBundles: Record<ID, EdgeData[]> = {};
|
|
188
|
+
const bundleThreshold = this.options.bundleThreshold;
|
|
189
|
+
const edges = this.context.model.getEdgeData();
|
|
190
|
+
|
|
191
|
+
edges.forEach((edge1, i) => {
|
|
192
|
+
edges.forEach((edge2, j) => {
|
|
193
|
+
if (j <= i) return;
|
|
194
|
+
|
|
195
|
+
const compatibility = this.measureEdgeCompatibility(edge1, edge2);
|
|
196
|
+
if (compatibility >= bundleThreshold) {
|
|
197
|
+
edgeBundles[idOf(edge1)] ||= [];
|
|
198
|
+
edgeBundles[idOf(edge1)].push(edge2);
|
|
199
|
+
edgeBundles[idOf(edge2)] ||= [];
|
|
200
|
+
edgeBundles[idOf(edge2)].push(edge1);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
return edgeBundles;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private getSpringForce(divisions: { pre: Point; cur: Point; next: Point }, kp: number): Point {
|
|
208
|
+
const { pre, cur, next } = divisions;
|
|
209
|
+
return multiply(subtract(add(pre, next), multiply(cur, 2)), kp);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private getElectrostaticForce(pidx: number, edge: EdgeData): Point {
|
|
213
|
+
if (isEmpty(this.edgeBundles)) {
|
|
214
|
+
this.edgeBundles = this.getEdgeBundles();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const edgeBundle = this.edgeBundles[idOf(edge)];
|
|
218
|
+
let resForce: Point = [0, 0];
|
|
219
|
+
|
|
220
|
+
edgeBundle?.forEach((eb) => {
|
|
221
|
+
const p1 = this.edgePoints[idOf(eb)][pidx];
|
|
222
|
+
const p2 = this.edgePoints[idOf(edge)][pidx];
|
|
223
|
+
const force = subtract(p1, p2);
|
|
224
|
+
const length = distance(p1, p2);
|
|
225
|
+
resForce = add(resForce, multiply(force, 1 / length));
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
return resForce;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private getEdgeForces(edge: EdgeData, divisions: number, lambda: number): Point[] {
|
|
232
|
+
const source = this.nodeMap[edge.source];
|
|
233
|
+
const target = this.nodeMap[edge.target];
|
|
234
|
+
const kp = this.options.K / (distance(source, target) * (divisions + 1));
|
|
235
|
+
const edgePointForces: Point[] = [[0, 0]];
|
|
236
|
+
const edgeId = idOf(edge);
|
|
237
|
+
|
|
238
|
+
for (let i = 1; i < divisions; i++) {
|
|
239
|
+
const spring = this.getSpringForce(
|
|
240
|
+
{
|
|
241
|
+
pre: this.edgePoints[edgeId][i - 1],
|
|
242
|
+
cur: this.edgePoints[edgeId][i],
|
|
243
|
+
next: this.edgePoints[edgeId][i + 1] || [0, 0],
|
|
244
|
+
},
|
|
245
|
+
kp,
|
|
246
|
+
);
|
|
247
|
+
const electrostatic = this.getElectrostaticForce(i, edge);
|
|
248
|
+
edgePointForces.push(multiply(add(spring, electrostatic), lambda));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
edgePointForces.push([0, 0]);
|
|
252
|
+
|
|
253
|
+
return edgePointForces;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
protected onBundle = () => {
|
|
257
|
+
const { model, element } = this.context;
|
|
258
|
+
const edges = model.getEdgeData();
|
|
259
|
+
this.divideEdges(this.options.divisions);
|
|
260
|
+
|
|
261
|
+
const { cycles, iterRate, divRate } = this.options;
|
|
262
|
+
let { lambda, divisions, iterations } = this.options;
|
|
263
|
+
for (let i = 0; i < cycles; i++) {
|
|
264
|
+
for (let j = 0; j < iterations; j++) {
|
|
265
|
+
const forces: Record<ID, Point[]> = {};
|
|
266
|
+
edges.forEach((edge) => {
|
|
267
|
+
if (edge.source === edge.target) return;
|
|
268
|
+
const edgeId = idOf(edge);
|
|
269
|
+
forces[edgeId] = this.getEdgeForces(edge, divisions, lambda);
|
|
270
|
+
|
|
271
|
+
for (let p = 0; p < divisions + 1; p++) {
|
|
272
|
+
this.edgePoints[edgeId] ||= [];
|
|
273
|
+
this.edgePoints[edgeId][p] = add(this.edgePoints[edgeId][p], forces[edgeId][p]);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// parameters for next cycle
|
|
279
|
+
lambda /= 2;
|
|
280
|
+
divisions *= divRate;
|
|
281
|
+
iterations *= iterRate;
|
|
282
|
+
this.divideEdges(divisions);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
edges.forEach((edge) => {
|
|
286
|
+
const edgeId = idOf(edge);
|
|
287
|
+
const edgeEl = element!.getElement(edgeId)!;
|
|
288
|
+
edgeEl.update({ d: getPolylinePath(this.edgePoints[edgeId]) });
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
private bindEvents() {
|
|
293
|
+
const { graph } = this.context;
|
|
294
|
+
|
|
295
|
+
graph.on(GraphEvent.AFTER_RENDER, this.onBundle);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private unbindEvents() {
|
|
299
|
+
const { graph } = this.context;
|
|
300
|
+
|
|
301
|
+
graph.off(GraphEvent.AFTER_RENDER, this.onBundle);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public destroy(): void {
|
|
305
|
+
this.unbindEvents();
|
|
306
|
+
super.destroy();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
interface VectorPosition {
|
|
311
|
+
source: Point;
|
|
312
|
+
target: Point;
|
|
313
|
+
vx: number;
|
|
314
|
+
vy: number;
|
|
315
|
+
length: number;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// The larger the angle between edges P and Q, the smaller Ca(P,Q).
|
|
319
|
+
// Ca(P,Q) is 0 if P and Q are orthogonal and 1 if P and Q are parallel.
|
|
320
|
+
const getAngleCompatibility = (p: VectorPosition, q: VectorPosition): number => {
|
|
321
|
+
return Math.abs(dot([p.vx, p.vy], [q.vx, q.vy]) / (p.length * q.length));
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// Cs(P,Q) is 1 if P and Q have equal length and approaches 0 if the ratio between the longest and the shortest edge approaches ∞.
|
|
325
|
+
const getScaleCompatibility = (p: VectorPosition, q: VectorPosition): number => {
|
|
326
|
+
const aLength = (p.length + q.length) / 2;
|
|
327
|
+
return 2 / (aLength / Math.min(p.length, q.length) + Math.max(p.length, q.length) / aLength);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
// Cp(P,Q) is 1 if Pm and Qm coincide and approaches 0 if ||Pm −Qm|| approaches ∞.
|
|
331
|
+
const getPositionCompatibility = (p: VectorPosition, q: VectorPosition): number => {
|
|
332
|
+
const aLength = (p.length + q.length) / 2;
|
|
333
|
+
|
|
334
|
+
const pMid = divide(add(p.source, p.target), 2);
|
|
335
|
+
const qMid = divide(add(q.source, q.target), 2);
|
|
336
|
+
|
|
337
|
+
return aLength / (aLength + distance(pMid, qMid));
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const projectPointToEdge = (p: Point, e: VectorPosition): Point => {
|
|
341
|
+
if (e.source[0] === e.target[0]) return [e.source[0], p[1]];
|
|
342
|
+
if (e.source[1] === e.target[1]) return [p[0], e.source[1]];
|
|
343
|
+
const k = (e.source[1] - e.target[1]) / (e.source[0] - e.target[0]);
|
|
344
|
+
const x = (k * k * e.source[0] + k * (p[1] - e.source[1]) + p[0]) / (k * k + 1);
|
|
345
|
+
const y = k * (x - e.source[0]) + e.source[1];
|
|
346
|
+
return [x, y];
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const getEdgeVisibility = (p: VectorPosition, q: VectorPosition): number => {
|
|
350
|
+
const is = projectPointToEdge(q.source, p);
|
|
351
|
+
const it = projectPointToEdge(q.target, p);
|
|
352
|
+
const iMid = divide(add(is, it), 2);
|
|
353
|
+
const pMid = divide(add(p.source, p.target), 2);
|
|
354
|
+
if (distance(is, it) === 0) return 0;
|
|
355
|
+
return Math.max(0, 1 - (2 * distance(pMid, iMid)) / distance(is, it));
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
const getVisibilityCompatibility = (p: VectorPosition, q: VectorPosition): number => {
|
|
359
|
+
return Math.min(getEdgeVisibility(p, q), getEdgeVisibility(q, p));
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Calculate the length of a polyline
|
|
364
|
+
* @param points - The points of the polyline
|
|
365
|
+
* @returns The length of the polyline
|
|
366
|
+
*/
|
|
367
|
+
const getEdgeLength = (points: Point[]): number => {
|
|
368
|
+
let length = 0;
|
|
369
|
+
for (let i = 1; i < points.length; i++) {
|
|
370
|
+
length += distance(points[i], points[i - 1]);
|
|
371
|
+
}
|
|
372
|
+
return length;
|
|
373
|
+
};
|
package/src/plugins/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { BasePlugin } from './base-plugin';
|
|
|
3
3
|
export { BubbleSets } from './bubble-sets';
|
|
4
4
|
export { CameraSetting } from './camera-setting';
|
|
5
5
|
export { Contextmenu } from './contextmenu';
|
|
6
|
+
export { EdgeBundling } from './edge-bundling';
|
|
6
7
|
export { EdgeFilterLens } from './edge-filter-lens';
|
|
7
8
|
export { Fisheye } from './fisheye';
|
|
8
9
|
export { Fullscreen } from './fullscreen';
|
|
@@ -22,6 +23,7 @@ export type { BasePluginOptions } from './base-plugin';
|
|
|
22
23
|
export type { BubbleSetsOptions } from './bubble-sets';
|
|
23
24
|
export type { CameraSettingOptions } from './camera-setting';
|
|
24
25
|
export type { ContextmenuOptions } from './contextmenu';
|
|
26
|
+
export type { EdgeBundlingOptions } from './edge-bundling';
|
|
25
27
|
export type { EdgeFilterLensOptions } from './edge-filter-lens';
|
|
26
28
|
export type { FisheyeOptions } from './fisheye';
|
|
27
29
|
export type { FullscreenOptions } from './fullscreen';
|
package/src/registry/build-in.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from '@antv/g';
|
|
13
13
|
import { ComboCollapse, ComboExpand, Fade, NodeCollapse, NodeExpand, PathIn, PathOut, Translate } from '../animations';
|
|
14
14
|
import {
|
|
15
|
+
AutoAdaptLabel,
|
|
15
16
|
BrushSelect,
|
|
16
17
|
ClickSelect,
|
|
17
18
|
CollapseExpand,
|
|
@@ -73,6 +74,7 @@ import {
|
|
|
73
74
|
Background,
|
|
74
75
|
BubbleSets,
|
|
75
76
|
Contextmenu,
|
|
77
|
+
EdgeBundling,
|
|
76
78
|
EdgeFilterLens,
|
|
77
79
|
Fisheye,
|
|
78
80
|
Fullscreen,
|
|
@@ -127,6 +129,7 @@ const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
|
|
|
127
129
|
'focus-element': FocusElement,
|
|
128
130
|
'hover-activate': HoverActivate,
|
|
129
131
|
'lasso-select': LassoSelect,
|
|
132
|
+
'auto-adapt-label': AutoAdaptLabel,
|
|
130
133
|
'optimize-viewport-transform': OptimizeViewportTransform,
|
|
131
134
|
'scroll-canvas': ScrollCanvas,
|
|
132
135
|
'zoom-canvas': ZoomCanvas,
|
|
@@ -188,6 +191,7 @@ const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
|
|
|
188
191
|
},
|
|
189
192
|
plugin: {
|
|
190
193
|
'bubble-sets': BubbleSets,
|
|
194
|
+
'edge-bundling': EdgeBundling,
|
|
191
195
|
'edge-filter-lens': EdgeFilterLens,
|
|
192
196
|
'grid-line': GridLine,
|
|
193
197
|
background: Background,
|
package/src/runtime/behavior.ts
CHANGED
package/src/runtime/viewport.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { clamp, isNumber, pick } from '@antv/util';
|
|
|
3
3
|
import { AnimationType, GraphEvent } from '../constants';
|
|
4
4
|
import type { FitViewOptions, ID, Point, TransformOptions, Vector2, ViewportAnimationEffectTiming } from '../types';
|
|
5
5
|
import { getAnimationOptions } from '../utils/animation';
|
|
6
|
-
import { getBBoxSize, getCombinedBBox, isPointInBBox } from '../utils/bbox';
|
|
6
|
+
import { getBBoxSize, getCombinedBBox, getExpandedBBox, isBBoxInside, isPointInBBox } from '../utils/bbox';
|
|
7
7
|
import { AnimateEvent, ViewportEvent, emit } from '../utils/event';
|
|
8
8
|
import { isPoint } from '../utils/is';
|
|
9
9
|
import { parsePadding } from '../utils/padding';
|
|
@@ -279,19 +279,29 @@ export class ViewportController {
|
|
|
279
279
|
*
|
|
280
280
|
* <en/> Determine whether the point or bounding box is in the viewport
|
|
281
281
|
* @param target - <zh/> 点或包围盒 | <en/> Point or bounding box
|
|
282
|
+
* @param complete - <zh/> 是否完全在视口中 | <en/> Whether it is completely in the viewport
|
|
283
|
+
* @param tolerance - <zh/> 视口外的容差 | <en/> Tolerance outside the viewport
|
|
282
284
|
* @returns - <zh/> 是否在视口中 | <en/> Whether it is in the viewport
|
|
283
285
|
*/
|
|
284
|
-
public isInViewport(target: Point | AABB) {
|
|
286
|
+
public isInViewport(target: Point | AABB, complete = false, tolerance = 0) {
|
|
285
287
|
const { graph } = this.context;
|
|
286
288
|
const size = this.getCanvasSize();
|
|
287
289
|
|
|
288
290
|
const [x1, y1] = graph.getCanvasByViewport([0, 0]);
|
|
289
291
|
const [x2, y2] = graph.getCanvasByViewport(size);
|
|
290
292
|
|
|
291
|
-
|
|
293
|
+
let viewportBBox = new AABB();
|
|
292
294
|
viewportBBox.setMinMax([x1, y1, 0], [x2, y2, 0]);
|
|
293
295
|
|
|
294
|
-
|
|
296
|
+
if (tolerance) {
|
|
297
|
+
viewportBBox = getExpandedBBox(viewportBBox, tolerance);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return isPoint(target)
|
|
301
|
+
? isPointInBBox(target, viewportBBox)
|
|
302
|
+
: !complete
|
|
303
|
+
? viewportBBox.intersects(target)
|
|
304
|
+
: isBBoxInside(target, viewportBBox);
|
|
295
305
|
}
|
|
296
306
|
|
|
297
307
|
public cancelAnimation() {
|
|
@@ -4,7 +4,6 @@ import type { ComboData } from '../spec';
|
|
|
4
4
|
import { isCollapsed } from '../utils/collapsibility';
|
|
5
5
|
import { getSubgraphRelatedEdges } from '../utils/edge';
|
|
6
6
|
import { idOf } from '../utils/id';
|
|
7
|
-
// import { reassignTo } from '../utils/transform';
|
|
8
7
|
import { BaseTransform } from './base-transform';
|
|
9
8
|
import type { DrawData } from './types';
|
|
10
9
|
import { reassignTo } from './utils';
|