bumbeishvili / org-chart

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

fit() function doesn't distinguish between expanded and unexpanded nodes #424

Open Exscotticus opened 3 months ago

Exscotticus commented 3 months ago

Describe the bug In cases where no nodes list is supplied and the root node is used, the fit function doesn't take the root node's location into account along with its descendants. It doesn't distinguish between expanded and unexpanded nodes.

The bug is in the line that defines the descendants.

Currently...

let descendants = nodes ? nodes : root.descendants();

...and what I think it should be...

const descendants = nodes ? nodes : [root].concat(root.descendants().filter(d => d.data._expanded === true));