forked from LeeDa16/DataStructure-Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbetweennessHtml.txt
57 lines (51 loc) · 1.48 KB
/
betweennessHtml.txt
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
var width = 1600;
var height = 1000;
var scale = d3.scale.linear()
.domain([0, 10000, 75000])
.range([2, 5, 20]);
var svg = d3.select("body")
.append("svg")
.attr("width",width)
.attr("height",height);
var force = d3.layout.force()
.nodes(nodes)
.links(edges)
.size([width,height])
.linkDistance(150)
.charge(-20);
force.start();
console.log(nodes);
console.log(edges);
var svg_edges = svg.selectAll("line")
.data(edges)
.enter()
.append("line")
.style("stroke","#ccc")
.style("stroke-width",1);
var color = d3.scale.category20();
var svg_nodes = svg.selectAll("circle")
.data(nodes)
.enter()
.append("circle")
.attr("r",function(d){
return scale(d.value);
})
.style("fill",function(d,i){
return color(i);
})
.call(force.drag);
svg_nodes.append("svg:title")
.text(function(d){
return String(d.id) + " " + d.name + '\n' + String(d.value);
});
force.on("tick", function(){
svg_edges.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; });
svg_nodes.attr("cx",function(d){ return d.x; })
.attr("cy",function(d){ return d.y; });
});
</script>
</body>
</html>