-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
376 lines (322 loc) · 12.4 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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Raed Anbarserri - US Obesity</title>
<meta name="author" content="Matthew Howell" />
<meta name="description" content="fullPage continuous scrolling demo." />
<meta name="keywords" content="fullpage,jquery,demo,scroll,loop,continuous" />
<meta name="Resource-type" content="Document" />
<link rel="stylesheet" type="text/css" href="dist/fullpage.css" />
<link rel="stylesheet" type="text/css" href="examples.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://d3js.org/d3.v4.js"></script>
<!--[if IE]>
<script type="text/javascript">
var console = { log: function() {} };
</script>
<![endif]-->
</head>
<body>
<ul id="menu">
<li data-menuanchor="1stPage" class="active"><a href="#1stPage" title="Overview">1</a></li>
<li data-menuanchor="2ndPage"><a href="#2ndPage" title="Income">2</a></li>
<li data-menuanchor="3rdPage"><a href="#3rdPage" title="Age">3</a></li>
<li data-menuanchor="4thPage"><a href="#4thPage" title="Education">4</a></li>
</ul>
<div id="fullpage">
<div class="section " id="section0">
<h1>Obesity in the United States (2012-2018)</h1>
</br>
<p>This visualization is designed to portray any correlations between obesity and multiple different factors of the United States
population from 2012 to 2018. The charts are ordered based on significance of the factor.
</p>
</br>
</br>
</br>
<p><b>Navigate</b> by either scrolling up and down or clicking the top-left buttons for each respective slide.</p>
</br>
</br>
</br>
<p>By Raed Anbarserri</p>
</br>
</br>
<p><a href="https://healthdata.gov/dataset/nutrition-physical-activity-and-obesity-behavioral-risk-factor-surveillance-system">Source: Center for Disease Control and Prevention </a></p>
</div>
<div class="section ">
<div style="width:50%;transform: translate(0%,250%)">
<p>Obesity according to Income</p>
</br>
<p class="texts">This bar chart plots the average obesity of people with certain levels of income, in which people earning less
than $15,000 have the highest average of obesity and people earning more than $75,000 have the lowest.
</p>
</br>
<p class="texts">Hover your mouse over the bars to view exact percentages.</p>
<p class="texts">Click the dropdown menu to change the year of the data.</p>
</div>
<div id="section1" style="width:50%;transform: translate(100%,0%)">
<h3>Obesity vs Income</h3>
</div>
</div>
<div class="section " >
<div style="width:50%;transform: translate(0%,250%)">
<p>Obesity according to Age</p>
</br>
<p class="texts">This bar chart plots the average obesity of people of certain ages, in which middle-aged people
tend to have the highest average of obesity and the youngest tend to have the least.
</p>
</br>
<p class="texts">Hover your mouse over the bars to view exact percentages.</p>
<p class="texts">Click the dropdown menu to change the year of the data.</p>
</div>
<div id="section2" style="width:50%;transform: translate(100%,0%)">
<h3>Obesity vs Age</h3>
</div>
</div>
<div class="section" >
<div style="width:50%;transform: translate(0%,250%)">
<p>Obesity according to Education</p>
</br>
<p class="texts">This bar chart plots the average obesity of people with certain levels of education, in which people who
have the lowest education have the highest average of obesity and people with the highest education have the lowest.
</p>
</br>
<p class="texts">Hover your mouse over the bars to view exact percentages.</p>
<p class="texts">Click the dropdown menu to change the year of the data.</p>
</div>
<div id="section3" style="width:50%;transform: translate(100%,0%)">
<h3>Obesity vs Education</h3>
</div>
</div>
</div>
<script>
// set the dimensions and margins of the graph
var margin = {top: 30, right: 30, bottom: 70, left: 60},
width = 500 - margin.left - margin.right,
height = 650 - margin.top - margin.bottom,
padding = -30;
var data = [2012,2013,2014,2015,2016,2017,2018];
50,10,100
50,0,100
///////////////////////////////////////////////////////////////////////////// graph1
function onchange() {
selectValue = $("#section1").find('select').val();
//d3.select('body').append('p').text(selectValue + ' is the last selected option.')
parseData(selectValue);
};
function parseData(selectValue){
$("#section1").html("");
var select = d3.select('#section1')
.append('select')
.attr('class','select')
.on('change',onchange)
var options = select
.selectAll('option')
.data(data).enter()
.append('option')
.text(function (d) { return d; });
d3.select('select').property('value',selectValue);
var svg_graph1 = d3.select("#section1")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", 50+ height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// Parse the Data
d3.csv("https://samanake.github.io/obesity_Income.csv", function(data) {
// X axis
var x = d3.scaleBand()
.range([ 0, width ])
.domain(data.map(function(d) { return d.Income; }))
.padding(0.2);
svg_graph1.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.style("text-anchor", "end");
svg_graph1.append("text")
.attr("text-anchor", "middle")
.attr("transform", "translate("+ (padding) +","+(height/2)+")rotate(-90)")
.text("Obesity (%)");
svg_graph1.append("text")
.attr("text-anchor", "middle")
.attr("transform", "translate("+ (width/2) +","+(50+height-(padding-10))+")")
.text("Income");
// Add Y axis
var y = d3.scaleLinear()
.domain([0, 50])
.range([ height, 0]);
svg_graph1.append("g")
.call(d3.axisLeft(y));
// Bars
svg_graph1.selectAll("mybar")
.data(data)
.enter()
.append("rect")
.attr("x", function(d) { if (d.Year == selectValue) return x(d.Income); })
.attr("y", function(d) { if (d.Year == selectValue) return y(d.Value); })
.attr("width", x.bandwidth())
.attr("height", function(d) { if (d.Year == selectValue) return height - y(d.Value); })
.attr("class","rect")
.append("title")
.text(function(d){
return "Income " + d.Income + " : " + d.Value + "%";
});
})
}
parseData('2012');
//////////////////////////////////////////////////////////////////////////// graph2
function onchange2() {
//selectValue = d3.select('#section1').find('select').property('value')
selectValue = $("#section2").find('select').val();
//d3.select('body').append('p').text(selectValue + ' is the last selected option.')
parseData2(selectValue);
};
function parseData2(selectValue){
$("#section2").html("");
var select = d3.select('#section2')
.append('select')
.attr('class','select')
.on('change',onchange2)
var options = select
.selectAll('option')
.data(data).enter()
.append('option')
.text(function (d) { return d; });
$("#section2").find('select').val(selectValue);
var svg_graph2 = d3.select("#section2")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", 50+ height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// Parse the Data
d3.csv("https://samanake.github.io/obesity_Age.csv", function(data) {
// X axis
var x = d3.scaleBand()
.range([ 0, width ])
.domain(data.map(function(d) { return d.Age; }))
.padding(0.2);
svg_graph2.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.style("text-anchor", "end");
svg_graph2.append("text")
.attr("text-anchor", "middle")
.attr("transform", "translate("+ (padding) +","+(height/2)+")rotate(-90)")
.text("Obesity (%)");
svg_graph2.append("text")
.attr("text-anchor", "middle")
.attr("transform", "translate("+ (width/2) +","+(10+height-(padding-10))+")")
.text("Age");
// Add Y axis
var y = d3.scaleLinear()
.domain([0, 50])
.range([ height, 0]);
svg_graph2.append("g")
.call(d3.axisLeft(y));
// Bars
svg_graph2.selectAll("mybar")
.data(data)
.enter()
.append("rect")
.attr("x", function(d) { if (d.Year == selectValue) return x(d.Age); })
.attr("y", function(d) { if (d.Year == selectValue) return y(d.Value); })
.attr("width", x.bandwidth())
.attr("height", function(d) { if (d.Year == selectValue) return height - y(d.Value); })
.attr("class","rect")
.append("title")
.text(function(d){
return "Age " + d.Age + " : " + d.Value + "%";
});
})
}
parseData2('2012');
//////////////////////////////////////////////////////////////////////////// graph3
function onchange3() {
//selectValue = d3.select('#section1').find('select').property('value')
selectValue = $("#section3").find('select').val();
//d3.select('body').append('p').text(selectValue + ' is the last selected option.')
parseData3(selectValue);
};
function parseData3(selectValue){
$("#section3").html("");
var select = d3.select('#section3')
.append('select')
.attr('class','select')
.on('change',onchange3)
var options = select
.selectAll('option')
.data(data).enter()
.append('option')
.text(function (d) { return d; });
$("#section3").find('select').val(selectValue);
var svg_graph3 = d3.select("#section3")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", 75+ height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// Parse the Data
d3.csv("https://samanake.github.io/obesity_Education.csv", function(data) {
// X axis
var x = d3.scaleBand()
.range([ 0, width ])
.domain(data.map(function(d) { return d.Education; }))
.padding(0.2);
svg_graph3.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.style("text-anchor", "end");
svg_graph3.append("text")
.attr("text-anchor", "middle")
.attr("transform", "translate("+ (padding) +","+(height/2)+")rotate(-90)")
.text("Obesity (%)");
svg_graph3.append("text")
.attr("text-anchor", "middle")
.attr("transform", "translate("+ (width/2) +","+(75+height-(padding-10))+")")
.text("Education");
// Add Y axis
var y = d3.scaleLinear()
.domain([0, 50])
.range([ height, 0]);
svg_graph3.append("g")
.call(d3.axisLeft(y));
// Bars
svg_graph3.selectAll("mybar")
.data(data)
.enter()
.append("rect")
.attr("x", function(d) { if (d.Year == selectValue) return x(d.Education); })
.attr("y", function(d) { if (d.Year == selectValue) return y(d.Value); })
.attr("width", x.bandwidth())
.attr("height", function(d) { if (d.Year == selectValue) return height - y(d.Value); })
.attr("class","rect")
.append("title")
.text(function(d){
return "Education " + d.Education + " : " + d.Value + "%";
});
})
}
parseData3('2012');
//d3.csv("https://samanake.github.io/obesity_2018_income.csv";
</script>
<script type="text/javascript" src="dist/fullpage.js"></script>
<script type="text/javascript">
var myFullpage = new fullpage('#fullpage', {
sectionsColor: ['rgb(193 193 193)', 'rgb(193 193 193)', 'rgb(193 193 193)','rgb(193 193 193)'],
anchors: ['1stPage', '2ndPage', '3rdPage', '4thPage'],
menu: '#menu',
lazyLoad: true
});
</script>
</body>
</html>