-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet.html
88 lines (69 loc) · 2.44 KB
/
net.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html>
<head>
<title>Tweeter mentions</title>
<script type="text/javascript" src="d3.js"></script>
<script type="text/javascript" src="d3.layout.js"></script>
<script type="text/javascript" src="lib/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="d3.geom.js"></script>
<style type="text/css">
.link { stroke: #ccc; }
.nodetext { pointer-events: none; font: 10px sans-serif; }
</style>
</head>
<body>
<div id="mention">FIA Twitter Mention Network: Node size by Degree</div>
<script type="text/javascript">
var width = 1200, height = 800;
// var color = d3.scale.category20();
force = d3.layout.force()
.charge(-120)
.linkDistance(40)
.size([width, height]);
var svg = d3.select("#mention").append("svg")
.attr("width", width)
.attr("height", height);
// before this, best way would be to set the source and target for each link by the index of the node, using ForEach, and node.index //
var data;
d3.json("query-result", function(json){
data=json;
var nodes = data.nodes;
var links = data.edges;
var nodeIndex=[]
nodes.forEach(function(val) {
nodeIndex.push(val.user_id);
});
console.log(nodeIndex);
links.forEach(function(val){
val.source = jQuery.inArray(val.source_user_id , nodeIndex );
val.target = jQuery.inArray(val.target_user_id , nodeIndex );
});
force.nodes(nodes).links(links).start();
var link = svg.selectAll("line.link")
.data(links)
.enter().append("line")
.attr("class", "link");
// .style("stroke-width", function(d,i) { var o = force.nodes[i]; console.log(o) ;return Math.sqrt(1); });
var node = svg.selectAll("circle.node")
.data(nodes)
.enter().append("circle")
.attr("class", "node")
.attr("r", function(d,i) { return Math.sqrt(force.nodes()[i].weight); })
.style("fill","white" )
.style("stroke","green")
.style("stroke-width",2)
.call(force.drag);
node.append("title").text(function(d) { return d.screen_name; });
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; })
.attr("cy", function(d) { return d.y; });
});
}
);
</script>
</body>
</html>