dagrejs / dagre-d3

A D3-based renderer for Dagre
MIT License
2.84k stars 587 forks source link

Unable to draw an edge from a child to parent in compound graph #319

Open thenylify opened 6 years ago

thenylify commented 6 years ago

Hi all,

I am currently using Dagre for one of my data visualisation project, it is a compound graph which requires a node to contain a nested node, I'm unable to draw edges from child nodes to parent nodes, I get the following error:

Uncaught TypeError: Cannot set property ‘rank’ of undefined.

Please also see the below code:

g.setNode('a', {label: 'A'}); g.setNode('b', {label: 'B'}); g.setNode('c', {label: 'C'}); g.setNode('d', {label: 'D'});

g.setNode('top_group', {label: 'Top Group', clusterLabelPos: 'bottom', style: 'fill: #ffd47f'}); g.setNode('bottom_group', {label: 'Group', clusterLabelPos: 'top', style: 'fill: #d3d7e8'});

// Set the parents to define which nodes belong to which cluster g.setParent('a', 'top_group'); g.setParent('b', 'bottom_group'); g.setParent('c', 'bottom_group'); g.setParent('d', 'bottom_group');

// Draw edges g.setEdge('a', 'b'); g.setEdge('b', 'c'); g.setEdge('b', 'd');

// Set edge from child to parent g.setEdge('a', 'bottom_group'); // THIS LINE CAUSES THE ABOVE ERROR

The way how we create a parent is the same as how we create a child node, so the library should allow us to draw an edge from a child node to a parent node.

Please see the following JSFIDDLE: http://jsfiddle.net/thenylify/Lbjm54ob/8/

Can someone please advice?

This is really urgent so can someone please help.

Much appreciated, Thanks, Michael

thenylify commented 6 years ago

PLEASE SEE THE JSFIDDLE: http://jsfiddle.net/thenylify/Lbjm54ob/8/

hastebrot commented 6 years ago

Seems once you promoted a node to a group node you can't define an edge from node to this group node anymore.

screen shot 2018-03-28 at 23 46 14 screen shot 2018-03-28 at 23 46 38

The graph is acyclic, but somehow new dagreD3.render()(d3.select("svg g", g)) ignores, that bottom_group is in g.nodes().

console.log(dagreD3.graphlib.alg.isAcyclic(g)); // true
console.log(g.node("bottom_group")) // Object { label: "Bottom Group", ...

Libraries:

hastebrot commented 6 years ago

This error is thrown whenever a or b in g.setEdge(a, b) is a group node.

thenylify commented 6 years ago

@hastebrot thank you so much for you reply dude. And yes, I did notice that. What I don’t understand is the library created the parent node by using g.setNode function which is same as the way how we created the child node. I think this is a bug rather than a feature, this is a must have feature for a compound/nested graph. I want to make some changes in the library but it’s really hard for me as I don’t have much graph knowledge. @cpettitt if you can give some advice that would be great. I will keep trying.

junneyang commented 6 years ago

any solution?

thenylify commented 6 years ago

@junneyang No, no solutions yet...

AmitMY commented 5 years ago

Or any workaround?

kfd9 commented 5 years ago

I have a same problem. How do solve it?

ChanDaoH commented 4 years ago

Any workaround ?

Polad10 commented 4 years ago

I used d3-graphviz library.

m1666 commented 2 years ago

let g = new graphlib.Graph({ directed: true, compound: true }); Try increasing the parameter compound like above

silentport commented 11 months ago

Any workaround ?

f-gueguen commented 8 months ago

I fixed it the following way:

node_modules/dagre/lib/layout.js in runLayout:

  time("    rank",                   function() { rank(util.asNonCompoundGraph(g)); });

becomes

  time("    rank",                   function() { rank(g); });

then in node_modules/dagre/lib/position/index.js in position(g) { remove

 g = util.asNonCompoundGraph(g);