-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
228 lines (191 loc) · 6.64 KB
/
index.html
File metadata and controls
228 lines (191 loc) · 6.64 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
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
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>Mapping Poverty</title>
<link rel="stylesheet" type="text/css" href="./css/reset.css">
<link rel="stylesheet" type="text/css" href="./css/stylesheet.css">
<link href="https://fonts.googleapis.com/css?family=Lora" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link rel="icon"
type="image/png"
href="./docs/images/favicon.png">
<div class="nav-bar">
<h1 class="title">Exploring Changes in US Poverty Rates </h1>
<h2 class="subtitle">Using Census Small Area Income and Poverty Estimates (SAIPE) to Show Changes in American Poverty Rates</h2>
</div>
</head>
<body>
<div class="content">
<div class="wrapper">
<div id="map"></div>
</div>
<div class="about-modal">
<div class="links">
<a href="https://github.com/swetagsanghavi/MappingPoverty"><img class="github" src="./docs/images/github-logo.png" alt=""></a>
<a href="https://www.linkedin.com/in/sweta-sanghavi/"><img class="linkedin" src="./docs/images/linkedin-button.png" alt=""></a>
</div>
<h3 class="year">Select Year
<select id="dropdown"></select>
</h3>
<div id="tooltip">
<h3 class="year prompt">Hover Over Map To See County Specific Poverty Levels</h3>
<div class="data">
<ul id="active-neighborhood">
<li> Bronx County, NY </li>
<li> 30.3% </li>
</ul>
<h3><span id = "neighborhood"> </span></h3>
<h5><span id = "datum"> </span></h5>
</div>
</div>
<p class="about-text">Using d3.js and census data, this choropleth map shows the estimated percent of people of all ages in poverty. Use the dropdown above to toggle through years to see changing demographics through time. This project examines counties with high rates of poverty. Does the percentage of people living in poverty increase over time in these counties? </p>
</div>
</div>
</body>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-96767454-1', 'auto');
ga('send', 'pageview');
</script>
<script type="text/javascript" src="./lib/d3.v4.min.js"></script>
<script src="./lib/topojson.v2.min.js"></script>
<script src="https://d3js.org/d3-geo.v1.min.js"></script>
<script src="https://d3js.org/d3-array.v1.min.js"></script>
<script src="./lib/d3.scale.chromatic.v1.min.js"></script>
<script src="https://d3js.org/d3-color.v1.min.js"></script>
<script src="https://d3js.org/d3-dispatch.v1.min.js"></script>
<script src="https://d3js.org/d3-ease.v1.min.js"></script>
<script src="https://d3js.org/d3-interpolate.v1.min.js"></script>
<script src="https://d3js.org/d3-selection.v1.min.js"></script>
<script src="https://d3js.org/d3-timer.v1.min.js"></script>
<script src="https://d3js.org/d3-transition.v1.min.js"></script>
<script src="https://d3js.org/d3-drag.v1.min.js"></script>
<script src="https://d3js.org/d3-zoom.v1.min.js"></script>
<script type="text/javascript">
let width;
let height;
let path;
let svg;
let year = 2015;
let z;
const init = () => {
setMap();
populationDropdown();
setKey();
loadData(year)
}
const setMap = () => {
width = 960;
height = 600;
svg = d3.select("#map").append("svg")
.attr("width", width)
.attr("height", height)
svg.append("rect")
.attr("class", "background")
.attr("width", width)
.attr("height", height)
}
const PovertyEstimates = d3.map();
path = d3.geoPath();
const x = d3.scaleLinear()
.domain([3, 50])
.rangeRound([600, 860]);
const color = d3.scaleThreshold()
.domain([10, 20, 30, 40, 60])
.range(d3.schemeBuPu[5]);
const setKey = () => {
const g = svg.append("g")
.attr("class", "key")
.attr("transform", "translate(20,27)")
g.selectAll("rect")
.data(color.range().map( d => {
d = color.invertExtent(d);
if (d[0] == null) d[0] = x.domain()[0];
if (d[1] == null) d[1] = x.domain()[1];
return d;
}))
.enter().append("rect")
.attr("height", 8)
.attr("x", d => x(d[0]))
.attr("width", d => x(d[1]) - x(d[0]))
.attr("fill", d => color(d[0]))
g.append("text")
.attr("class", "caption")
.attr("x", x.range()[0])
.attr("y", -10)
.attr("fill", "#fff")
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text("Poverty Rate");
g.call(d3.axisBottom(x)
.tickSize(13)
.tickFormat((x, i) => ( i ? x : x + "%" ))
.tickValues(color.domain()))
.select(".domain")
.remove();
}
const years = [2015, 2014, 2013, 2012]
const populationDropdown = () => {
d3.select("#dropdown")
.selectAll("option")
.data(years)
.enter()
.append("option")
.attr("value", year => year)
.text(year => year);
}
const dropDown = d3.select("#dropdown");
dropDown.on("change", () => {
loadData(d3.event.target.value)
});
const processData = (error, us) => {
if (error) throw error;
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.enter().append("path")
.attr("fill", d => {
d.county = PovertyEstimates.get(`County${d.id}`)
d.state = PovertyEstimates.get(`State${d.id}`)
return color(d.rate = PovertyEstimates.get(d.id))
}).attr("d", path)
.on("mouseover", (d) => displayData(d))
.on("mouseout", hideData())
.append("title")
.text(d => `${d.county}, ${d.state} Poverty Rate: ${d.rate}%`)
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, (a, b) => ( a !== b ) ))
.attr("class", "states")
.attr("d", path)
}
const displayData = (d) => {
d3.select("#neighborhood")
.text(`${d.county}, ${d.state}`)
d3.select("#datum")
.text(`Poverty Rate: ${d.rate}%`);
d3.select("#active-neighborhood")
.selectAll("li")
.classed("inactive-neighborhood", true)
}
const hideData = () => {
d3.select("#neighborhood")
.text("\u00A0");
d3.select("#datum")
.text("\u00A0");
}
const loadData = (year) => {
let key = `rate${year}`
d3.queue()
.defer(d3.json, "https://d3js.org/us-10m.v1.json")
.defer(d3.tsv, "./data/PovertyEstimates_all_years.tsv", d => (PovertyEstimates.set(d.id, d[key]).set(`State${d.id}`, d.State).set(`County${d.id}`, d.Area_Name)))
.await(processData);
}
function stopped() {
if (d3.event.defaultPrevented) d3.event.stopPropagation();
}
window.onload = init();
</script>