Skip to content

Commit

Permalink
defensive check (#39)
Browse files Browse the repository at this point in the history
* defensive check

* prettier

* defensive check

* defensive check

* Update src/dagre/rank/network-simplex.js

Co-authored-by: Alois Klink <[email protected]>

---------

Co-authored-by: tbo47 <[email protected]>
Co-authored-by: Alois Klink <[email protected]>
  • Loading branch information
3 people authored Sep 23, 2024
1 parent 261104e commit bae97cf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
10 changes: 6 additions & 4 deletions src/dagre/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ function debugOrdering(g) {
layerMatrix.forEach((layer, i) => {
var layerV = 'layer' + i;
h.setNode(layerV, { rank: 'same' });
layer.reduce((u, v) => {
h.setEdge(u, v, { style: 'invis' });
return v;
});
if (layer.length > 0) {
layer.reduce((u, v) => {
h.setEdge(u, v, { style: 'invis' });
return v;
});
}
});

return h;
Expand Down
4 changes: 2 additions & 2 deletions src/dagre/position/bk.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function findType1Conflicts(g, layering) {
return layer;
}

layering.reduce(visitLayer);
if (layering.length > 0) layering.reduce(visitLayer);
return conflicts;
}

Expand Down Expand Up @@ -114,7 +114,7 @@ function findType2Conflicts(g, layering) {
return south;
}

layering.reduce(visitLayer);
if (layering.length > 0) layering.reduce(visitLayer);
return conflicts;
}

Expand Down
18 changes: 11 additions & 7 deletions src/dagre/rank/network-simplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,24 @@ function enterEdge(t, g, edge) {
flip = true;
}

var candidates = g.edges().filter((edge) => {
const candidates = g.edges().filter((edge) => {
return (
flip === isDescendant(t, t.node(edge.v), tailLabel) &&
flip !== isDescendant(t, t.node(edge.w), tailLabel)
);
});

return candidates.reduce((acc, edge) => {
if (slack(g, edge) < slack(g, acc)) {
return edge;
}
if (candidates.length > 0) {
return candidates.reduce((acc, edge) => {
if (slack(g, edge) < slack(g, acc)) {
return edge;
}

return acc;
});
return acc;
});
} else {
return undefined;
}
}

function exchangeEdges(t, g, e, f) {
Expand Down
20 changes: 11 additions & 9 deletions src/graphlib/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,17 @@ export class Graph {
return Object.values(this._edgeObjs);
}
setPath(vs, value) {
var args = arguments;
vs.reduce((v, w) => {
if (args.length > 1) {
this.setEdge(v, w, value);
} else {
this.setEdge(v, w);
}
return w;
});
const args = arguments;
if (vs.length > 0) {
vs.reduce((v, w) => {
if (args.length > 1) {
this.setEdge(v, w, value);
} else {
this.setEdge(v, w);
}
return w;
});
}
return this;
}
/*
Expand Down

0 comments on commit bae97cf

Please sign in to comment.