Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thenylify opened this issue Mar 26, 2018 · 13 comments
Open

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

thenylify opened this issue Mar 26, 2018 · 13 comments

Comments

@thenylify
Copy link

thenylify commented Mar 26, 2018

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 thenylify changed the title Compound Graph - Unable to draw an edge from a child to parent Urgent!! Compound Graph - Unable to draw an edge from a child to parent Mar 26, 2018
@thenylify thenylify changed the title Urgent!! Compound Graph - Unable to draw an edge from a child to parent Urgent!! Compound Graph - Unable to draw an edge from a child to parent, JSFIDDLE ADDED! Mar 28, 2018
@thenylify
Copy link
Author

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

@hastebrot
Copy link

hastebrot commented Mar 28, 2018

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
Copy link

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

@thenylify
Copy link
Author

@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.

@lutzroeder lutzroeder changed the title Urgent!! Compound Graph - Unable to draw an edge from a child to parent, JSFIDDLE ADDED! Unable to draw an edge from a child to parent in compound graph Apr 4, 2018
@junneyang
Copy link

any solution?

@thenylify
Copy link
Author

@junneyang No, no solutions yet...

@AmitMY
Copy link

AmitMY commented Sep 24, 2018

Or any workaround?

@kfd9
Copy link

kfd9 commented Nov 8, 2018

I have a same problem. How do solve it?

@ChanDaoH
Copy link

Any workaround ?

@Polad10
Copy link

Polad10 commented Mar 30, 2020

I used d3-graphviz library.

@m1666
Copy link

m1666 commented Jun 27, 2022

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

@silentport
Copy link

Any workaround ?

@f-gueguen
Copy link

f-gueguen commented Dec 27, 2023

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants