-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18fconsulting2.html
99 lines (85 loc) · 2.48 KB
/
18fconsulting2.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
90
91
92
93
94
95
96
97
98
99
<!doctype html>
<html><head>
<style>
<!--
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 1.0px;
}
-->
.node {
font: 12px sans-serif;
}
.link {
fill: none;
stroke: lightgray;
stroke-width: 1.0px;
}
.node text {
pointer-events: none;
font: 10px sans-serif;
}
line {
stroke: steelblue;
}
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>
var margin = {top: 40, right: 40, bottom: 40, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var tree = d3.layout.tree()
.size([height, width]);
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.csv("18fconsulting2.csv", function(error, links) {
if (error) throw error;
var nodesByName = {};
// Create nodes for each unique source and target.
links.forEach(function(link) {
var parent = link.source = nodeByName(link.source),
child = link.target = nodeByName(link.target);
if (parent.children) parent.children.push(child);
else parent.children = [child];
});
// Extract the root node and compute the layout.
var nodes = tree.nodes(links[0].source);
// Create the link lines.
svg.selectAll(".link")
.data(links)
.enter().append("path")
.attr("class", "link")
.attr("d", diagonal);
// Create the node circles.
svg.selectAll(".node")
.data(nodes)
.enter().append("circle")
.attr("class", "node circle")
.attr("r", 4.5)
.attr("cx", function(d) { return d.y; })
.attr("cy", function(d) { return d.x; })
.attr("fill", "#fff")
.attr("stroke", "steelblue")
.attr("stroke-width", "1.0px");
svg.selectAll(".node")
.data(nodes)
.enter().append("text")
.attr("dx", 12)
.attr("dy", ".35em")
.attr("pointer-events", "none")
.attr("font", "10px sans-serif")
.text(function(d) {return d.name });
function nodeByName(name) {
return nodesByName[name] || (nodesByName[name] = {name: name});
}
});
</script>
</body></html>