-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
161 lines (131 loc) · 3.6 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font-family: "Source Sans Pro","Helvetica Neue",Helvetica,Arial,sans-serif;
}
.link {
fill: none;
stroke: #666;
stroke-width: 1.5px;
}
.node circle {
fill: #ccc;
stroke: #fff;
stroke-width: 1.5px;
}
text {
font: 10px sans-serif;
pointer-events: none;
}
svg {
display: block;
text-align: center;
vertical-align: middle;
margin: auto;
}
#show-class {
display: block;
text-align: center;
vertical-align: middle;
margin: auto;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var nodes = {};
// get the data
d3.csv("data/data.csv", function(error, links) {
var nodes = {};
// Compute the distinct nodes from the links.
links.forEach(function(link) {
link.source = nodes[link.source] ||
(nodes[link.source] = {name: link.source, t: link.class});
link.target = nodes[link.target] ||
(nodes[link.target] = {name: link.target, t: link.class});
link.value = +link.value;
link.class = link.class;
});
var width = 1000,
height = 1700;
var force = d3.layout.force()
.size([width, height])
.linkDistance(50)
.charge(-150)
.on("tick", tick);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.append("svg:defs").selectAll("marker")
.data(["end"]) // Different link/path types can be defined here
.enter().append("svg:marker") // This section adds in the arrows
.attr("id", String)
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "0 -5 10 10")
.attr("refX", 11)
.attr("refY", 0)
.attr("markerWidth", 6)
.attr("markerHeight", 6)
.attr("orient", "auto")
.append("svg:path")
.attr("d", "M 0, -3 L 6, 0 L 0, 3");
force.nodes(d3.values(nodes))
.links(links)
.start();
var link = svg.selectAll(".link")
.data(force.links())
.enter().append("line")
.attr("class", "link")
.style("stroke-width", function(d) { return 2; })
.attr("marker-end", "url(#end)");
var node = svg.selectAll(".node")
.data(force.nodes())
.enter().append("g")
.attr("class", "node")
.on("mouseover", mouseover)
.on("mouseout", mouseout)
.call(force.drag);
node.append("circle")
.attr("r", 6);
node.append("text")
.attr("x", 12)
.attr("dy", ".35em")
.text(function(d) { return d.name; });
function tick(e) {
var k = 10 * e.alpha;
// Push sources up and targets down to form a weak tree.
link
.each(function(d) { d.source.y -= k, d.target.y += k; })
.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 + ")"; });
}
function mouseover() {
d3.select(this).select("circle").transition()
.duration(250)
.attr("r", 10);
console.log(d3.select(this).select("text").datum());
document.getElementById("class-show").value = d3.select(this).select("text").datum().class;
}
function mouseout() {
d3.select(this).select("circle").transition()
.duration(250)
.attr("r", 6);
document.getElementById("class-show").value = "";
}
});
</script>
<br>
<div id="show-class">
<form>
<h1> Course 6 Roadmap </h1>
<br>
<!-- <input id="class-show" type="text" name="classname" value=""> -->
</form>
</div>
</body>
</html>