I am experimenting with d3 and tree layout. I think if it is possible to create tree with for example two roots. I know that it is rule that tree has only one root but maybe someone has some example.
Here's a Fiddle showing what I think you're looking for. The important code is right near the bottom.
node.each(function(d){
if (d.name == "flare")
d3.select(this).remove();});
link.each(function(d){
if (d.source.name == "flare")
d3.select(this).remove();});
This is just using the sample data from one of the d3 tree examples, where the root node has the field name
as flare
. Adjust accordingly for your own data set, as well as the name of the node
and link
variables (containing the g
and path
objects respectively). Essentially how this is works is by creating a tree with a single root node and then removing that node and its links which leaves the children, allowing for as many pseudo-roots as you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With