react-d3-graph
react-d3-graph copied to clipboard
Question: Manually collapsing a particular node
Hi,
In my requirement, I need manually to collapse a node. I tried with collapsible property and with the mouse click on the node it's working.
But I need to do it manually so I tried to call onClickNode() by using the ref provided by the Graph component unfortunately it's not working. Then I checked in your project source code and there also's handled in onClickNode.
Can you help me to achieve this?
But I need to do it manually so I tried to call onClickNode()
You mean programmatically? I'm afraid it might not be possible at the moment. I think you can try and look at the property isHidden in the codebase and try to figure a way to make it work properly. But I think it will only get you as far as hiding the connection and not the leaf node. Pull Requests are welcome.
Today only I got the way to do with ref provided by graph. The User has to dynamically update the node click event based from graphref.
graphRef.current.onClickNode(history[currentNodeIndex]);
In my case I'm saving the history of every node then once user click on the prev and next buttons based current node index I'm updating the onClickNode.
The above solution will not work if you have updated any state value.