0

I am working with the Collapsible Force Layout in D3 and I need a way to start the graph fully collapsed (where I can expand the graph node by node). My graph is relatively large and it lags the screen with the amount of information.

I figured calling the click() function on all nodes in the graph would collapse the graph to a single point .There are examples on click events, but I am not versed enough in Javascript to know how or where to put them in the code to implement them.

This answerthat has been provided before doesn't seem to work when added between the root=json and the update(); lines. Please explain where to add it if it does.

Community
  • 1
  • 1
  • I've tried the suggestions on that answer page and it doesn't seem to work. I've added the link in my original question to see if someone else can get it to work. – Sycomantis Dec 01 '15 at 17:42

1 Answers1

0

The click event swaps the node .children and ._children variables (the second one is ignored when drawing the graph).

If you open your graph.json file and find/replace all "children" with "_children", then it should start off in a collapsed state.

benjaminbenben
  • 1,218
  • 8
  • 15
  • Great! One more problem, now when I expand the nodes down to the orange "leaf" The leaf nodes don't show up, all I see is a link with a missing node. Do I need to add an empty children section for the leaf nodes? – Sycomantis Dec 01 '15 at 01:44
  • @Sycomantis nope, you shouldn't have to add children, perhaps the `size` value is small? (if it's 100, then the circle will have a radius of 1px). (ps, did the answer resolve your original question? Could you mark it if so?) – benjaminbenben Dec 01 '15 at 02:01
  • Apparently the change from children to _children doesn't work. i added the link the other thread in the main body. The answer posted in that thread doesn't seem to work for me. Either that, or I don't fully understand where to put it. – Sycomantis Dec 01 '15 at 04:03