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 compound graph #238

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

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

thenylify opened this issue Mar 26, 2018 · 12 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.

Can someone please advice?

This is really urgent so can someone please help.

Much appreciated,
Thanks,
Michael

@GordonSmith
Copy link

Just curios why your trying to set and edge usingsetParentand not setEdge?

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

(not saying it will work, just asking?)

@thenylify
Copy link
Author

@GordonSmith thanks for the reply. It was a typo in my question, it’s setEdge, and it’s still having the same error.

@koosvanderkolk
Copy link

Could you please provide a jsfiddle (or equivalent?)

@thenylify
Copy link
Author

@koosvanderkolk Hay, thank you so much for the reply! I have created a JSFiddle for this, but you can refer to this demo repo - https://github.com/dagrejs/dagre-d3/blob/master/demo/clusters.html, you can simply pull this down and run the "Cluster" demo, please add a line "g.setEdge('b', 'bottom_group'); // Try to draw an edge from child "b" to parent "bottom_group"." to line 78 in the clusters.html, after you done this you should see the error "Unable to draw an edge from a child to parent".

In the meantime, I will create a JSFiddle to make this easier to debug for other helpers.

Thanks so much man, appreciate this!

@koosvanderkolk
Copy link

If the error indeed reads "Unable to draw an edge from a child to parent" then I am afraid this isn't just possible with this library.

But maybe with your jsfiddle people can come up with a nice workaround :-).

@thenylify
Copy link
Author

@koosvanderkolk Okay, no problem. Thanks anyway. Here is the JSFiddle if you're interested: http://jsfiddle.net/thenylify/Lbjm54ob/8/

Thank you.

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

No solutions?

@gordonwoodhull
Copy link

I don't think this is supported by this library. You could use graphviz via Viz.js

@ChanDaoH
Copy link

Any workaround ?

1 similar comment
@yangxiaoqiao2016
Copy link

Any workaround ?

@rewweRrr rewweRrr mentioned this issue Apr 3, 2020
@rewweRrr
Copy link

rewweRrr commented Apr 3, 2020

Fix here: #293
Workaround: https://www.npmjs.com/package/dagre-cluster-fix
Workaround for cytoscape-dagre : https://www.npmjs.com/package/cytoscape-dagre-cluster-fix

@LeonsCd
Copy link

LeonsCd commented Apr 19, 2022

if (isNode(element)) {
      const { data,id } = element
      if(id!=="0"){
        const {parentId} = data
        if(parentId===0||parentId){
          g.setParent(id, parentId+"");
        }
      }
      g.setNode(element.id, {
        width: element.__rf?.width,
        height: element.__rf?.height,
      });
    } else {
      g.setEdge(element.source, element.target);
    }

I used setEdge before
but i got the graph drawn by the nodes of the second level is evenly spaced, so I think they are caused by no parent-child relationship
So you see that code
i added the setParent
I hope they can divide the space equally in their own area
but i failed
Uncaught TypeError: Cannot set properties of undefined (setting 'rank')
i don't know what to use

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

9 participants