I want to keep a clicked node expanded and collapse other siblings of the clicked node.

134 views
Skip to first unread message

nimm

unread,
Oct 12, 2015, 11:15:00 AM10/12/15
to d3-js
On a radial tree layout..I want to keep a clicked node expanded and collapse other siblings of the clicked node.

For example:


So..in example on first view if i click "analytics node" it collapses and sibling "animate node" also collapses.

But, i want is to  click on and collapse only "analytics node" but not "animate node"

How should i approach? can somebody help me?

Ben Lyall

unread,
Oct 12, 2015, 10:12:08 PM10/12/15
to d3-js
I answered a similar question on Stack Overflow not that long ago that should provide some help.  Take a look and if you've got any questions, let me know.


Ben.

nimm

unread,
Oct 15, 2015, 7:06:19 AM10/15/15
to d3-js
Thanks a lot Ben.
I updated my code according to your comments.
But, I am still stuck with one small problem. ;-(

I can now expand the nodes as i want but when it collapsing and bring the tree to its original state.
I am not able to do it.
I have attached a fiiddle here 


Can you please help me with this.
Looking forward for your reply

Ben Lyall

unread,
Oct 15, 2015, 10:40:47 PM10/15/15
to d3-js
In your click handler, you don't seem to have the else clause necessary to expand the node if it's already collapsed.

Take a look at my example again, and you'll see in the click handler there is an if statement, one branch is run if the node is expanded, the other is run if it is already collapsed.  They do the opposite of each other.  I suspect that is where the issue is coming from.

Ben.
Reply all
Reply to author
Forward
0 new messages