-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnectivity.html
89 lines (73 loc) · 1.94 KB
/
connectivity.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
89
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
fill: none;
stroke: #bbb;
}
.node text {
pointer-events: none;
font: 10px sans-serif;
stroke: black;
stroke-width: 0px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = window.innerWidth * .98,
height = window.innerHeight * .95,
radius = 5;
var color = d3.scale.category20();
var force = d3.layout.force()
.charge(-80)
.gravity(.04)
.linkDistance(function(d) { return 50 + 10000 / d.value; })
.size([width, height]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("lists.json", function(error, graph) {
force
.nodes(graph.nodes)
.links(graph.links)
.start();
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link");
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("g")
.attr("class", "node")
.call(force.drag);
node.append("circle")
.attr("class", "node")
.attr("r", radius)
.style("fill", function(d) { return color(d.group); })
.append("svg:title")
.text(function(d) { return d.name; });
node.append("text")
.attr("dx", 12)
.attr("dy", ".35em")
.text(function(d) { return d.name });
force.on("tick", function() {
node.attr("transform", function(d) {
d.x = Math.max(radius, Math.min(width - radius, d.x));
d.y = Math.max(radius, Math.min(height - radius, d.y));
return "translate("
+ d.x + ","
+ d.y + ")";
});
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; });
});
});
</script>
<title>HCS group connectivity graph</title>