-
Notifications
You must be signed in to change notification settings - Fork 1
/
index_2.html
104 lines (88 loc) · 2.94 KB
/
index_2.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Atec Courses</title>
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var w = 2000,
h = 2000,
r = 10;
// function x(d, i) {
// if(d.number.toString().substring(0,1) == 2) { return 100; }
// else if(d.number.toString().substring(0,1) == 3) { return 200; }
// else if(d.number.toString().substring(0,1) == 4) { return 300; }
// };
// function y(d, i) { return i * 70 + 50 };
var svg = d3.select("body").append("svg")
.attr("width", w)
.attr("height", h);
d3.csv("atec_courses.csv", function(classes) {
var prereqs = classes.filter(function(d){return d.prereq});
function x(d, i) { return d.number.toString().substring(0, 2)*10 };
function y(d, i) { return (d.number.toString().substring(2, 4)*10 + i*h)/classes.length };
// function xTarget(d) { return d.prereq.toString().substring(0, 2)*10 };
// function yTarget(d) { return d.prereq.toString().substring(2, 4)*3 + 30};
var group = svg.selectAll("g")
.data(classes)
.enter()
.append("g");
var cirlces = group.selectAll("circle")
.append("circle")
.attr({
"cx": x,
"cy": y,
"r": r,
"fill": "steelblue",
"stroke": "none",
"id": function(d){return d.number;}
});
// .property("__data__", function(d) { return d + append("hey: you suck") }); <-- sets custom data!
var titles = group.selectAll("text.title")
.append("text")
.text(function(d) { return d.prefix + " " + d.number } )
.attr({
"transform": "translate(10, 0)",
"x": x,
"y": y,
"font-family": "sans-serif",
"font-size": 9,
"fill": "black",
"class": "title"
});
var descriptions = group.selectAll("textarea.description")
.append("textarea")
.text(function(d) { return d.description } )
.attr({
"x": x,
"y": y,
"width": 175,
"transform": "translate(10,10)",
"font-family": "sans-serif",
"font-size": 9,
"fill": "black",
"class": "description"
});
var diagonal = d3.svg.diagonal()
/* This just seems easier. you would need to know the position of i when the original object was generated in order to re create the position mathematically. So i'm just pulling cx and cy from the dom directly.*/
.source( function(d, i) {return {
x: document.getElementById(d.number.substring(0, 4)).getAttribute("cx")*1,
y: document.getElementById(d.number.substring(0, 4)).getAttribute("cy")*1 } } )
.target( function(d, i) { return {
x: document.getElementById(d.prereq.substring(5, 9)).getAttribute("cx")*1,
y: document.getElementById(d.prereq.substring(5, 9)).getAttribute("cy")*1} } );
var lines = group.selectAll("path")
.data(prereqs)
.enter()
.append("path")
.attr({
fill: "none",
stroke: "lightblue",
d: diagonal
})
})
</script>
</body>
</html>