Database Reference
In-Depth Information
//Store the list of retweeted nodes
ArrayList<NetworkNode> finalnodes = new ArrayList<
NetworkNode>();
for(String n:allnodes) {
...
}
//Sort in ascending order of the Node ID
Collections.sort(finalnodes,new NodeIDComparator());
//Step 5: Reformat the network into D3 format
return GetD3Structure(finalnodes);
}
Source: Chapter5/network/CreateD3Network.java
Listing 5.3
Visualizing the retweet network using force-directed layout
create_network: function() {
...
// Step 1: Create the nodes and the links in the network
network_page.net = network_page.create_dataset(network_page.
jsondata, network_page.net, network_page.getGroup);
/ **
* Step 2: Initialize the D3 layout with the data and node
settings that
* define the forces acting on the nodes and start the layout
* /
network_page.force = d3.layout.force()
.nodes(network_page.net.nodes)
.links(network_page.net.links)
.size([width,height])
.charge(-500)
.linkDistance(80)
.theta(0.8)
.gravity(0.2)
.start();
...
/ **
* Step 3: Compute the distance between nodes after each
iteration
* the forces are computed using the tick event.
* /
network_page.force.on( "tick" , function() {
link.attr( "x1" , function(d) { return d.source.x; })
.attr( "y1" , function(d) { return d.source.y; })
.attr( "x2" , function(d) { return d.target.x; })
.attr( "y2" , function(d) { return d.target.y; });
node.attr( "cx" , function(d) {
return d.x = Math.max(r, Math.min(width - r, d.x));
}).attr( "cy" , function(d) {
return d.y = Math.max(r, Math.min(height - r, d.y));
});
}
Source: TwitterDataAnalytics/js/network.js
 
Search WWH ::




Custom Search