-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
183 lines (161 loc) · 6.22 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:image" content="img/brooklyn.png">
<meta name="twitter:image" content="img/brooklyn.png">
<link href="https://fonts.googleapis.com/css?family=Libre+Baskerville:wght@400,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:wght@300,600,800" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@900" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<title>American Geography</title>
</head>
<body>
<header>
<div><a href="#"><h2> American</h2><h2>Geography</h2></a></div>
<div class="menu-icon">☰</div>
<nav>
<a href="#" onclick="closeMenu()">Top</a>
<a href="#" onclick="scrollToSection('contact');">Contact</a>
<a href="https://github.com/geographyclub/american-geography" target="_blank">Github Repo</a>
</nav>
</header>
<div class="container">
<!-- <div class="border-container"><div class="color-block"></div><div class="color-block"></div><div class="color-block"></div></div>-->
<div id="banner">
<h1>U.S. STATE RANKER</h1>
<p style="font-weight:300;">Refresh for more random stats from <a href="https://data.census.gov/" target="_blank">US Census</a></p>
</div>
<div id="matchingResultsDiv"></div>
</div>
<script>
function fetchData() {
const prefixes = ["dp02", "dp03", "dp04", "dp05"];
const randomPrefix = prefixes[Math.floor(Math.random() * prefixes.length)];
const labelsUrl = `https://raw.githubusercontent.com/geographyclub/american-geography/main/json/${randomPrefix}_labels.json`;
let counter = 1;
fetch(labelsUrl)
.then(response => response.json())
.then(labelsData => {
const randomLabelObject = labelsData[Math.floor(Math.random() * labelsData.length)];
const [randomKey, randomValue] = Object.entries(randomLabelObject)[0];
const splitRandomValue = randomValue.split('!!');
const fileUrl = `https://raw.githubusercontent.com/geographyclub/american-geography/main/json/state/${randomPrefix}_state.json`;
return fetch(fileUrl)
.then(response => response.json())
.then(secondFileData => {
const lowercaseRandomKey = randomKey.toLowerCase();
const matchingResults = [];
secondFileData.forEach(obj => {
if (lowercaseRandomKey in obj) {
matchingResults.push({
matchingKey: randomKey,
matchingValue: obj[lowercaseRandomKey],
name: obj.name
});
}
});
matchingResults.sort((a, b) => b.matchingValue - a.matchingValue);
const minResult = matchingResults[matchingResults.length - 1];
const medianResult = matchingResults[Math.floor(matchingResults.length / 2)];
const maxResult = matchingResults[0];
const topThreeResults = [maxResult, medianResult, minResult];
const matchingResultsDiv = document.getElementById('matchingResultsDiv');
const randomValueDiv = document.createElement('div');
randomValueDiv.innerHTML = `<div style="padding-bottom:15px"><h2 style="padding-bottom:5px;">${splitRandomValue[1]}</h2><h1>${splitRandomValue.slice(2).join(' <hr> ').replace(/:/g, '')}</h1></div>`;
matchingResultsDiv.appendChild(randomValueDiv);
topThreeResults.forEach(result => {
const resultElement = document.createElement('div');
resultElement.classList.add('flex-column-wide');
const formattedValue = (randomKey.endsWith('PE') && Number(result.matchingValue) < 100)
? `${Number(result.matchingValue).toLocaleString()}%`
: Number(result.matchingValue).toLocaleString();
resultElement.innerHTML = `
<div>
<p>${getContentBasedOnCounter(counter)}</p>
<h1 class="result-${counter}">${formattedValue}</h1>
<h4>${result.name.toUpperCase()}</h4>
</div>
`;
matchingResultsDiv.appendChild(resultElement);
counter++;
});
const resultsContainer = document.createElement('div');
resultsContainer.classList.add('results-container');
matchingResults.forEach(result => {
const resultElement = document.createElement('span');
resultElement.style.lineHeight = '0.5';
const formattedValue = (randomKey.endsWith('PE') && Number(result.matchingValue) < 100)
? `${Number(result.matchingValue).toLocaleString()}%`
: Number(result.matchingValue).toLocaleString();
resultElement.innerHTML = `
<span class="name-4">${result.name.toUpperCase()}</span><span class="result-4">${formattedValue}</span>
`;
resultsContainer.appendChild(resultElement);
});
matchingResultsDiv.appendChild(resultsContainer);
const multilineTextToAdd = `
<hr class="long">
`;
matchingResultsDiv.innerHTML += multilineTextToAdd;
});
})
.then(undefined, error => console.error("Error:", error));
}
const numberOfFetches = 5;
for (let i = 0; i < numberOfFetches; i++) {
fetchData();
}
function getContentBasedOnCounter(counter) {
// Customize the content based on the value of counter
switch (counter) {
case 1:
return '— M A X I M U M —';
case 2:
return '— M E D I A N —';
case 3:
return '— M I N I M U M —';
default:
return ''; // Default content if counter is not 1, 2, or 3
}
}
</script>
<div class="container" style="margin-top:-10px;">
<div class="flex-column-wide footer">
<p id="contact">EMAIL</p>
<a href="mailto:emailstevekim@gmail.com"><h2>emailstevekim@gmail.com</h2></a>
<p>LINKEDIN</p>
<a href="https://www.linkedin.com/in/steve-kim-38a38b295/" target="_blank"><h2>Steve Kim</h2></a>
<p>GITHUB</p>
<a href="https://github.com/geographyclub" target="_blank"><h2>geographyclub</h2></a>
<p>TWITTER</p>
<a href="https://twitter.com/newgeographer2" target="_blank"><h2>@newgeographer2</h2></a>
</div>
</div>
<!-- close menu -->
<script>
document.querySelector('.menu-icon').addEventListener('click', function () {
document.querySelector('nav').classList.toggle('show');
});
function closeMenu() {
document.querySelector('nav').classList.remove('show');
}
</script>
<!-- scroll to section with offset -->
<script>
function scrollToSection(sectionId) {
const targetSection = document.getElementById(sectionId);
const offset = 50;
if (targetSection) {
window.scrollTo({
top: targetSection.offsetTop - offset,
behavior: 'smooth'
});
}
event.preventDefault();
closeMenu();
}
</script>
</body>
</html>