Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Expand nodes dynamically #466

Answered by onlyreddy
mayukhghoshme asked this question in Q&A
Discussion options

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?
You must be logged in to vote

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

Comment options

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.
You must be logged in to vote
0 replies
Answer selected by antoninklopp
Comment options

I think this perfectly answers the question ! Thanks @onlyreddy

Closing this issue, please reopen if any more help is needed

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #458 on May 15, 2021 11:40.

AltStyle によって変換されたページ (->オリジナル) /