-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
81 lines (65 loc) · 2.07 KB
/
index.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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
stroke: #999;
stroke-opacity: .6;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="colorbrewer.min.js"></script>
<script>
var width = 1800,
height = 1150;
//var color = d3.scale.category20c();
var color = d3.scale.ordinal()
.domain([1,2,3,4,5])
.range(colorbrewer.Blues[5]);
var color2 = d3.scale.ordinal()
.domain([1,2,3,4,5])
.range(colorbrewer.Oranges[5]);
var force = d3.layout.force()
.charge(-70)
.linkDistance(30)
.size([width, height]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("output.json", function(error, graph) {
if (error) throw error;
force
.nodes(graph.nodes)
.links(graph.links)
.start();
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link")
.style("stroke-width", function(d) { return Math.sqrt(d.value); });
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("class", "node")
.attr("fixed", true)
.attr("cx", function(d) { if(d.num == 1) {return (Math.random() * ((width / 2) - 150) + 75); } else {return (Math.random() * ((width / 2) - 150) + 100 + (width / 2));}})
.attr("cy", function(d) { return (Math.random() * 850) + 50; })
.attr("r", function(d) { return ((d.group + 1) * (d.group + 1)) * 2; })
.style("fill", function(d) { if(d.num == 1) {return color(d.group);} else {return color2(d.group);} })
.call(force.drag);
node.append("title")
.text(function(d) { return d.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>