-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
407 lines (333 loc) · 13.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<!DOCTYPE html>
<meta charset="utf-8">
<title>Carleton Career Paths</title>
<style>
@import url(style.css);
#chart {
height: 1000px;
}
.node rect {
cursor: pointer;
fill-opacity: .4;
shape-rendering: crispEdges;
}
.node:hover rect {
fill-opacity: 0.9;
}
.node text {
pointer-events: none;
text-shadow: 0 1px 0 #fff;
}
.link {
fill: none;
stroke-opacity: .3;
}
.link:hover {
stroke-opacity: .5;
}
</style>
<body>
<h1>Carleton College Career Paths</h1>
<h3>Majors on left, job fields on right. Click on a major or career to see only its paths. Click on a path to see more specific careers.</h3>
<p id="careerLink">
<p id="chart">
<p id="majorDescription">
<footer>Note: This graphic does not account for the career paths of alumni who have not provided this data to the College. We are including all career paths we have information about, even when a single individual has moved among two or more fields over the years since they graduated (they will show up twice). Special majors are not included.
</footer>
<footer>
Many thanks to <a href="http://bost.ocks.org/mike" rel="author">Mike Bostock</a>, creator of <a href="http://d3js.org">D3</a> and its <a href="https://github.com/d3/d3-plugins/tree/master/sankey">Sankey plugin</a>.
<aside>August, 2013</aside>
</footer>
<script src="http://d3js.org/d3.v2.min.js?2.9.1"></script>
<script src="sankey.js"></script>
<script>
/* If there are multiple links per career category, the thing after the : should look like
[["sub-career0","link0"], ["sub-career1","link1"], ...]
*/
var careerLinks = {
"Arts/Museums" : "https://apps.carleton.edu/pathways/arts_communication/",
"Business/Finance/Sales" : "https://apps.carleton.edu/pathways/businesses/",
"Communications/Media" : "https://apps.carleton.edu/pathways/arts_communication/",
"Education (Higher Ed)" : "https://apps.carleton.edu/pathways/education/higher_education/",
"Education (Pre K-12)" : "https://apps.carleton.edu/pathways/education/k_12_education/",
"Engineering" : "https://apps.carleton.edu/pathways/engineering/engineering_technology/",
"Environment/Agriculture" : "https://apps.carleton.edu/pathways/environment/",
"Government/Public Service" : "https://apps.carleton.edu/pathways/government_law_activism/government_politics_public_policy/",
"Healthcare" : "https://apps.carleton.edu/pathways/health_wellness/health_professions/",
"Info Systems/Technology/Library" :
[["Tech","https://apps.carleton.edu/pathways/engineering/computers_and_information_systems/"],
["Library Science","https://apps.carleton.edu/pathways/education/library_science/"]],
"Legal Professions" : "https://apps.carleton.edu/pathways/government_law_activism/law_justice/",
"Peacecorps/Americorps/Teach for America" : "https://apps.carleton.edu/pathways/government_law_activism/advocacy_activism_humanrights/",
"Science/Lab Research" : "https://apps.carleton.edu/pathways/health_wellness/health_professions/",
"Social Service/Advocacy" : "https://apps.carleton.edu/pathways/health_wellness/counseling_socialservices/"
}
var majorDescriptions = {
"Area Studies" : "Includes majors: African/African-American Studies, American Studies, Asian Studies, Latin American Studies",
"Art/Art History" : "Includes Studio Art and Art History",
"Classics" : "Includes Classics and Classical Languages",
"Modern Languages" : "Includes majors: French, German, Russian, Spanish",
"Political Science" : "Includes Political Science and International Relations",
"Theater/Dance" : "Includes Dance and Theater Arts",
}
var VIEW_ENTIRE = 0,
VIEW_MAJOR = 1,
VIEW_CAREER = 2;
VIEW_SPECIFIC = 3;
var view = VIEW_ENTIRE;
var margin = {top: 1, right: 1, bottom: 6, left: 1},
// width = 960 - margin.left - margin.right,
width = 880 - margin.left - margin.right,
height = 1000 - margin.top - margin.bottom;
var formatNumber = d3.format(",.0f"),
format = function(d) { return formatNumber(d) + " Students"; },
color = d3.scale.category20();
var chart = d3.select("#chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
var svg = chart.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var sankey = d3.sankey()
.nodeWidth(15)
.nodePadding(10)
.size([width, height]);
var path = sankey.link();
d3.json("data.json", function(allData) {
drawEntire();
function eraseSankey() {
d3.selectAll(".link").remove();
d3.selectAll(".node").remove();
}
function drawOneCareer(node) {
view = VIEW_CAREER;
window.scroll(0,0);
// Changes the space alloted
var newHeight = 30;
var elem = document.getElementById("chart");
elem.style.height = newHeight + "px";
// Reset data
currentData = {"nodes":[], "links":[]};
var targetLinks = d3.select(node).datum().targetLinks;
currentData.nodes.push(targetLinks[0].target);
targetLinks.forEach(function(link) {
currentData.links.push(link);
currentData.nodes.push(link.source);
});
// Delete the previously drawn diagram
eraseSankey();
// Reset the dimensions
sankey
.size([width, newHeight - margin.top - margin.bottom]);
drawNewSankey(10);
var careerName = d3.select(node).datum().name;
var careerLink = careerLinks[careerName]
if (careerLink == undefined) {
document.getElementById("careerLink").innerHTML = "";
}
else {
drawCareerResources();
// document.getElementById("careerLink").innerHTML = "<a href=\"" + careerLink + "\">Link to " + careerName + " on Pathways site</a>";
}
d3.select("body").select("h3").text("Majors on left, job fields on right. Click on a path to see more specific careers. Click on the career or press backspace to go back to the full view.");
}
function drawOneMajor(node) {
view = VIEW_MAJOR;
window.scroll(0,0);
// Changes the space alloted
var newHeight = 300;
var elem = document.getElementById("chart");
elem.style.height = newHeight + "px";
// Reset data, so that it always draws the same thing no matter which view you got there from
currentData = {"nodes":[], "links":[]};
var nodeName = d3.select(node).datum().name;
var newNode;
eraseSankey();
sankey
.nodes(allData[0].nodes)
.links(allData[0].links)
.layout(0);
sankey.nodes().forEach(function(node) {
if (node.name == nodeName) {
newNode = node;
}
});
var sourceLinks = newNode.sourceLinks;
currentData.nodes.push(sourceLinks[0].source);
sourceLinks.forEach(function(link) {
currentData.links.push(link);
currentData.nodes.push(link.target);
});
// Delete the previously drawn diagram
eraseSankey();
// Reset the dimensions
sankey
.size([width, newHeight - margin.top - margin.bottom]);
drawNewSankey(10);
// Add text about which majors fall under this category
var majorText = majorDescriptions[d3.select(node).datum().name]
if (majorText == undefined) {
majorText = ""
}
document.getElementById("majorDescription").innerHTML = majorText;
document.getElementById("careerLink").innerHTML = "";
d3.select("body").select("h3").text("Majors on left, job fields on right. Click on a path to see more specific careers. Click on the major or press backspace to go back to the full view.");
}
function drawMajorToSpecifics(link) {
view = VIEW_SPECIFIC;
window.scroll(0,0);
var newHeight = 300;
currentData = allData[d3.select(link).datum().index];
eraseSankey();
sankey
.size([width, newHeight - margin.top - margin.bottom]);
drawNewSankey(10);
var majorText = majorDescriptions[d3.select(link).datum().source.name]
if (majorText == undefined) {
majorText = ""
}
document.getElementById("majorDescription").innerHTML = majorText;
document.getElementById("careerLink").innerHTML = "";
d3.select("body").select("h3").text("Majors on left, job fields (under " + d3.select(link).datum().target.name + ") on right. Click on the major to see all its broad career paths. Press backspace to go to the full view.");
}
function drawEntire() {
view = VIEW_ENTIRE;
window.scroll(0,0);
eraseSankey();
currentData = allData[0];
sankey
.size([width, height])
drawNewSankey(0);
d3.select("body").select("h3").text("Majors on left, job fields on right. Click on a major or career to see only its paths. Click on a path to see more specific careers.");
}
// Add the links on the right side of each career
function drawCareerResources() {
sankey.nodes().forEach(function(node) {
if (node.x != 0 && careerLinks[node.name] != undefined) {
var firstDiv = document.createElement('div');
var newDiv = document.createElement('div');
var xPos = node.x + sankey.nodeWidth() + 5;
var yPos = node.y;
var height = node.dy;
firstDiv.setAttribute('style', 'position:absolute; margin-top:'+yPos+'px; margin-left:'+xPos+'px; height:'+height+'px; display:table; border:"1px"');
newDiv.setAttribute('style', 'display:table-cell; vertical-align:middle; font-family:"PT Sans",sans-serif;');
var innerhtml = "";
// If there are multiple links per career
if (Object.prototype.toString.call(careerLinks[node.name]) === '[object Array]' && careerLinks[node.name].length > 1) {
innerhtml += "<p style=\"line-height: 50%\">";
for (var i=0; i<careerLinks[node.name].length; i++) {
innerhtml = innerhtml + "<a href=\""+careerLinks[node.name][i][1]+"\" style=\"font-size:10px\">See " + careerLinks[node.name][i][0] + " Pathway</a><br><br>";
}
innerhtml += "</p>";
newDiv.innerHTML = innerhtml;
}
else {
newDiv.innerHTML = "<a href=\""+careerLinks[node.name]+"\" style=\"font-size:10px\">See this Pathway</a>";
}
firstDiv.appendChild(newDiv);
document.getElementById('careerLink').appendChild(firstDiv);
}
});
}
// Should be called after the previous sankey has been erased and after currentData has been updated.
function drawNewSankey(layoutAmount) {
sankey
.nodes(currentData.nodes)
.links(currentData.links);
// Increase the height of the graphic if need be
var newHeight = sankey.layoutTest(1);
var elem = document.getElementById("chart");
elem.style.height = newHeight + "px";
sankey
.size([width, newHeight])
.layout(layoutAmount);
chart.attr("height", newHeight + margin.top + margin.bottom);
var link = svg.append("g").selectAll(".link")
.data(currentData.links)
.enter().append("path")
.attr("class", "link")
.attr("d", path)
.style("stroke-width", function(d) { return Math.max(1, d.dy); })
.style("stroke", function(d) { return d.color = color(d.source.name.replace(/ .*/, "")); })
.sort(function(a, b) { return b.dy - a.dy; })
link.append("title")
.text(function(d) { return d.source.name + " → " + d.target.name + "\n" + format(d.value); });
var node = svg.append("g").selectAll(".node")
.data(currentData.nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
node.append("rect")
.attr("height", function(d) { return d.dy; })
.attr("width", sankey.nodeWidth())
.style("fill", function(d) { return d.color = color(d.name.replace(/ .*/, "")); })
.style("stroke", function(d) { return d3.rgb(d.color).darker(2); })
.append("title")
.text(function(d) { return d.name + "\n" + format(d.value); });
node.append("text")
// Before career resources were added to the right side
// .attr("x", +60)
// .attr("y", function(d) { return d.dy / 2; })
// .attr("dy", ".35em")
// .attr("text-anchor", "end")
// .attr("transform", null)
// .text(function(d) { return d.name; })
// .filter(function(d) { return d.x < width / 2; })
// .attr("x", 6 + sankey.nodeWidth())
// .attr("text-anchor", "start");
.attr("x", -6)
.attr("y", function(d) { return d.dy / 2; })
.attr("dy", ".35em")
.attr("text-anchor", "end")
.attr("transform", null)
.text(function(d) { return d.name; })
.filter(function(d) { return d.x < width / 2; })
.attr("x", 6 + sankey.nodeWidth())
.attr("text-anchor", "start");
node
.on("click", function() {
if (view == VIEW_ENTIRE) {
// Left node
if (d3.select(this).datum().x == 0) {
drawOneMajor(this);
}
// Right node
else {
drawOneCareer(this);
}
}
else if (view == VIEW_MAJOR) {
if (d3.select(this).datum().x == 0) {
drawEntire();
}
}
else if (view == VIEW_CAREER) {
if (d3.select(this).datum().x != 0) {
drawEntire();
}
}
else if (view == VIEW_SPECIFIC) {
if (d3.select(this).datum().x == 0) {
drawOneMajor(this);
}
}
})
link
.on("click", function() {
if (view != VIEW_SPECIFIC) {
drawMajorToSpecifics(this);
}
})
document.getElementById("majorDescription").innerHTML="";
document.getElementById("careerLink").innerHTML="";
drawCareerResources();
}
document.onkeydown = function(event) {
event = event || window.event;
var keycode = event.charCode || event.keyCode;
if (keycode == 8 || keycode == 46) {
drawEntire();
return false;
}
}
});
</script>