-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene3.html
More file actions
145 lines (131 loc) · 4.9 KB
/
scene3.html
File metadata and controls
145 lines (131 loc) · 4.9 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
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
<html>
<script src='https://d3js.org/d3.v5.min.js'></script>
<script src="https://rawgit.com/susielu/d3-annotation/master/d3-annotation.min.js"></script>
<script src="format_utils.js"></script>
<script src="data_utils.js"></script>
<head>
<link rel="stylesheet" href="scene.css">
</head>
<body onload='init()'>
<h1>Are Americans getting more educated?</h1>
<br><br><br>
<div class="center">
<p> And for <strong>Social sciences and history (SS&H)</strong>, the number has been steady over the years.
<br>This means the percentage of graduates is now much lower than before!</p>
</div>
<br><br>
<table class="center">
<tr>
<td>
<p>SS&H degrees</p>
<svg id="social_graph"></svg>
</td>
<td>
<p>Fraction relative to all degrees</p>
<svg id="social_graph_fraction"></svg>
</td>
</tr>
</table>
<div class="center">
<a href="scene2.html" class="previous">« Back</a>
<a href="scene4.html" class="next">Continue »</a>
</div>
<br><br><br><br>
</body>
<footer>SOURCE: U.S. Department of Education, National Center for Education Statistics, Higher Education General Information Survey (HEGIS), "Degrees and Other Formal Awards Conferred" surveys, 1970-71 through 1985-86; Integrated Postsecondary Education Data System (IPEDS), "Completions Survey" (IPEDS-C:91-99); and IPEDS Fall 2000 through Fall 2020, Completions component. (The data was prepared September 2021.)</footer>
<script>
function getData(data, field) {
let vals = [];
for (let i = 0; i < data.length; i++) {
let val = 0;
for (let key in data[i]) {
if (key == field) {
val = parseInt(data[i][key])
} else if (key == 'Year') {
year = data[i][key];
}
}
vals.push({'Year': year, 'Value': val});
}
return vals;
}
function getRelative(data, sums) {
let relative = [];
for (let i = 0; i < data.length; i++) {
relative.push({'Year': data[i].Year, 'Value': (data[i].Value/sums[i].Value)});
}
return relative;
}
async function init() {
let margin = 60,
width = 500 - 2*margin;
height = 400 - 2*margin;
let svgSsh = getSvgWithMargins("#social_graph", width, height, margin),
svgSshRelative = getSvgWithMargins("#social_graph_fraction", width, height, margin);
data = await d3.csv("https://rm36.github.io/degrees_conferred.csv");
let sums = getSums(data),
dataPerField = getDataPerField(data),
relativePerField = getRelativePerField(dataPerField, sums),
ssh = dataPerField["Social sciences and history"],
sshRelative = relativePerField["Social sciences and history"];
let yearsExtent = d3.extent(data, function(d) { return d.Year; }),
valuesExtent = [0, 180000],
relativeExtent = [0, 0.25];
let xScale = d3.scaleLinear().domain(yearsExtent).range([ 0, width ]);
let years = [1971, 1980, 1990, 2000, 2010, 2020];
formatXAxis(svgSsh, height, xScale, years);
formatXAxis(svgSshRelative, height, xScale, years);
let yScale = d3.scaleLinear().domain(valuesExtent).range([height * 0.8, 0]);
let yRelativeScale = d3.scaleLinear().domain(relativeExtent).range([height * 0.8, 0]);
formatYAxis(svgSsh, width, yScale, valuesExtent[1]);
formatYAxisPercent(svgSshRelative, width, yRelativeScale);
let valuesArea = getArea(xScale, yScale, height),
relativeArea = getArea(xScale, yRelativeScale, height);
plotArea(svgSsh, ssh, valuesArea, "#2ca02c");
plotArea(svgSshRelative, sshRelative, relativeArea, "#2ca02c");
let bottomAxisLabel = {"x":width/2, "y": height-20};
addHorizontalAxis(svgSsh, bottomAxisLabel, "Year");
addHorizontalAxis(svgSshRelative, bottomAxisLabel, "Year");
let leftAxisLabel = {"x": -50, "y": height/2 - 130}
addLeftAxis(svgSsh, leftAxisLabel, "Number of degrees (thousands)");
addLeftAxis(svgSshRelative, leftAxisLabel, "Fraction of degrees");
const sshAnnotations = [
{
note: {
title: "1971",
label: "18.5% of degrees were SS&H majors",
bgPadding: 0,
align: "left",
wrapSplitter: /\n/,
},
x: xScale(1971),
y: yRelativeScale(0.185),
dy: -10,
dx: 120,
color: "#bb0000",
connector: { end: "dot" },
type: d3.annotationCalloutElbow,
},
{
note: {
title: "2020",
label: "8% of degrees are SS&H majors",
bgPadding: 0,
align: "left",
wrapSplitter: /\n/,
},
x: xScale(2020),
y: yRelativeScale(0.08),
dy: -50,
dx: -300,
color: "#bb0000",
connector: { end: "dot" },
type: d3.annotationCalloutElbow,
},
];
makeAnnotationsSsh = d3.annotation().annotations(sshAnnotations);
svgSshRelative.append("g").call(makeAnnotationsSsh);
}
</script>
</body>
</html>