Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the nodes, groups, and values mean in the JSON for a d3 force-directed graph?

I am trying to create a d3 force-directed graph (http://mbostock.github.com/d3/ex/force.html). Here is the simple JSON file containing my data.

{"nodes":[{"name":"Node1","group":1}, {"name":"Node2","group":1}],

    "links":[{"source":1,"target":2,"value":2}]}

I have two nodes in the same group. I am trying to also create a link between the two nodes. However, my page remains blank (and I am sure that other parts other than the JSON are correct).

What is a "group"? Why do edges have both a "source" and a "target" - and what are these values? Why do links have a "value"? Aren't the links just unweighted edges? I'm having trouble understand the JSON structure of data storage.

like image 869
dangerChihuahua007 Avatar asked Apr 06 '12 02:04

dangerChihuahua007


1 Answers

In the d3 force-directed graph example, the 'value' of links is mapped to the stroke width of the edges and the 'group' of nodes is mapped to the color of the nodes. The integer value of 'source' and 'target' in links refers to the array index of the corresponding node in nodes (https://github.com/mbostock/d3/wiki/Force-Layout#wiki-links).

If you change source links to

 "links":[{"source":0,"target":1,"value":2}]}

it, d3 should render an edge between the two nodes.

like image 114
Lars Grammel Avatar answered Oct 13 '22 21:10

Lars Grammel