From 282024c5c5560707e3b4ea78a21a979a3fc44e73 Mon Sep 17 00:00:00 2001 From: Yanyan Wang Date: Wed, 14 Dec 2022 20:58:37 +0800 Subject: [PATCH] fix: dagre with complex combos; (#117) --- CHANGELOG.md | 5 ++++- __tests__/g6/dagre-g6-test.ts | 2 +- package.json | 2 +- src/layout/dagre/src/rank/feasible-tree.ts | 2 +- src/layout/dagre/src/rank/util.ts | 7 ++++++- src/layout/dagre/src/util.ts | 1 + 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a6f942b..1a4efa0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # ChangeLog +### 0.3.11 -### 0.4.10 +- fix: dagre with complex combos; + +### 0.3.10 - chore: upgrade g-webgpu-core; diff --git a/__tests__/g6/dagre-g6-test.ts b/__tests__/g6/dagre-g6-test.ts index 5c1db656..f41ea77b 100644 --- a/__tests__/g6/dagre-g6-test.ts +++ b/__tests__/g6/dagre-g6-test.ts @@ -257,7 +257,7 @@ describe("dagre layout", () => { graph.data(tdata); graph.render(); - + // graph.getGroup().addShape('circle', { // attrs: { // r: 46.63239832592534, diff --git a/package.json b/package.json index 79c4fde8..97f09210 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@antv/layout", - "version": "0.3.10", + "version": "0.3.11", "description": "graph layout algorithm", "main": "lib/index.js", "module": "es/index.js", diff --git a/src/layout/dagre/src/rank/feasible-tree.ts b/src/layout/dagre/src/rank/feasible-tree.ts index 226d9884..300ecb5a 100644 --- a/src/layout/dagre/src/rank/feasible-tree.ts +++ b/src/layout/dagre/src/rank/feasible-tree.ts @@ -97,7 +97,7 @@ const feasibleTreeWithLayer = (g: Graph) => { // Choose arbitrary node from which to start our tree const start = g.nodes()[0]; - const size = g.nodeCount(); + const size = g.nodes().filter(n => !!g.node(n)).length; t.setNode(start, {}); let edge: any; diff --git a/src/layout/dagre/src/rank/util.ts b/src/layout/dagre/src/rank/util.ts index 5982a51c..b6491732 100644 --- a/src/layout/dagre/src/rank/util.ts +++ b/src/layout/dagre/src/rank/util.ts @@ -26,6 +26,7 @@ const longestPath = (g: Graph) => { const dfs = (v: string) => { const label = g.node(v)!; + if (!label) return 0; if (visited[v]) { return label.rank!; } @@ -65,6 +66,7 @@ const longestPathWithLayer = (g: Graph) => { const dfs = (v: string) => { const label = g.node(v)!; + if (!label) return 0; if (visited[v]) { return label.rank!; } @@ -98,7 +100,9 @@ const longestPathWithLayer = (g: Graph) => { return rank; }; - g.sources()?.forEach((source) => dfs(source)); + g.sources()?.forEach((source) => { + if (g.node(source)) dfs(source) + }); if (minRank! === undefined) { minRank = 0; @@ -132,6 +136,7 @@ const longestPathWithLayer = (g: Graph) => { // 指定层级的,更新下游 g.nodes().forEach((n) => { const label = g.node(n)!; + if(!label) return; if (!isNaN(label.layer as number)) { dfsForward(n, label.layer as number); // 默认的dummy root所在层的rank是-1 } else { diff --git a/src/layout/dagre/src/util.ts b/src/layout/dagre/src/util.ts index e17928ea..8cf0f6e2 100644 --- a/src/layout/dagre/src/util.ts +++ b/src/layout/dagre/src/util.ts @@ -155,6 +155,7 @@ export const buildLayerMatrix = (g: Graph) => { // const layering = _.map(_.range(maxRank(g) + 1), function() { return []; }); g.nodes().forEach((v: string) => { const node = g.node(v)!; + if (!node) return; const rank = node.rank; if (rank !== undefined && layeringNodes[rank]) { layeringNodes[rank].push(v);