Skip to content

Commit

Permalink
fix: dagre with complex combos; (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanyan-Wang authored Dec 14, 2022
1 parent 5eafa1f commit 282024c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# ChangeLog

### 0.3.11

### 0.4.10
- fix: dagre with complex combos;

### 0.3.10

- chore: upgrade g-webgpu-core;

Expand Down
2 changes: 1 addition & 1 deletion __tests__/g6/dagre-g6-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe("dagre layout", () => {

graph.data(tdata);
graph.render();

// graph.getGroup().addShape('circle', {
// attrs: {
// r: 46.63239832592534,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/layout/dagre/src/rank/feasible-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/layout/dagre/src/rank/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
}
Expand Down Expand Up @@ -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!;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/layout/dagre/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 282024c

Please sign in to comment.