-
Notifications
You must be signed in to change notification settings - Fork 0
/
Site2.html
214 lines (174 loc) · 6.39 KB
/
Site2.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
<html>
<script src='https://d3js.org/d3.v5.min.js'></script>
<head>
<style>
h1 { text-align:center}
svg {display: block; margin: auto;}
.button {
background-color: #003f5c;
border: none;
color: white;
padding: 15px 15px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: auto;
cursor: pointer;
}
select{font-size: 20px; font-weight: bold;}
#dropdown{margin:0 auto;width:100px;}
.source {
text-align: center;
font-size: 10px;
}
.events {
text-align: center;
font-size: 14px;
}
.decadeEvents {
width:800px;
margin: auto;
}
.intro {
width:800px;
margin: auto;
font-size: 18px;}
}
</style>
</head>
<body onload='init()'>
<h1>Top 10 Countries of Origin by Decade</h1>
<div class="intro">
<p>Immigration can be dependent on the country of origin of the individual.
Factors such as war, socioeconomics and legislation provide a catalyst for people from varying nations to migrate.
Depending on the decade, some nationalities dominated the level of immigration.
Select different decades below to see the top 10 countries of origin for individuals migrating into the U.S along with worldwide events that may have driven the immigration.
</p>
</div>
<div id="dropdown">
<select id="decades">
<option value="1820to1829" selected="selected">1820 to 1829</option>
<option value="1830to1839">1830 to 1839</option>
<option value="1840to1849">1840 to 1849</option>
<option value="1850to1859">1850 to 1859</option>
<option value="1860to1869">1860 to 1869</option>
<option value="1870to1879">1870 to 1879</option>
<option value="1880to1889">1880 to 1889</option>
<option value="1890to1899">1890 to 1899</option>
<option value="1900to1909">1900 to 1909</option>
<option value="1910to1919">1910 to 1919</option>
<option value="1920to1929">1920 to 1929</option>
<option value="1930to1939">1930 to 1939</option>
<option value="1940to1949">1940 to 1949</option>
<option value="1950to1959">1950 to 1959</option>
<option value="1960to1969">1960 to 1969</option>
<option value="1970to1979">1970 to 1979</option>
<option value="1980to1989">1980 to 1989</option>
<option value="1990to1999">1990 to 1999</option>
<option value="2000to2009">2000 to 2009</option>
<option value="2010to2018">2010 to 2018</option>
</select>
</div>
<svg width=1000 height=500 ></svg>
<div style="float: left;">
<button class="button" onclick="location.href='http://jhuamani.github.io/Site1.html'" type="button">Immigrants Admitted</button>
</div>
<div style="float: right;">
<button class="button" onclick="location.href='http://jhuamani.github.io/Site3.html'" type="button">Age Groups</button>
</div>
<div class="decadeEvents"></div>
<p class="source">Data Source: "Yearbook of Immigration Statistics" U.S. Department of Homeland Security,
https://www.dhs.gov/immigration-statistics/yearbook</br>
Historical Event Sources: "Wikipedia" Wikimedia Foundation, https://en.wikipedia.org/</br>
"Library" Central Intelligence Agency, https://cia.gov/library</br>
"U.S. Immigration Timeline" History, A&E Television Networks "https://history.com/topics/immigration/immigration-united-states-timeline</p>
<script>
async function init() {
data = await d3.csv("https://jhuamani.github.io/Countries%20and%20Decades.csv");
events = await d3.csv("https://jhuamani.github.io/DecadeEvents.csv");
//Tooltip
var tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity",0)
.style("position","absolute")
.style("background-color", "white")
.style("padding", "5px");
var currentDecade = document.getElementById("decades").value
//sorting data according to first column
//then filtering out top 10 countries in descending order
FiltData = data.sort(function(a,b) { return +a[currentDecade] - +b[currentDecade]; });
FiltData = FiltData.filter(function(d,i){ return i>68; });
FiltEvent = events.filter(function(d){ return d.Decades == currentDecade })
EventText = FiltEvent[0].Events
DEvents = d3.select(".decadeEvents")
.append("p")
.attr("class","events")
.html("<strong>Decade Events:</strong></br>" + EventText+ "</br>")
var margin = 100; //all but left margin
var height = 550 - 2*margin;
var width = 1000-2*margin;
//y-axis
var y = d3.scaleBand().domain(FiltData.map(function(d) {return d.Countries;}))
.range([height,0]).padding(0.1);
yaxis = d3.select("svg").append("g")
.attr("transform","translate("+150+","+margin+")")
.call(d3.axisLeft(y));
//x-axis
var ticks = [1000,10000,100000,1000000,3000000];
var x = d3.scaleLog().domain([1000,3000000]).range([0,width]);
xaxis = d3.select("svg").append("g")
.attr("transform","translate("+150+","+(height+margin)+")")
.call(d3.axisBottom(x).tickFormat(d3.format(",")).tickValues(ticks));
//Bars for barchart
var rects = d3.select("svg").append("g")
.attr("transform","translate("+150+","+margin+")")
.selectAll("rect").data(FiltData).enter().append("rect")
.attr("x", 0)
.attr("y", function(d) {return y(d.Countries);})
.attr("height", y.bandwidth())
.attr("width", function(d) {return x(d[currentDecade]);})
.attr("fill", "#58508d")
.on("mouseover",function(d){
tooltip
.style("opacity",1)
d3.select(this)
.attr("fill", "#ffa600");
;})
.on("mousemove",function(d){
tooltip
.style("left", (d3.event.pageX + 60) + "px")
.style("top", (d3.event.pageY) + "px")
.html("Country: " + d.Countries + "<br>" + "Immigrants: " + d[currentDecade])
;})
.on("mouseout",function () {
tooltip.style("opacity",0)
d3.select(this)
.attr("fill", "#58508d")
;});
function rebar(decade){
FiltData = data.sort(function(a,b) { return +a[decade] - +b[decade]; });
FiltData = FiltData.filter(function(d,i){ return i>68; })
y.domain(FiltData.map(function(d) {return d.Countries;}))
yaxis.transition().duration(1000).call(d3.axisLeft(y));
var update = d3.select("svg").selectAll("rect").data(FiltData);
update
.enter().append("rect").merge(update)
.transition().duration(1000)
.attr("x", 0)
.attr("y", function(d) {return y(d.Countries);})
.attr("height", y.bandwidth())
.attr("width", function(d) {return x(d[decade]);})
.attr("fill", "#58508d")
FiltEvent = events.filter(function(d){ return d.Decades == decade })
EventText = FiltEvent[0].Events
DEvents.html("<strong>Decade Events:</strong></br>" + EventText+ "</br>")
};
d3.select("#decades").on("change", function(d){
currentDecade = this.value
rebar(currentDecade)
});
}
</script>
</body>
</html>