-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
75 lines (60 loc) · 1.87 KB
/
index.html
File metadata and controls
75 lines (60 loc) · 1.87 KB
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
<!DOCTYPE html>
<meta charset="utf-8">
<script src="d3/d3.v3.min.js"></script>
<style>
.link {
stroke: #ccc;
}
.node text {
pointer-events: none;
font: 10px sans-serif;
}
</style>
<body>
<script>
var width = window.innerWidth,
height = window.innerHeight;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var force = d3.layout.force()
.charge(-1299)
.linkDistance(function(d) { return height / (2 + (2 * d.level)); })
.size([width, height]);
d3.json("network.json", function(json) {
force
.nodes(json.nodes)
.links(json.links)
.start();
var link = svg.selectAll(".link")
.data(json.links)
.enter().append("line")
.attr("class", "link");
var node = svg.selectAll(".node")
.data(json.nodes)
.enter().append("g")
.attr("class", "node")
.call(force.drag);
// node.append("circle")
// .attr("r", function(d) { return d.radius; })
// .style("fill", function(d) { return d.fill; });
node.append("image")
.attr("xlink:href", function(d) { return "images/" + d.logo; })
.attr("x", function(d) { return 0 - (d.width / 2); })
.attr("y", function(d) { return 0 - (d.height / 2); })
.attr("width", function(d) { return d.width; })
.attr("height", function(d) { return d.height; })
.on("click", function(d) { window.location = d.url; });
// node.append("text")
// .attr("dx", 12)
// .attr("dy", ".35em")
// .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("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
});
});
</script>