JavaScript d3.js tree layout: collapsing other nodes when expanding one?

On a tree layout using d3.js (example), I'd like to collapse nodes that are not in the branch that has been clicked on.

For example, in the above demo, try the following:

  1. click on "Parent 1" (Child 1 and Child 2 are shown)
  2. click on "Child 1" (Child 1.1 is shown)
  3. click on "Child 2" (Child 2.1 is shown)

Now you should see both the children of "Child 1" and "Child 2".

I would like to have the following happen:

  1. click on "Parent 1" (Child 1 and Child 2 are shown)
  2. click on "Child 1" (Child 1.1 is shown)
  3. click on "Child 2" (Child 2.1 is shown, Child 1.1 is hidden)

So children of nodes other than on the "active" branch should be hidden.

How can I best approach this? (efficiently of course, as I'll be using a fairly large dataset)

Answer:1

Magento Javascript Question Does anyone know how I can call the session singleton in Javascript? I have a validation to a form like this which, everytime it validates the checkbox element, I want to ...

Magento Javascript Question Does anyone know how I can call the session singleton in Javascript? I have a validation to a form like this which, everytime it validates the checkbox element, I want to ...

  1. magento save data in custom table
  2. magento save data in cache
  3. magento save data in session
  4. magento save data
  5. magento save data to quote
  6. magento 2 save data in custom table
  7. magento 2 save data in model
  8. magento 2 save data into custom model
  9. magento 2 save data in session
  10. magento 1.9 save data in custom table
  11. magento 2 save data in database
  12. magento 2 save data in controller
  13. magento 2 save data to cache
  14. magento 2 save data
  15. magento save form data in database
  16. magento 2 save data in checkout session
  17. magento 2 save data using model
  18. magento model save data
  19. magento 1 save data
  20. magento save collection data

I want to design a helper function which would try to execute passed as parameter deep property path and to return value extracted by it. For example consider following code var foo = { bar: ...

I want to design a helper function which would try to execute passed as parameter deep property path and to return value extracted by it. For example consider following code var foo = { bar: ...

  1. javascript create universal function

How to dismiss Bootstrap popover by clicking outside the popover. Currently it has toggle for open link. HTML <div class="widget-rating"> <span class="rateit rating-average">&...

How to dismiss Bootstrap popover by clicking outside the popover. Currently it has toggle for open link. HTML <div class="widget-rating"> <span class="rateit rating-average">&...

  1. dismiss bootstrap popover programmatically
  2. dismiss bootstrap popover
  3. dismiss bootstrap popover on click
  4. bootstrap dismiss popover click outside
  5. bootstrap popover dismiss button
  6. bootstrap popover dismiss on next click
  7. bootstrap popover dismiss not working
  8. popover dismiss bootstrap 4
  9. bootstrap popover dismiss event
  10. popover dismiss bootstrap 3
  11. bootstrap popover dismiss ios

I am develop an app using GWT Maps Api V3. I try create Place search box like example of Google Maps JavaScript API(link Place search box - Google Maps JavaScript API ) I have viewed the javascript ...

I am develop an app using GWT Maps Api V3. I try create Place search box like example of Google Maps JavaScript API(link Place search box - Google Maps JavaScript API ) I have viewed the javascript ...