react-d3-graph icon indicating copy to clipboard operation
react-d3-graph copied to clipboard

Expand nodes dynamically

Open mayukhghoshme opened this issue 5 years ago • 2 comments

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?

mayukhghoshme avatar May 04 '21 08:05 mayukhghoshme

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.

onlyreddy avatar May 10 '21 03:05 onlyreddy

I think this perfectly answers the question ! Thanks @onlyreddy

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

antoninklopp avatar May 13 '21 13:05 antoninklopp