I am trying to create a collapsible tree structure in Cytoscape using breadthfirst layout, to replicate the D3 collapsible tree.
I am trying to replicate this type of click action on nodes, but adding restore functionality in addition - Images & breadthfirst layout
The reason I chose Cytoscape is because I had a scenario where the tree would have nodes with more than 1 parent.
I have tried to add a tap event using the following code:
cy.on('tap', 'node', function() {
if (this.scratch().restData == null) {
// Save node data and remove
this.scratch({
restData: this.connectedEdges().targets().remove()
});
} else {
// Restore the removed nodes from saved data
this.scratch().restData.restore();
this.scratch({
restData: null
});
}
}
But, this is successful only to collapse and expand its immediate child nodes (rest of the nodes are still visible) and also causes problem when I tap on leaf nodes.
If anyone knows a way to expand and collapse a node, please help.
Edit: Guys, if anyone knows the solution for a simple multilevel tree also, that would also be a good start...
d3.js
and the tag should probably be removed. If you are interested in d3, though,cytoscape
looks like it produces whatd3
would call a force tree. – Snowfall