D3 Collapsible Force Layout adding nodes to the layout dynamically

30 views
Skip to first unread message

Ignacio Carter

unread,
Jun 22, 2016, 7:49:07 PM6/22/16
to d3-js

I have some issues with adding nodes dynamically in my collapsible force layout. My data set will be created dynamically so the object will change every time the force layout is created so I used an example from a D3 mbostock where they used a local object instead of loading a JSON as my initial starting point.

I have added pan + zoom but adding a node seems to not work. I have a static object (for test purposes) and my addNode function is called on click of a node. I am trying to add the nodes through: var childrenTest=[ {"name": "Title", "size": 3938}, {"name": "Title", "size": 3938}, {"name": "Title", "size": 3938} ];

g.data.children[1].children = childrenTest;and then running the update(); which is supposed to flatten the data for collapsing and create links between nodes before updating them.

Unfortunately, it seems that when I do this it completely breaks my graph creating a floating cluster offset from my main graph and links and nodes go missing. I was wondering if I could get some assistance in figuring out why it will not add the nodes properly.

Here is an example of my code: https://jsfiddle.net/Diffusion_net/hu6t2ywb/9/

(Note: the addnode function will only add the node on childless node click once due to the check for test purposes only)

Thank You


P.S.This was also submitted to http://stackoverflow.com/questions/37976133/d3-collapsible-force-layout-adding-nodes-to-the-layout-dynamically
Reply all
Reply to author
Forward
0 new messages