@antv/g6 5.0.25 → 5.0.27
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/README.en-US.md +5 -5
- package/README.md +5 -5
- package/dist/g6.min.js +78 -5
- 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 +8 -4
- package/dist/lib/elements/combos/base-combo.d.ts +1 -1
- 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 +2 -14
- package/dist/lib/version.d.ts +1 -1
- package/esm/animations/executor.js +1 -0
- package/esm/animations/executor.js.map +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 +8 -4
- package/esm/behaviors/optimize-viewport-transform.js +31 -11
- package/esm/behaviors/optimize-viewport-transform.js.map +1 -1
- package/esm/elements/combos/base-combo.d.ts +1 -1
- package/esm/elements/combos/base-combo.js +1 -1
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/nodes/base-node.js +1 -1
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/elements/shapes/base-shape.js +1 -1
- package/esm/elements/shapes/base-shape.js.map +1 -1
- 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/fisheye/index.js +1 -1
- package/esm/plugins/fisheye/index.js.map +1 -1
- 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/preset.js +0 -2
- package/esm/preset.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/element.js +3 -0
- package/esm/runtime/element.js.map +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/place-radial-labels.js +5 -3
- package/esm/transforms/place-radial-labels.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/edge.js +5 -2
- package/esm/utils/edge.js.map +1 -1
- package/esm/utils/element.js +1 -1
- package/esm/utils/element.js.map +1 -1
- 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/polygon.js +3 -3
- package/esm/utils/polygon.js.map +1 -1
- package/esm/utils/transform.d.ts +2 -14
- package/esm/utils/transform.js +18 -23
- package/esm/utils/transform.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/animations/executor.js +1 -0
- package/lib/animations/executor.js.map +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 +8 -4
- package/lib/behaviors/optimize-viewport-transform.js +31 -11
- package/lib/behaviors/optimize-viewport-transform.js.map +1 -1
- package/lib/elements/combos/base-combo.d.ts +1 -1
- package/lib/elements/combos/base-combo.js +1 -1
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/nodes/base-node.js +1 -1
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/elements/shapes/base-shape.js +1 -1
- package/lib/elements/shapes/base-shape.js.map +1 -1
- 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/fisheye/index.js +1 -1
- package/lib/plugins/fisheye/index.js.map +1 -1
- 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/preset.js +0 -2
- package/lib/preset.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/element.js +3 -0
- package/lib/runtime/element.js.map +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/place-radial-labels.js +5 -3
- package/lib/transforms/place-radial-labels.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/edge.js +5 -2
- package/lib/utils/edge.js.map +1 -1
- package/lib/utils/element.js +1 -1
- package/lib/utils/element.js.map +1 -1
- 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/polygon.js +3 -3
- package/lib/utils/polygon.js.map +1 -1
- package/lib/utils/transform.d.ts +2 -14
- package/lib/utils/transform.js +18 -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 +8 -8
- package/src/animations/executor.ts +1 -0
- 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 +36 -18
- package/src/elements/combos/base-combo.ts +1 -1
- package/src/elements/nodes/base-node.ts +1 -1
- package/src/elements/shapes/base-shape.ts +1 -1
- package/src/exports.ts +3 -0
- package/src/plugins/edge-bundling/index.ts +373 -0
- package/src/plugins/fisheye/index.ts +1 -1
- package/src/plugins/index.ts +2 -0
- package/src/preset.ts +0 -2
- package/src/registry/build-in.ts +4 -0
- package/src/runtime/behavior.ts +1 -0
- package/src/runtime/element.ts +3 -1
- 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/place-radial-labels.ts +6 -3
- 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/edge.ts +6 -3
- package/src/utils/element.ts +1 -1
- package/src/utils/padding.ts +24 -0
- package/src/utils/polygon.ts +3 -3
- package/src/utils/transform.ts +25 -32
- package/src/version.ts +1 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { findShortestPath, pageRank } from '@antv/algorithm';
|
|
2
|
+
import type { EdgeData, GraphData } from '../spec';
|
|
3
|
+
import type { EdgeDirection, ID, NodeCentralityOptions } from '../types';
|
|
4
|
+
import { idOf } from './id';
|
|
5
|
+
|
|
6
|
+
export type CentralityResult = Map<ID, number>;
|
|
7
|
+
|
|
8
|
+
export const getNodeCentralities = (
|
|
9
|
+
graphData: GraphData,
|
|
10
|
+
getRelatedEdgesData: (id: ID, direction?: EdgeDirection) => EdgeData[],
|
|
11
|
+
centrality: NodeCentralityOptions,
|
|
12
|
+
) => {
|
|
13
|
+
switch (centrality.type) {
|
|
14
|
+
case 'degree': {
|
|
15
|
+
const centralityResult = new Map<ID, number>();
|
|
16
|
+
graphData.nodes?.forEach((node) => {
|
|
17
|
+
const degree = getRelatedEdgesData(idOf(node), centrality.direction).length;
|
|
18
|
+
centralityResult.set(idOf(node), degree);
|
|
19
|
+
});
|
|
20
|
+
return centralityResult;
|
|
21
|
+
}
|
|
22
|
+
case 'betweenness':
|
|
23
|
+
return computeNodeBetweennessCentrality(graphData, centrality.directed, centrality.weightPropertyName);
|
|
24
|
+
case 'closeness':
|
|
25
|
+
return computeNodeClosenessCentrality(graphData, centrality.directed, centrality.weightPropertyName);
|
|
26
|
+
case 'eigenvector':
|
|
27
|
+
return computeNodeEigenvectorCentrality(graphData, centrality.directed);
|
|
28
|
+
case 'pagerank':
|
|
29
|
+
return computeNodePageRankCentrality(graphData, centrality.epsilon, centrality.linkProb);
|
|
30
|
+
default:
|
|
31
|
+
return initCentralityResult(graphData);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const initCentralityResult = (graphData: GraphData): CentralityResult => {
|
|
36
|
+
const centralityResult = new Map<ID, number>();
|
|
37
|
+
graphData.nodes?.forEach((node) => {
|
|
38
|
+
centralityResult.set(idOf(node), 0);
|
|
39
|
+
});
|
|
40
|
+
return centralityResult;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* <zh/> 计算图中每个节点的中介中心性
|
|
45
|
+
*
|
|
46
|
+
* <en/> Calculate the betweenness centrality for each node in the graph
|
|
47
|
+
* @param graphData - <zh/> 图数据 | <en/>Graph data
|
|
48
|
+
* @param directed - <zh/> 是否为有向图 | <en/>Whether the graph is directed
|
|
49
|
+
* @param weightPropertyName - <zh/> 边的权重属性名 | <en/>The weight property name of the edge
|
|
50
|
+
* @returns <zh/> 每个节点的中介中心性值 | <en/>The betweenness centrality for each node
|
|
51
|
+
*/
|
|
52
|
+
export const computeNodeBetweennessCentrality = (
|
|
53
|
+
graphData: GraphData,
|
|
54
|
+
directed?: boolean,
|
|
55
|
+
weightPropertyName?: string,
|
|
56
|
+
): CentralityResult => {
|
|
57
|
+
const centralityResult = initCentralityResult(graphData);
|
|
58
|
+
const { nodes = [] } = graphData;
|
|
59
|
+
nodes.forEach((source) => {
|
|
60
|
+
nodes.forEach((target) => {
|
|
61
|
+
if (source !== target) {
|
|
62
|
+
const { allPath } = findShortestPath(graphData, idOf(source), idOf(target), directed, weightPropertyName);
|
|
63
|
+
const pathCount = allPath.length;
|
|
64
|
+
(allPath as ID[][]).flat().forEach((nodeId) => {
|
|
65
|
+
if (nodeId !== idOf(source) && nodeId !== idOf(target)) {
|
|
66
|
+
centralityResult.set(nodeId, centralityResult.get(nodeId)! + 1 / pathCount);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
return centralityResult;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* <zh/> 计算图中每个节点的接近中心性
|
|
77
|
+
*
|
|
78
|
+
* <en/> Calculate the closeness centrality for each node in the graph
|
|
79
|
+
* @param graphData - <zh/> 图数据 | <en/>Graph data
|
|
80
|
+
* @param directed - <zh/> 是否为有向图 | <en/>Whether the graph is directed
|
|
81
|
+
* @param weightPropertyName - <zh/> 边的权重属性名 | <en/>The weight property name of the edge
|
|
82
|
+
* @returns <zh/> 每个节点的接近中心性值 | <en/>The closeness centrality for each node
|
|
83
|
+
*/
|
|
84
|
+
export const computeNodeClosenessCentrality = (
|
|
85
|
+
graphData: GraphData,
|
|
86
|
+
directed?: boolean,
|
|
87
|
+
weightPropertyName?: string,
|
|
88
|
+
): CentralityResult => {
|
|
89
|
+
const centralityResult = new Map<ID, number>();
|
|
90
|
+
const { nodes = [] } = graphData;
|
|
91
|
+
nodes.forEach((source) => {
|
|
92
|
+
const totalLength = nodes.reduce((acc, target) => {
|
|
93
|
+
if (source !== target) {
|
|
94
|
+
const { length } = findShortestPath(graphData, idOf(source), idOf(target), directed, weightPropertyName);
|
|
95
|
+
acc += length;
|
|
96
|
+
}
|
|
97
|
+
return acc;
|
|
98
|
+
}, 0);
|
|
99
|
+
centralityResult.set(idOf(source), 1 / totalLength);
|
|
100
|
+
});
|
|
101
|
+
return centralityResult;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* <zh/> 计算图中每个节点的 PageRank 中心性
|
|
106
|
+
*
|
|
107
|
+
* <en/> Calculate the PageRank centrality for each node in the graph
|
|
108
|
+
* @param graphData - <zh/> 图数据 | <en/>Graph data
|
|
109
|
+
* @param epsilon - <zh/> PageRank 算法的收敛容差 | <en/>The convergence tolerance of the PageRank algorithm
|
|
110
|
+
* @param linkProb - <zh/> PageRank 算法的阻尼系数,指任意时刻,用户访问到某节点后继续访问该节点链接的下一个节点的概率,经验值 0.85 | <en/>The damping factor of the PageRank algorithm, which refers to the probability that a user will continue to visit the next node linked to a node at any time, with an empirical value of 0.85
|
|
111
|
+
* @returns <zh/> 每个节点的 PageRank 中心性值 | <en/>The PageRank centrality for each node
|
|
112
|
+
*/
|
|
113
|
+
export const computeNodePageRankCentrality = (
|
|
114
|
+
graphData: GraphData,
|
|
115
|
+
epsilon?: number,
|
|
116
|
+
linkProb?: number,
|
|
117
|
+
): CentralityResult => {
|
|
118
|
+
const centralityResult = new Map<ID, number>();
|
|
119
|
+
const data = pageRank(graphData, epsilon, linkProb);
|
|
120
|
+
graphData.nodes?.forEach((node) => {
|
|
121
|
+
centralityResult.set(idOf(node), data[idOf(node)]);
|
|
122
|
+
});
|
|
123
|
+
return centralityResult;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* <zh/> 计算图中每个节点的特征向量中心性
|
|
128
|
+
*
|
|
129
|
+
* <en/> Calculate the eigenvector centrality for each node in the graph.
|
|
130
|
+
* @param graphData - <zh/> 图数据 | <en/>Graph data
|
|
131
|
+
* @param directed - <zh/> 是否为有向图 | <en/>Whether the graph is directed
|
|
132
|
+
* @returns 每个节点的特征向量中心性值 The eigenvector centrality for each node.
|
|
133
|
+
*/
|
|
134
|
+
export const computeNodeEigenvectorCentrality = (graphData: GraphData, directed?: boolean): CentralityResult => {
|
|
135
|
+
const { nodes = [] } = graphData;
|
|
136
|
+
const adjacencyMatrix = createAdjacencyMatrix(graphData, directed);
|
|
137
|
+
const eigenvector = powerIteration(adjacencyMatrix, nodes.length);
|
|
138
|
+
|
|
139
|
+
const centralityResult = new Map<ID, number>();
|
|
140
|
+
nodes.forEach((node, index) => {
|
|
141
|
+
centralityResult.set(idOf(node), eigenvector[index]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return centralityResult;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* <zh/> 创建图的邻接矩阵
|
|
149
|
+
*
|
|
150
|
+
* <en/> Create the adjacency matrix for the graph.
|
|
151
|
+
* @param graphData - <zh/> 图数据 | <en/>Graph data
|
|
152
|
+
* @param directed - <zh/> 是否为有向图 | <en/>Whether the graph is directed
|
|
153
|
+
* @returns <zh/> 邻接矩阵 | <en/>The adjacency matrix
|
|
154
|
+
*/
|
|
155
|
+
export const createAdjacencyMatrix = (graphData: GraphData, directed?: boolean): number[][] => {
|
|
156
|
+
const { nodes = [], edges = [] } = graphData;
|
|
157
|
+
const matrix: number[][] = Array(nodes.length)
|
|
158
|
+
.fill(null)
|
|
159
|
+
.map(() => Array(nodes.length).fill(0));
|
|
160
|
+
|
|
161
|
+
edges.forEach(({ source, target }) => {
|
|
162
|
+
const uIndex = nodes.findIndex((node) => idOf(node) === source);
|
|
163
|
+
const vIndex = nodes.findIndex((node) => idOf(node) === target);
|
|
164
|
+
if (directed) {
|
|
165
|
+
matrix[uIndex][vIndex] = 1;
|
|
166
|
+
} else {
|
|
167
|
+
matrix[uIndex][vIndex] = 1;
|
|
168
|
+
matrix[vIndex][uIndex] = 1;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return matrix;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* <zh/> 使用幂迭代法计算主特征向量
|
|
177
|
+
*
|
|
178
|
+
* <en/> Calculate the principal eigenvector using the power iteration method
|
|
179
|
+
* @see https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors
|
|
180
|
+
* @param matrix - <zh/> 邻接矩阵 | <en/> The adjacency matrix
|
|
181
|
+
* @param numNodes - <zh/> 节点数量 | <en/> The number of nodes
|
|
182
|
+
* @param maxIterations - <zh/> 最大迭代次数 | <en/> The maximum number of iterations
|
|
183
|
+
* @param tolerance - <zh/> 收敛容差 | <en/> The convergence tolerance
|
|
184
|
+
* @returns <zh/> 主特征向量 | <en/> The principal eigenvector
|
|
185
|
+
*/
|
|
186
|
+
const powerIteration = (matrix: number[][], numNodes: number, maxIterations = 100, tolerance = 1e-6): number[] => {
|
|
187
|
+
let eigenvector = Array(numNodes).fill(1);
|
|
188
|
+
let diff = Infinity;
|
|
189
|
+
|
|
190
|
+
for (let iter = 0; iter < maxIterations && diff > tolerance; iter++) {
|
|
191
|
+
const newEigenvector = Array(numNodes).fill(0);
|
|
192
|
+
|
|
193
|
+
for (let i = 0; i < numNodes; i++) {
|
|
194
|
+
for (let j = 0; j < numNodes; j++) {
|
|
195
|
+
newEigenvector[i] += matrix[i][j] * eigenvector[j];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const norm = Math.sqrt(newEigenvector.reduce((sum, val) => sum + val * val, 0));
|
|
200
|
+
for (let i = 0; i < numNodes; i++) {
|
|
201
|
+
newEigenvector[i] /= norm;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
diff = Math.sqrt(newEigenvector.reduce((sum, val, index) => sum + (val - eigenvector[index]) * val, 0));
|
|
205
|
+
eigenvector = newEigenvector;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return eigenvector;
|
|
209
|
+
};
|
package/src/utils/edge.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AABB, DisplayObject } from '@antv/g';
|
|
1
|
+
import type { AABB, DisplayObject, TransformArray } from '@antv/g';
|
|
2
2
|
import type { PathArray } from '@antv/util';
|
|
3
3
|
import { isEqual, isNumber } from '@antv/util';
|
|
4
4
|
import type { EdgeData } from '../spec';
|
|
@@ -57,7 +57,7 @@ export function getLabelPositionStyle(
|
|
|
57
57
|
|
|
58
58
|
if (isHorizontal(point, pointOffset) || !autoRotate) {
|
|
59
59
|
const [x, y] = getXYByPlacement(key, ratio, offsetX, offsetY);
|
|
60
|
-
return { transform:
|
|
60
|
+
return { transform: [['translate', x, y]], textAlign };
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
let angle = Math.atan2(pointOffset[1] - point[1], pointOffset[0] - point[0]);
|
|
@@ -70,7 +70,10 @@ export function getLabelPositionStyle(
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const [x, y] = getXYByPlacement(key, ratio, offsetX, offsetY, angle);
|
|
73
|
-
const transform =
|
|
73
|
+
const transform: TransformArray = [
|
|
74
|
+
['translate', x, y],
|
|
75
|
+
['rotate', (angle / Math.PI) * 180],
|
|
76
|
+
];
|
|
74
77
|
|
|
75
78
|
return {
|
|
76
79
|
textAlign,
|
package/src/utils/element.ts
CHANGED
package/src/utils/padding.ts
CHANGED
|
@@ -14,3 +14,27 @@ export function parsePadding(padding: Padding = 0): STDPadding {
|
|
|
14
14
|
}
|
|
15
15
|
return [padding, padding, padding, padding];
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* <zh/> 获取在垂直方向上的 padding
|
|
20
|
+
*
|
|
21
|
+
* <en/> get vertical padding
|
|
22
|
+
* @param padding - <zh/> padding | <en/> padding
|
|
23
|
+
* @returns <zh/> 垂直方向上的 padding | <en/> vertical padding
|
|
24
|
+
*/
|
|
25
|
+
export function getVerticalPadding(padding: Padding = 0): number {
|
|
26
|
+
const parsedPadding = parsePadding(padding);
|
|
27
|
+
return parsedPadding[0] + parsedPadding[2];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* <zh/> 获取在水平方向上的 padding
|
|
32
|
+
*
|
|
33
|
+
* <en/> get horizontal padding
|
|
34
|
+
* @param padding - <zh/> padding | <en/> padding
|
|
35
|
+
* @returns <zh/> 水平方向上的 padding | <en/> horizontal padding
|
|
36
|
+
*/
|
|
37
|
+
export function getHorizontalPadding(padding: Padding = 0): number {
|
|
38
|
+
const parsedPadding = parsePadding(padding);
|
|
39
|
+
return parsedPadding[1] + parsedPadding[3];
|
|
40
|
+
}
|
package/src/utils/polygon.ts
CHANGED
|
@@ -32,7 +32,7 @@ export function getPolygonTextStyleByPlacement(
|
|
|
32
32
|
const style: Partial<TextStyleProps> = {
|
|
33
33
|
textAlign: placement === 'left' ? 'right' : placement === 'right' ? 'left' : 'center',
|
|
34
34
|
textBaseline: placement === 'top' ? 'bottom' : placement === 'bottom' ? 'top' : 'middle',
|
|
35
|
-
transform:
|
|
35
|
+
transform: [['translate', x + offsetX, y + offsetY]],
|
|
36
36
|
};
|
|
37
37
|
if (placement === 'center' || !closeToContour) return style;
|
|
38
38
|
|
|
@@ -51,10 +51,10 @@ export function getPolygonTextStyleByPlacement(
|
|
|
51
51
|
const line = findNearestLine([x, y], lines);
|
|
52
52
|
const intersection = findNearestPointOnLine([x, y], line);
|
|
53
53
|
if (intersection && line) {
|
|
54
|
-
style.transform =
|
|
54
|
+
style.transform = [['translate', intersection[0] + offsetX, intersection[1] + offsetY]];
|
|
55
55
|
if (autoRotate) {
|
|
56
56
|
const angle = Math.atan((line[0][1] - line[1][1]) / (line[0][0] - line[1][0]));
|
|
57
|
-
style.transform
|
|
57
|
+
style.transform.push(['rotate', (angle / Math.PI) * 180]);
|
|
58
58
|
style.textAlign = 'center';
|
|
59
59
|
if (placement === 'right' || placement === 'left') {
|
|
60
60
|
if (angle > 0) {
|
package/src/utils/transform.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { DrawData, ProcedureData } from '../transforms/types';
|
|
3
|
-
import type { ElementDatum, ElementType } from '../types';
|
|
4
|
-
import { idOf } from './id';
|
|
1
|
+
import type { TransformArray } from '@antv/g';
|
|
5
2
|
|
|
6
3
|
/**
|
|
7
4
|
* <zh/> 从 transform 字符串中替换 translate 部分
|
|
@@ -13,7 +10,30 @@ import { idOf } from './id';
|
|
|
13
10
|
* @param transform - <zh/> transform 字符串 | <en/> transform string
|
|
14
11
|
* @returns <zh/> 替换后的 transform 字符串 | <en/> replaced transform string
|
|
15
12
|
*/
|
|
16
|
-
export function replaceTranslateInTransform(
|
|
13
|
+
export function replaceTranslateInTransform(
|
|
14
|
+
x: number,
|
|
15
|
+
y: number,
|
|
16
|
+
z: number,
|
|
17
|
+
transform: string | TransformArray,
|
|
18
|
+
): string | TransformArray {
|
|
19
|
+
if (Array.isArray(transform)) {
|
|
20
|
+
let hasTranslate = false;
|
|
21
|
+
const newTransform: TransformArray = transform.map((t) => {
|
|
22
|
+
if (t[0] === 'translate') {
|
|
23
|
+
hasTranslate = true;
|
|
24
|
+
return ['translate', x, y];
|
|
25
|
+
} else if (t[0] === 'translate3d') {
|
|
26
|
+
hasTranslate = true;
|
|
27
|
+
return ['translate3d', x, y, z];
|
|
28
|
+
}
|
|
29
|
+
return t;
|
|
30
|
+
});
|
|
31
|
+
if (!hasTranslate) {
|
|
32
|
+
newTransform.splice(0, 0, z === 0 ? ['translate', x, y] : ['translate3d', x, y, z]);
|
|
33
|
+
}
|
|
34
|
+
return newTransform;
|
|
35
|
+
}
|
|
36
|
+
|
|
17
37
|
const removedTranslate = transform ? transform.replace(/translate(3d)?\([^)]*\)/g, '') : '';
|
|
18
38
|
if (z === 0) {
|
|
19
39
|
return `translate(${x}, ${y})${removedTranslate}`;
|
|
@@ -21,30 +41,3 @@ export function replaceTranslateInTransform(x: number, y: number, z: number, tra
|
|
|
21
41
|
return `translate3d(${x}, ${y}, ${z})${removedTranslate}`;
|
|
22
42
|
}
|
|
23
43
|
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* <zh/> 重新分配绘制任务
|
|
27
|
-
*
|
|
28
|
-
* <en/> Reassign drawing tasks
|
|
29
|
-
* @param input - <zh/>绘制数据 | <en/>DrawData
|
|
30
|
-
* @param type - <zh/>类型 | <en/>type
|
|
31
|
-
* @param elementType - <zh/>元素类型 | <en/>element type
|
|
32
|
-
* @param datum - <zh/>数据 | <en/>data
|
|
33
|
-
* @param merge - <zh/>是否合并 | <en/>whether to merge
|
|
34
|
-
*/
|
|
35
|
-
export const reassignTo = (
|
|
36
|
-
input: DrawData,
|
|
37
|
-
type: 'add' | 'update' | 'remove',
|
|
38
|
-
elementType: ElementType,
|
|
39
|
-
datum: ElementDatum,
|
|
40
|
-
merge = false,
|
|
41
|
-
) => {
|
|
42
|
-
const id = idOf(datum);
|
|
43
|
-
const typeName = `${elementType}s` as keyof ProcedureData;
|
|
44
|
-
const exitsDatum: any =
|
|
45
|
-
input.add[typeName].get(id) || input.update[typeName].get(id) || input.remove[typeName].get(id) || datum;
|
|
46
|
-
Object.entries(input).forEach(([_type, value]) => {
|
|
47
|
-
if (type === _type) value[typeName].set(id, merge ? deepMix(exitsDatum, datum) : datum);
|
|
48
|
-
else value[typeName].delete(id);
|
|
49
|
-
});
|
|
50
|
-
};
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.0.
|
|
1
|
+
export const version = '5.0.27';
|