-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
170 lines (150 loc) · 7.74 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
<html>
<head>
<meta property="og:title" content="Alaska Names" />
<meta property="og:type" content="article" />
<meta property="og:image" content="http://codeforanchorage.org/pfd-names/img/screen_shot.png" />
<meta property="og:url" content="http://codeforanchorage.org/pfd-names" />
<meta property="og:description" content="Alaska Name Popularity Over Time" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Alaska Names" />
<meta name="twitter:description" content="Alaska Name Popularity Over Time" />
<meta name="twitter:image" content="http://codeforanchorage.org/pfd-names/img/screen_shot.png" />
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<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-56999250-1', 'auto');
ga('send', 'pageview', {
'page': location.pathname + location.search + location.hash
});
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>
<script>
const chartColors = [
'rgb(255, 99, 132)',
'rgb(75, 192, 192)',
'rgb(255, 205, 86)',
'rgb(54, 162, 235)',
'rgb(255, 159, 64)',
'rgb(153, 102, 255)',
'rgb(201, 203, 207)',
]
function getNameData() {
const rawNames = document.getElementById('name').value
const names = rawNames
.split(',')
.map(x => x.trim())
.map(x => `'${x}'`)
.join(',')
.toUpperCase()
$.ajax({
url: "https://data.muni.org/resource/utuq-8d9h.json",
type: "GET",
data: {
$where: `first_name in (${names})`
}
}).done(function(data) {
data.sort((a, b) => parseInt(a.year) - parseInt(b.year))
const datasets = data.reduce((datasets, current) => {
const foundName = datasets.find(d => d.label === current.first_name)
const nameObject = foundName || {
label: current.first_name,
data: [],
fill: false,
borderColor: chartColors[datasets.length % chartColors.length],
backgroundColor: chartColors[datasets.length % chartColors.length],
}
if (!foundName) datasets.push(nameObject)
nameObject.data.push({
x: parseInt(current.year),
y: parseInt(current.count),
})
return datasets
}, [])
myLineChart.data.datasets = []
myLineChart.data.datasets = datasets
myLineChart.update()
});
}
function handleSubmit() {
window.location.hash = document.getElementById('name').value;
ga('send', 'pageview', {
'page': location.pathname + location.search + location.hash
});
return false;
}
</script>
<style>
body {
font-family: sans-serif;
}
h1 {
text-align: center;
}
form {
margin-top: 50px;
}
</style>
</head>
<body style="padding:20px;">
<h1>Alaskan Names</h1>
<p>Type a name to see how many Alaskans with that first name have filed for the PFD each year.</p>
<p>You can also do multiple names seperated with commas.</p>
<form onsubmit="return handleSubmit()">
<input id="name" style="width:60%; margin-left:55px; margin-bottom:20px;" />
<input type="submit" value="Go" />
</form>
<canvas id="results"></canvas>
<h3>Interesting data</h3>
<ul>
<li><a href="#mary,jennifer,elizabeth,sarah,jessica,susan,linda,patricia,rebecca,michelle">Most popular female names 2021</a></li>
<li><a href="#michael,james,john,david,robert,william,daniel,christopher,joseph,thomas">Most popular male names 2021</a></li>
<li>Biggest Increase (male and female) - <a href="#jacob,hannah">All Time</a> | <a href="#benjamin,amelia">2020 - 2021</a></li>
<li>Biggest Decrease (male and female) - <a href="#robert,mary">All Time</a> | <a href="#david,mary">2020 - 2021</a></li>
<li>Top 10 Increases - <a href="#jacob,tyler,ethan,joshua,logan,hannah,alexander,emily,jordan,olivia">All Time</a> | <a href="#benjamin,theodore,samuel,amelia,joshua,ava,olivia,oliver,justin,aurora">2020 - 2021</a></li>
<li><a href="#sunday,monday,tuesday,wednesday,thursday,friday,saturday">Days of the week</a></li>
<li><a href="#january,february,march,april,may,june,july,august,september,october,november,december">Months of the year</a></li>
<li><a href="#Anchorage,Fairbanks,Juneau,Sitka,Wasilla,Kenai,Kodiak,Bethel,Palmer,Homer,Unalaska">Cities in Alaska</a></li>
<li><a href="#Alabama,Alaska,AmericanSamoa,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida,Georgia,Guam,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Maryland,Massachusetts,Michigan,Minnesota,MinorOutlyingIslands,Mississippi,Missouri,Montana,Nebraska,Nevada,NewHampshire,NewJersey,NewMexico,NewYork,NorthCarolina,NorthDakota,NorthernMarianaIslands,Ohio,Oklahoma,Oregon,Pennsylvania,PuertoRico,RhodeIsland,SouthCarolina,SouthDakota,Tennessee,Texas,U.S.VirginIslands,Utah,Vermont,Virginia,Washington,WestVirginia,Wisconsin,Wyoming">States in the union</a></li>
<li><a href="#wolf,bear,eagle,fox,lynx,salmon,trout,otter,beaver,raven">Alaskan animals</a></li>
</ul>
<script>
const ctx = document.getElementById('results').getContext('2d');
const myLineChart = new Chart(ctx, {
type: 'line',
data: { },
options: {
scales: {
xAxes: [{
type: 'linear',
scaleLabel: {
display: true,
labelString: 'Year',
}
}],
yAxes: [{
type: 'linear',
scaleLabel: {
display: true,
labelString: 'Count',
}
}]
},
}
});
function drawGraphFromHash() {
const names = decodeURI(window.location.hash.replace('#', ''))
document.getElementById('name').value = names
getNameData()
}
if (window.location.hash) {
drawGraphFromHash()
}
window.addEventListener('hashchange', function() {
drawGraphFromHash()
}, false)
</script>
</body>
</html>