cytoscape / cytoscape.js-dagre

The Dagre layout for DAGs and trees for Cytoscape.js
MIT License
246 stars 82 forks source link

Layout on a collection of nodes is different than on entire graph #37

Closed Jbonavita closed 5 years ago

Jbonavita commented 5 years ago

I first create a graph with 100's of connected nodes. After all the nodes have been added I call cy.layout({name: "dagre"});

Next, I'm creating 5 or so additional connected nodes I call layout on the nodes added but it doesn't lay them out as expected. Instead of being more like a tree all the nodes are in a straight line.

It looks like this: layout1

collection.layout({ name: "dagre", fit: false, boundingBox: { x1: mousex - width / 2, y1: mousey - height / 2, x2: mousex + width, y2: mousey + height }, nodeSep: 30 }).run();

But I expect it to look like the image below. layout2

In order to get it to look like the above, I call layout shown below.

'cy.layout({name: "dagre"});'

I can't call cy.layout because it lays out the entire graph which is not what I want.

I've looked through all the options for a dagre layout and can't find anything to make it create the tree.

Jbonavita commented 5 years ago

The problem was caused by me not added the edges to the collection. Once I added them, the correct layout was performed.