dagre
dagre copied to clipboard
error when autolayout
The case is : we use graphlib to create a graph g
g.setNode("boss1", { label: "boss1", width: 30, height: 10 });
g.setNode("hford", { label: "hford", width: 30, height: 10 });
g.setNode("lwilson", { label: "lwilson", width: 30, height: 10 });
g.setParent("hford", 'boss1', {minLen:1}, '6');
g.setParent("lwilson", 'boss1', {minLen:1}, '7');
when we create edge which from other node to connect this parent,
g.setNode("kspacey", { label: "kspacey", width: 30, height: 10 });
g.setEdge("kspacey", "boss1", {minLen:1}, '11');
then we use
dagre.layout(g);
the error will be:
dagre.js:2655 Uncaught TypeError: Cannot set property 'rank' of undefined
at dfs (http://localhost:63342/test/dagre.js:2655:32)
at http://localhost:63342/test/dagre.js:2641:24
at arrayMap (http://localhost:63342/test/dagre.js:5454:41)
at Function.map (http://localhost:63342/test/dagre.js:10758:28)
at dfs (http://localhost:63342/test/dagre.js:2640:32)
at http://localhost:63342/test/dagre.js:2641:24
at arrayMap (http://localhost:63342/test/dagre.js:5454:41)
at Function.map (http://localhost:63342/test/dagre.js:10758:28)
at dfs (http://localhost:63342/test/dagre.js:2640:32)
at arrayEach (http://localhost:63342/test/dagre.js:5337:29)
it looks node boss1 is undefined in g.nodes
Any comments? I also have seen undefineds in g.nodes().forEach( function(v){} for v after dagre.layout().
PS: Thanks for the cool project.
I'm having the same issue.
The problem (for me at least) is atrender.js:135:
g.edges().forEach(function(e) {
var edge = g.edge(e);
if (!_.has(edge, "label")) { edge.label = ""; }
_.defaults(edge, EDGE_DEFAULT_ATTRS);
});
g.edge(g.edges()[0])
This returns undefined, which means that edge.label = ""; will fail.
JUST AS I SUSPECTED this has to do with using graphlib.Graph. Replace your g = graphlib.Graph() line with:
let g = new dagreD3.graphlib.Graph().setGraph({});