/
index.html
275 lines (231 loc) · 7.33 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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
#buttonHolder {
padding-left: 17%;
}
.option {
display: inline-block;
width: 10%;
}
input {
width: 91%;
}
.counties {
fill: #fff;
}
.states {
fill: none;
stroke: #fff;
stroke-linejoin: round;
}
/*.q0-9 { fill:rgb(0,0,0); }
.p0-9 { fill:rgb(200,107,200); }*/
.black { fill:rgb(0,0,0); }
.q0-9 { fill:rgb(247,251,255); }
.q1-9 { fill:rgb(222,235,247); }
.q2-9 { fill:rgb(198,219,239); }
.q3-9 { fill:rgb(158,202,225); }
.q4-9 { fill:rgb(107,174,214); }
.q5-9 { fill:rgb(66,146,198); }
.q6-9 { fill:rgb(33,113,181); }
.q7-9 { fill:rgb(8,81,156); }
.q8-9 { fill:rgb(8,48,107); }
.p0-9 { fill:rgb(107,255,247); }
.p1-9 { fill:rgb(156,247,222); }
.p2-9 { fill:rgb(181,239,198); }
.p3-9 { fill:rgb(198,225,158); }
.p4-9 { fill:rgb(214,214,255); }
.p5-9 { fill:rgb(225,198,66); }
.p6-9 { fill:rgb(239,181,33); }
.p7-9 { fill:rgb(247,156,28); }
.p8-9 { fill:rgb(255,107,18); }
svg {
display: none;
}
</style>
<head>
<!-- <script src="http://d3js.org/d3.v3.min.js"></script> -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400' rel='stylesheet' type='text/css'>
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
</head>
<body style="margin:auto; width:1000px">
<h1 style="font-family:Source Sans Pro;font-weight:300;font-size:475%">
North Carolina Education Visualized
</h1>
<hr>
<p style="font-family:Source Sans Pro;font-size:150%">
We've compared
<strong> student achievement per pupil expenditure </strong>
across the school districts of North Carolina.
</p>
<!-- <div style="height:100px;"> -->
<svg width="960" height="100">
<circle cx="20" cy="25" r="10" fill="orange"></circle>
<text x="35" y="32.5" font-family="Source Sans Pro" font-size="18px" fill="black"> The orange scale signifies the upper socio-economic portion of North Carolina's counties.
</text>
<circle cx="20" cy="55" r="10" fill="blue"></circle>
<text x="35" y="62.5" font-family="Source Sans Pro" font-size="18px" fill="black"> The blue scale signifies the lower socio-economic portion of North Carolina's counties.
</text>
</svg>
<!-- </div> -->
<div id="buttonHolder">
<div id="firstbutton" class="option">
<input name="updateButton"
type="button"
class="btn btn-default" aria-label="Center Align"
value="2006"
onclick="showYear(2006)" />
</div>
<div class="option">
<input name="updateButton"
type="button"
class="btn btn-default" aria-label="Center Align"
value="2007"
onclick="showYear(2007)" />
</div>
<div class="option">
<input name="updateButton"
type="button"
class="btn btn-default" aria-label="Center Align"
value="2008"
onclick="showYear(2008)" />
</div>
<div class="option">
<input name="updateButton"
type="button"
class="btn btn-default" aria-label="Center Align"
value="2009"
onclick="showYear(2009)" />
</div>
<div class="option">
<input name="updateButton"
type="button"
class="btn btn-default" aria-label="Center Align"
value="2010"
onclick="showYear(2010)" />
</div>
<div class="option">
<input name="updateButton"
type="button"
class="btn btn-default" aria-label="Center Align"
value="2011"
onclick="showYear(2011)" />
</div>
<div class="option">
<input name="updateButton"
type="button"
class="btn btn-default" aria-label="Center Align"
value="2012"
onclick="showYear(2012)" />
</div>
</div>
<script>
var width = 960,
height = 600;
var start = 2006;
var end = 2012;
var rateByIdUpArr = [];
var rateByIdDownArr = [];
var currentRenderYear = 2006;
var quantizeUp = d3.scale.quantize()
.domain([0, .16])
.range(d3.range(0,9).map(function(i) {
var something = "p" + i + "-9";
return something;
}));
var quantizeDown = d3.scale.quantize()
.domain([0, .15])
.range(d3.range(0,9).map(function(i) {
var something = "q" + i + "-9";
return something;
}));
var projection = d3.geo.albersUsa()
.scale(6600)
// .translate([width / 4, height / 4]);
.translate([-width, height / 6]);
var path = d3.geo.path()
.projection(projection);
function renderYear(year) {
currentRenderYear = year;
rateByIdUpArr.push(d3.map());
rateByIdUp = rateByIdUpArr[rateByIdUpArr.length - 1];
rateByIdDownArr.push(d3.map());
rateByIdDown = rateByIdDownArr[rateByIdDownArr.length - 1];
queue()
//.defer(d3.json, "http://bl.ocks.org/mbostock/raw/4090846/us.json")
.defer(d3.json, "us.json")
.defer(d3.csv, year + "-rich-bydistrict-fips.csv", function(d) {
var id = "37";
if (d.id.length == 2) {
id += "0";
} else if (d.id.length == 1) {
id += "00";
}
rateByIdUp.set(id+d.id, +d.rate);
})
.defer(d3.csv, year + "-poor-bydistrict-fips.csv", function(d) {
var id = "37";
if (d.id.length == 2) {
id += "0";
} else if (d.id.length == 1) {
id += "00";
}
rateByIdDown.set(id+d.id, +d.rate); })
.await(ready);
}
function ready(error, us) {
// console.log(us);
// console.log(currentRenderYear - 2006);
rateByIdUp = rateByIdUpArr[currentRenderYear - start];
rateByIdDown = rateByIdDownArr[currentRenderYear - start];
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.attr("id", currentRenderYear);
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.enter().append("path")
.attr("class", function(d) {
if (d.id - 37000 > 0 && d.id - 37000 < 1000) {
if (rateByIdUp.has(d.id)) {
return quantizeUp(rateByIdUp.get(d.id));
}
return quantizeDown(rateByIdDown.get(d.id));
}
})
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; }))
.attr("class", "states")
.attr("d", path);
renderNext();
}
var showYear = function(year) {
$("svg").hide();
$("#"+year).show();
}
d3.select(self.frameElement).style("height", height + "px");
var year = start;
function renderNext() {
if (year > end) { return; }
renderYear(year);
year++;
}
renderNext();
</script>
</body>
<style>
</style>
</html>