bumbeishvili / org-chart

Highly customizable org chart. Integrations available for Angular, React, Vue
https://stackblitz.com/edit/web-platform-o5t1ha
MIT License
897 stars 317 forks source link

How can I read which nodes are expanded? #398

Open ldm-acn opened 4 months ago

ldm-acn commented 4 months ago

I need to read which nodes are expanded when I click a button in the page that is rendering my orgchart.

To do so I pass a reference to the same data object I pass to d3 and check if the _expanded flag is set, this gives me a value of true if the node is expanded and a value of undefined otherwise.

My issue is that for the nodes that are already visibile when the tree first renders the value is always undefined.

If I hide all the nodes exepct the root the values are then set to false for all the nodes.

After that if I expand again the tree the value for all nodes except the root are set to true when I would exepect them to, but the value for the root alwys stays on false.

I also tried checking the expanded, _children, children, _centered and centered flags for all nodes and they always are undefined. In fact, the only property that is set when interacting with the tree is _expanded.

Is there a way that I can check with nodes are open on the orgchart at any given time?

bumbeishvili commented 4 months ago

If the node parent has .children property, then the current node is expanded, otherwise if the node parent has _children property then current node is collapsed

ldm-acn commented 4 months ago

You're right that I can get that info from the handlers implemented by the library like onNodeClick and onExpandOrCollapse.

Since I was seeing the _expanded property being modified in the original data object I had hoped that I could have access to the same data from outside the methods of OrgChart.

This seems to be an unintended side effect and the data object itself is (correctly) cloned for internal use.