react-d3-graph
react-d3-graph copied to clipboard
Expand nodes dynamically
Hi, I am new to this and evaluating react-d3-graph for a project. Below is my question:
- Is there a way I can populate a node dynamically?
- For example, if I have a parent node and 3 children associated with it, can I click on the child nodes, fetch the data from db and append to the child node its children, thus showing a grandparent to grandchildren relationship?
Yes, you can achieve this feature. You can try with the below steps:
- Maintain the data in a state variable.
- Handle click event of the nodes.
- Update the latest data from DB with setState of the data variable and once that's done you can able to see the new nodes.
- For merging the data I used one package and ie. deepmerge. You can use direct JavaScript. But above package can take care of any type of data format.
- Suppose if you updated the new data then you may use the old one. To bind the with previous data use the below syntax
deepmerge(newData, graphData). - You can follow the same for the remaining nodes also.
I think this perfectly answers the question ! Thanks @onlyreddy
Closing this issue, please reopen if any more help is needed