forked from cs573-19s/lab-slopechart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
106 lines (104 loc) · 3.83 KB
/
Copy pathindex.html
File metadata and controls
106 lines (104 loc) · 3.83 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
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
<body>
<div id="section1">
</div>
</body>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
console.log(d3); // test if d3 is loaded
// Insert slopegraph here
var width = 1280;
var height = 720;
var svg1 = d3.select("#section1")
.append("svg")
.attr("width", width)
.attr("height", height);
d3.csv('wpi-cs-grads.csv').then(function(d) {
console.log(d);
var xScale = d3.scaleLinear()
.domain( [0, 4] )
.range( [60, 700] );
var xScaleText = d3.scaleLinear()
.domain( [0, 4] )
.range( [10, 650] );
var yScale = d3.scaleLinear()
.domain( [0, d3.max(d, function(row) { return parseInt(row.Total); })] )
.range( [550, 50] );
for(i = 0; i < d.length; i++){
svg1.append("line")
.attr("x1", xScale(i))
.attr("y1", 50)
.attr("x2", xScale(i))
.attr("y2", 550)
.attr("stroke-width", 2)
.style("opacity", .4)
.attr("stroke", "black");
svg1.append("text")
.attr("x", xScaleText(i))
.attr("y", 25)
.attr("font-family", "sans-serif")
.attr("font-size", "20px")
.style("opacity", .8)
.attr("fill", "black")
.text(d[i].Timespan);
}
console.log(d.length)
for(n = 1; n < d.length; n++){
createLines(xScale(n-1), yScale(parseInt(d[n-1].Total)), xScale(n), yScale(parseInt(d[n].Total)), "blue");
createLines(xScale(n-1), yScale(parseInt(d[n-1].FT)), xScale(n), yScale(parseInt(d[n].FT)), "orange");
createLines(xScale(n-1), yScale(parseInt(d[n-1].PT)), xScale(n), yScale(parseInt(d[n].PT)), "red");
createLines(xScale(n-1), yScale(parseInt(d[n-1].MS)), xScale(n), yScale(parseInt(d[n].MS)), "green");
createLines(xScale(n-1), yScale(parseInt(d[n-1].PhD)), xScale(n), yScale(parseInt(d[n].PhD)), "purple");
createCircle(xScale(n-1), yScale(parseInt(d[n-1].Total)), "blue");
createCircle(xScale(n-1), yScale(parseInt(d[n-1].FT)), "orange");
createCircle(xScale(n-1), yScale(parseInt(d[n-1].PT)), "red");
createCircle(xScale(n-1), yScale(parseInt(d[n-1].MS)), "green");
createCircle(xScale(n-1), yScale(parseInt(d[n-1].PhD)), "purple");
if(n == 1){
createText(10, yScale(parseInt(d[n-1].Total)), "Total");
createText(10, yScale(parseInt(d[n-1].FT)), "FT");
createText(10, yScale(parseInt(d[n-1].PT)), "PT");
createText(10, yScale(parseInt(d[n-1].MS)), "MS");
createText(10, yScale(parseInt(d[n-1].PhD)), "PhD");
}
if(n == 4){
createText(xScale(n) + 10, yScale(parseInt(d[n].Total)), "Total");
createText(xScale(n) + 10, yScale(parseInt(d[n].FT)), "FT");
createText(xScale(n) + 10, yScale(parseInt(d[n].PT)), "PT");
createText(xScale(n) + 10, yScale(parseInt(d[n].MS)), "MS");
createText(xScale(n) + 10, yScale(parseInt(d[n].PhD)), "PhD");
createCircle(xScale(n), yScale(parseInt(d[n].Total)), "blue");
createCircle(xScale(n), yScale(parseInt(d[n].FT)), "orange");
createCircle(xScale(n), yScale(parseInt(d[n].PT)), "red");
createCircle(xScale(n), yScale(parseInt(d[n].MS)), "green");
createCircle(xScale(n), yScale(parseInt(d[n].PhD)), "purple");
}
}
})
function createLines(x1, y1, x2, y2, color){
svg1.append("line")
.attr("x1", x1)
.attr("y1", y1)
.attr("x2", x2)
.attr("y2", y2)
.attr("stroke-width", 2)
.style("opacity", .4)
.attr("stroke", color);
}
function createText(x, y, text){
svg1.append("text")
.attr("x", x)
.attr("y", y)
.attr("font-family", "sans-serif")
.attr("font-size", "20px")
.style("opacity", .8)
.attr("fill", "black")
.text(text);
}
function createCircle(x, y, color){
svg1.append("circle")
.attr("r", 5)
.attr("cx", x)
.attr("cy", y)
.attr("fill", color)
}
</script>