Constructing Force Directed Graphs From Only Link Data Constructing Force Directed Graphs From Only Link Data json json

Constructing Force Directed Graphs From Only Link Data


I've done just this in the example "D3 Based Force Directed Radial Graph". I do this because I want to understand how the data is used, internally, independent of structures like JSON and CSV, which can always be layered in, later.

Anyhow, I hope the example helps you.

My Best,

Frank


I've had to do this a few times. The simplest approach I've found has been to simply compute the set of nodes base don the list of links and then turn it into an array for the force graph to use:

var links = [ .... ];var nodeMap = {};links.forEach(function(d, i) {     nodeMap[d.source] = true;    nodeMap[d.target] = true;});var nodes = [];for (key in nodeMap)    nodes.push(key);d3.layout.force()         .nodes(nodes)         .links(links);