bkrem / react-d3-tree

:deciduous_tree: React component to create interactive D3 tree graphs
https://bkrem.github.io/react-d3-tree
MIT License
1.06k stars 268 forks source link

How to set a default path of nodes to be expanded? #441

Closed sockthedev closed 1 year ago

sockthedev commented 1 year ago

Howdy, thanks for this fantastic library. I'm building a fun little project and this will become a core mechanism of interaction for the users. I'd be happy to share when I launch it.

I have one question, sorry I tried parsing the docs but the answer wasn't explicitly obvious.

I would like to load the tree with a specific path expanded (everything else collapsed).

For example, given the following tree;

             A
           /   \
          /     \
         B       E
        / \
       /   \
      C     D

I would like to be able to set the path of A -> B -> D to be be visible/expanded when the tree initially loads;

             A
           /   
          /     
         B 
          \
           \
            D

Is this possible? I'm happy to utilise an imperative API is there is one suitably available.

Thanks again x

sockthedev commented 1 year ago

Duplicate of #402 😅

danielbeeke commented 3 months ago

Something like this patch can work: https://gist.github.com/danielbeeke/ca8e4c6a95928d11cc9b8df0f7c18628