Skip to content

Commit 076f26a

Browse files
authored
perf: improve the performance of dagre with layers; (#106)
1 parent 17e915a commit 076f26a

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ChangeLog
22

3+
### 0.3.4
4+
5+
- perf: improve the performance of dagre with layers;
6+
37
### 0.3.3
48

59
- fix: dagre layer failed when the layer number begin with 0;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/layout",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "graph layout algorithm",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/layout/dagre/src/rank/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const longestPathWithLayer = (g: Graph) => {
107107
// minRank += 1; // NOTE: 最小的层级是dummy root,+1
108108

109109
// forward一遍,赋值层级
110+
const forwardVisited: Record<string, boolean> = {};
110111
const dfsForward = (v: string, nextRank: number) => {
111112
const label = g.node(v)!;
112113

@@ -119,6 +120,9 @@ const longestPathWithLayer = (g: Graph) => {
119120
label.rank = currRank;
120121
}
121122

123+
if (forwardVisited[v]) return;
124+
forwardVisited[v] = true;
125+
122126
// DFS遍历子节点
123127
g.outEdges(v)?.map((e) => {
124128
dfsForward(e.w, currRank + g.edge(e)!.minlen!);

0 commit comments

Comments
 (0)