-
Notifications
You must be signed in to change notification settings - Fork 228
Expand nodes dynamically #466
Answered
by
onlyreddy
mayukhghoshme
asked this question in
Q&A
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
Answered by
onlyreddy
May 10, 2021
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.
Replies: 2 comments
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Answer selected by
antoninklopp
-
I think this perfectly answers the question ! Thanks @onlyreddy
Closing this issue, please reopen if any more help is needed
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment