Search code examples
javascriptcytoscape.jscytoscape

Multiple Root Nodes in Cytoscape


I am creating a tree with Breadthfirst layout in Cytoscape.

In layout options, I have set a node as root. But is there a way that I can have 2 nodes as root nodes? I see in cytoscape reference has layout options in following way:

var options = {
  name: 'breadthfirst',
  roots: undefined, // the roots of the trees
};

Now, individual nodes can be set as root nodes by using its ID. For example:

roots: "#a"

How can I do this So I have multiple roots for a single tree as represented in this image?

Multiple Root Tree representation


Solution

  • Actually, I found out that the easiest way to do it was to use a comma separator. The code will look something like this -

    roots: "#a,#b"