Skip to content

Instantly share code, notes, and snippets.

@saraquigley
Created November 20, 2014 21:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save saraquigley/eb9cddd11657887e1e0d to your computer and use it in GitHub Desktop.
Save saraquigley/eb9cddd11657887e1e0d to your computer and use it in GitHub Desktop.
Curriculum Exploration
d3.tip=function(){function t(t){v=d(t),w=v.createSVGPoint(),document.body.appendChild(g)}function e(){return"n"}function n(){return[0,0]}function r(){return" "}function o(){var t=y();return{top:t.n.y-g.offsetHeight,left:t.n.x-g.offsetWidth/2}}function s(){var t=y();return{top:t.s.y,left:t.s.x-g.offsetWidth/2}}function u(){var t=y();return{top:t.e.y-g.offsetHeight/2,left:t.e.x}}function f(){var t=y();return{top:t.w.y-g.offsetHeight/2,left:t.w.x-g.offsetWidth}}function l(){var t=y();return{top:t.nw.y-g.offsetHeight,left:t.nw.x-g.offsetWidth}}function i(){var t=y();return{top:t.ne.y-g.offsetHeight,left:t.ne.x}}function a(){var t=y();return{top:t.sw.y,left:t.sw.x-g.offsetWidth}}function c(){var t=y();return{top:t.se.y,left:t.e.x}}function m(){var t=document.createElement("div");return t.style.position="absolute",t.style.display="none",t.style.boxSizing="border-box",t}function d(t){return t=t.node(),"svg"==t.tagName.toLowerCase()?t:t.ownerSVGElement}function y(){var t=d3.event.target,e={},n=t.getScreenCTM(),r=t.getBBox(),o=r.width,s=r.height,u=r.x,f=r.y,l=document.body.scrollTop,i=document.body.scrollLeft;return document.documentElement&&document.documentElement.scrollTop&&(l=document.documentElement.scrollTop,i=document.documentElement.scrollLeft),w.x=u+i,w.y=f+l,e.nw=w.matrixTransform(n),w.x+=o,e.ne=w.matrixTransform(n),w.y+=s,e.se=w.matrixTransform(n),w.x-=o,e.sw=w.matrixTransform(n),w.y-=s/2,e.w=w.matrixTransform(n),w.x+=o,e.e=w.matrixTransform(n),w.x-=o/2,w.y-=s/2,e.n=w.matrixTransform(n),w.y+=s,e.s=w.matrixTransform(n),e}var p=e,h=n,x=r,g=m(),v=null,w=null;t.show=function(){var e,n=x.apply(this,arguments),r=h.apply(this,arguments),o=p.apply(this,arguments),s=d3.select(g),u=0;for(s.html(n).style("display","block");u--;)s.classed(b[u],!1);return e=T.get(o).apply(this),s.classed(o,!0).style({top:e.top+r[0]+"px",left:e.left+r[1]+"px"}),t},t.hide=function(){return g.style.display="none",g.innerHTML="",t},t.attr=function(e,n){return arguments.length<2?d3.select(g).attr(e):(d3.select(g).attr(e,n),t)},t.style=function(e,n){return arguments.length<2?d3.select(g).style(e):(d3.select(g).style(e,n),t)},t.direction=function(e){return arguments.length?(p=null==e?e:d3.functor(e),t):p},t.offset=function(e){return arguments.length?(h=null==e?e:d3.functor(e),t):h},t.html=function(e){return arguments.length?(x=null==e?e:d3.functor(e),t):x};var T=d3.map({n:o,s:s,e:u,w:f,nw:l,ne:i,sw:a,se:c}),b=T.keys();return t};
Graduating-Year Headcount Major Stat2 Stat-20 Stat-21 Stat-N21 Stat-W21 Stat-133 Stat-LD-Other Stat-UD-Other Stat-Grad-Other CS-10 CS-W10 CS-61A CS-61AS CS-61B-BL CS-LD-Other CS-UD-Other CS-Grad-Other
2013-14 11 African American Studies 3 0 2 0 0 0 2 0 0 0 0 0 0 0 0 0 0
2013-14 1 African American Studies - Plan A: Social Sciences Concentration 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 102 American Studies 15 2 4 0 0 0 9 0 0 0 0 0 0 0 3 0 0
2013-14 164 Anthropology 18 3 3 1 1 0 1 1 0 2 0 3 1 1 3 2 0
2013-14 158 Applied Mathematics 5 14 24 3 5 26 12 117 5 7 0 34 3 29 43 32 7
2013-14 136 Architecture 7 2 4 0 0 0 0 1 0 5 0 4 2 2 7 10 1
2013-14 58 Art Practice 4 1 2 0 0 0 0 1 0 1 0 3 0 1 4 6 0
2013-14 12 Asian American and Asian Diaspora Studies 3 1 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0
2013-14 1 Asian American Studies 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 4 Asian Studies 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 8 Asian Studies - Area 1: China 1 0 1 0 0 0 0 0 0 1 0 2 0 1 1 0 0
2013-14 2 Asian Studies - Area 2: Japan 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 33 Astrophysics 2 0 0 0 0 1 0 4 0 0 0 2 0 1 3 4 0
2013-14 99 Bioengineering 2 4 0 0 2 2 0 14 0 0 0 20 0 21 17 14 2
2013-14 1 Biological Sciences 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 332 Business Administration 5 61 121 24 56 9 13 28 0 15 1 22 3 14 30 24 5
2013-14 2 Celtic Studies 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 59 Chemical Biology 8 4 0 0 1 1 0 11 0 2 1 3 0 3 3 5 1
2013-14 124 Chemical Engineering 5 0 1 0 1 2 1 2 0 3 0 6 0 6 18 5 1
2013-14 51 Chemistry 3 1 0 0 1 1 0 7 0 1 1 6 2 2 5 4 0
2013-14 19 Chicano Studies 5 2 2 0 0 0 2 0 0 0 0 0 0 0 0 0 0
2013-14 11 Chinese Language 0 1 2 0 1 0 0 0 0 0 0 0 0 0 0 1 0
2013-14 91 Civil Engineering 0 0 0 0 0 0 0 2 0 0 0 2 0 5 9 2 0
2013-14 12 Classical Civilization 4 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0
2013-14 5 Classical Languages 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 134 Cognitive Science 23 5 11 1 4 2 0 7 0 20 0 75 7 43 72 45 5
2013-14 21 Comparative Literature 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
2013-14 218 Computer Science 4 21 20 3 6 12 4 43 1 21 0 195 8 186 218 218 36
2013-14 90 Conservation and Resource Studies 18 9 2 0 1 0 1 6 0 2 0 3 0 1 3 4 0
2013-14 10 Dance and Performance Studies 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 32 Development Studies 3 3 5 0 1 0 0 1 0 0 0 1 0 0 1 0 0
2013-14 1 Dutch Studies 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 544 Economics 14 201 246 14 50 57 19 156 5 34 1 47 4 28 55 40 2
2013-14 407 Electrical Engineering and Computer Sciences 5 7 4 1 6 5 6 27 4 15 0 380 2 340 407 394 106
2013-14 1 Energy Engineering 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0
2013-14 6 Engineering Mathematics and Statistics 0 0 1 0 0 1 0 5 1 0 0 3 0 3 4 3 3
2013-14 20 Engineering Physics 0 0 0 0 0 0 0 1 0 1 0 5 0 5 7 6 0
2013-14 325 English 32 4 8 2 2 0 1 9 0 3 0 7 1 1 10 8 0
2013-14 126 Environmental Economics and Policy 1 58 51 7 12 6 2 30 0 2 1 7 0 4 12 8 1
2013-14 6 Environmental Engineering Science 0 0 0 0 0 1 0 2 0 0 0 0 0 0 0 0 0
2013-14 52 Environmental Sciences 2 0 2 0 0 0 0 41 1 2 0 1 0 0 0 3 1
2013-14 2 EPS - Atmospheric Science 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 13 EPS - Environmental Earth Science 3 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 0
2013-14 8 EPS - Geology 0 0 0 0 0 0 0 0 0 2 0 0 0 0 1 0 0
2013-14 13 EPS - Geophysics 0 0 0 0 0 0 0 0 0 1 0 3 0 0 0 0 0
2013-14 14 EPS - Marine Science 2 0 0 0 0 0 0 9 0 0 0 1 0 0 0 0 0
2013-14 5 EPS - Planetary Science 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
2013-14 38 Ethnic Studies 5 2 1 0 0 0 1 0 0 0 0 1 0 0 2 0 0
2013-14 69 Film 7 0 1 0 0 0 0 1 0 2 1 4 0 2 6 5 0
2013-14 13 Forestry and Natural Resources 7 2 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
2013-14 35 French 6 1 3 0 3 1 1 2 0 1 1 0 0 0 0 1 0
2013-14 30 Gender and Womens Studies 5 2 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0
2013-14 17 Genetics and Plant Biology 7 1 0 0 0 0 0 2 0 0 0 0 0 0 1 0 0
2013-14 55 Geography 11 4 3 0 0 0 1 1 0 2 0 2 1 0 1 1 0
2013-14 16 German 1 2 2 0 0 0 1 0 0 1 0 0 0 0 0 0 0
2013-14 154 History 24 3 11 0 2 0 2 2 0 5 0 3 0 2 3 5 0
2013-14 60 History of Art 2 3 2 0 0 0 0 4 0 0 0 0 0 0 0 3 0
2013-14 47 Industrial Engineering and Operations Research 0 1 3 0 0 0 2 16 1 0 0 9 0 9 25 3 0
2013-14 417 Integrative Biology 156 14 4 5 2 0 2 28 0 7 1 5 1 3 20 14 0
2013-14 164 Interdisciplinary Studies 20 11 27 4 8 0 1 7 1 4 0 5 1 2 8 10 0
2013-14 10 Italian Studies 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 21 Japanese Language 0 1 1 1 0 0 1 2 0 1 0 3 0 2 2 2 0
2013-14 10 Joint Bioengineering/Materials Science and Engineering 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0
2013-14 9 Joint Chemical Engineering/Materials Science and Engineering 0 0 0 0 0 0 0 0 0 0 0 1 0 2 2 0 0
2013-14 4 Joint Electrical Eng and Computer Sciences/Materials Science and Eng 0 0 0 0 0 0 0 2 0 0 0 2 0 4 4 2 0
2013-14 1 Joint Electrical Eng and Computer Sciences/Nuclear Engineering 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0
2013-14 9 Joint Materials Science and Engineering/Mechanical Engineering 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 1 Joint Materials Science and Engineering/Nuclear Engineering 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
2013-14 6 Joint Mechanical Engineering/Nuclear Engineering 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0
2013-14 20 Landscape Architecture 2 0 0 0 0 0 0 0 0 1 0 0 0 0 2 0 0
2013-14 1 Latin 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 6 Latin American Studies 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 151 Legal Studies 51 6 20 4 3 1 3 4 0 2 0 6 1 3 8 2 0
2013-14 62 Linguistics 7 1 3 1 0 0 1 2 0 1 0 6 1 4 7 4 0
2013-14 3 Mass Communications 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 17 Materials Science and Engineering 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0
2013-14 99 Mathematics 1 19 7 1 0 14 0 43 8 0 0 28 2 22 33 24 5
2013-14 66 MCB, Plan 1, Emphasis 1: Biochemistry and Molecular Biology 14 4 2 0 0 2 1 18 0 3 0 9 0 5 8 4 0
2013-14 55 MCB, Plan 1, Emphasis 2: Genetics 14 0 3 1 0 2 1 20 0 2 1 1 0 0 4 1 0
2013-14 93 MCB, Plan 1, Emphasis 3: Immunology 30 1 3 1 1 4 1 10 0 4 0 4 0 0 6 1 0
2013-14 98 MCB, Plan 2, Emphasis 2: Cell and Developmental Biology 32 2 4 0 1 0 1 18 0 2 0 0 0 0 1 1 0
2013-14 112 MCB, Plan 2, Emphasis 3: Neurobiology 42 4 5 1 0 0 0 20 0 3 0 6 1 4 9 3 1
2013-14 150 Mechanical Engineering 0 8 2 0 0 2 2 8 1 1 0 7 0 15 24 9 2
2013-14 198 Media Studies 26 9 17 4 6 1 2 2 0 6 0 4 0 3 9 14 0
2013-14 29 Microbial Biology 13 2 3 0 1 0 0 3 0 2 0 2 0 3 2 1 0
2013-14 2 Middle Eastern Studies 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 93 Molecular Environmental Biology 27 1 6 0 1 0 0 13 0 1 0 1 0 0 2 1 0
2013-14 43 Molecular Toxicology 5 0 1 0 1 0 0 37 0 1 0 1 0 0 1 0 0
2013-14 37 Music 3 2 0 1 0 0 0 1 0 0 0 3 0 2 3 0 0
2013-14 4 Native American Studies 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 4 Near Eastern Studies - Near Eastern Civilizations 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 6 Near Eastern Studies - Near Eastern Languages and Literatures 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 7 Nuclear Engineering 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
2013-14 19 Nutritional Science - Dietetics 6 0 0 0 0 0 0 1 0 0 0 2 0 0 0 2 0
2013-14 45 Nutritional Science - Physiology and Metabolism 34 0 2 0 1 0 0 1 0 0 0 1 0 0 0 0 0
2013-14 12 Operations Research and Management Science 0 3 6 0 1 0 0 7 0 0 0 3 1 3 4 2 1
2013-14 57 Peace and Conflict Studies 7 0 0 0 0 0 0 4 0 3 0 1 0 0 0 0 0
2013-14 88 Philosophy 2 3 2 0 0 0 0 5 0 4 1 4 1 3 4 1 0
2013-14 106 Physics 6 2 0 0 0 1 0 5 0 0 0 17 1 15 34 14 2
2013-14 271 Political Economy 71 67 79 14 17 1 7 16 0 9 0 6 0 3 11 10 0
2013-14 3 Political Economy of Industrial Societies 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 427 Political Science 46 14 15 2 6 2 1 20 0 7 0 5 2 2 6 8 0
2013-14 336 Psychology 98 12 13 4 8 5 2 14 0 5 0 8 1 1 13 8 0
2013-14 170 Public Health 22 6 6 1 4 0 1 18 0 1 0 3 0 2 6 2 0
2013-14 8 Religious Studies 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 1 Resource Management 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 111 Rhetoric 13 3 6 2 3 0 3 5 0 4 0 2 0 1 1 4 1
2013-14 2 Scandinavian 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 10 Slavic Languages and Literatures 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 1 Social Sciences Field Major 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 116 Social Welfare 55 8 5 0 1 0 10 0 0 4 0 2 0 0 3 3 0
2013-14 62 Society and Environment 14 2 2 0 1 1 2 1 0 1 0 0 0 0 2 3 1
2013-14 213 Sociology 82 10 9 0 2 0 7 5 0 3 0 1 0 1 5 5 0
2013-14 9 South and Southeast Asian Studies 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0
2013-14 1 Spanish - Option B: Luso-Brazilian Language and Literature 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 2 Spanish - Option C, Plan 1: Iberian Languages and Literatures 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 9 Spanish - Option C, Plan 2: Latin-American Languages and Lit 2 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 21 Spanish - Option D: Hispanic Languages and Bilingual Issues 4 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0
2013-14 19 Spanish - Spanish Language and Literature 2 2 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0
2013-14 167 Statistics 4 29 60 2 6 165 16 167 14 5 1 29 2 18 32 17 2
2013-14 46 Theater and Performance Studies 8 4 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2013-14 36 Urban Studies 10 4 4 2 1 0 1 1 0 0 0 0 0 0 0 2 0
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Data Science Curriculum Exploration</title>
</head>
<style type="text/css">
table {
margin-top: 10px;
border-collapse: collapse;
font: 10px sans-serif;
width: 720px;
}
th {
font-weight: normal;
text-align: right;
padding-right: 6px;
min-width: 43px;
}
thead td {
cursor: s-resize;
}
tbody tr:first-child td {
padding-top: 2px;
}
tbody td {
padding: 0;
}
tbody rect {
fill: steelblue;
}
tbody tr:hover rect {
fill: orange;
}
.tophead {
font: 400 26px "Helvetica Neue";
color: #525252;
}
.hint {
padding-left: 20px;
font: 200 18px "Helvetica Neue";
color: #525252;
}
/* testing out d3 tooltip */
.d3-tip {
line-height: 1;
font-weight: normal;
padding: 12px;
background: rgba(0, 0, 0, 0.8);
color: #fff;
border-radius: 8px;
}
/* Creates a small triangle extender for the tooltip */
.d3-tip:after {
box-sizing: border-box;
display: inline;
font-size: 10px;
width: 100%;
line-height: 1;
color: rgba(0, 0, 0, 0.8);
content: "\25BC";
position: absolute;
text-align: center;
}
/* Style northward tooltips differently */
.d3-tip.n:after {
margin: -1px 0 0 0;
top: 100%;
left: 0;
}
</style>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" src="d3.tip.min.js"></script>
<script>
// tooltips for bar chart
var barTip = d3.tip()
.attr('class', 'd3-tip')
.offset([-10, 0])
.html(function (d) {
return d + " students";
});
d3.csv("degree-earners.csv", function(csv) {
var courses = d3.keys(csv[0]).filter(function(key) {
return key != "Major" && key != "Graduating-Year";
});
d3.selectAll("thead td").data(courses).on("click", function(k) {
tr.sort(function(a, b) { return (b[k]) - (a[k]); });
});
var tr = d3.select("tbody").selectAll("tr")
.data(csv)
.enter().append("tr");
var x = d3.scale.linear().domain([0,(d3.max(csv, function(d) {return +d.Headcount;}) + 10)]).range([0,71]);
tr.append("th")
.attr("width", 200)
.text(function(d) { return d.Major; });
tr.selectAll("td")
.data(function(d) { return courses.map(function(k) { return d[k]; }); })
.enter().append("td").append("svg")
.attr("width", 71)
.attr("height", 12)
.append("rect")
.attr("class", "bar")
.attr("height", 12)
.attr("width", function(d) {
return x(+d);
});
d3.selectAll(".bar").call(barTip);
d3.selectAll(".bar").on('mouseover', barTip.show)
.on('mouseout', barTip.hide);
});
</script>
<body>
<span class="tophead">Curriculum Exploration</span><span class="hint">(November 20, 2014) </span><span class="hint">hint: click a column header to sort on a column</span>
<table>
<thead>
<tr>
<th>Major</th>
<td>Headcount</td>
<td>Stat 2</td>
<td>Stat 20</td>
<td>Stat 21</td>
<td>Stat N21 </td>
<td>Stat W21 </td>
<td>Stat 133 </td>
<td>Stat LD Other</td>
<td>Stat UD Other</td>
<td>Stat Grad Other</td>
<td>CS 10</td>
<td>CS W10 </td>
<td>CS 61A </td>
<td>CS 61AS</td>
<td>CS 61B_BL</td>
<td>CS LD Other</td>
<td>CS UD Other</td>
<td>CS Grad Other</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment