-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.html
144 lines (128 loc) · 4.49 KB
/
data.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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lexend:[email protected]&display=swap" rel="stylesheet">
<style>
body {
font-family: "Lexend", "Helvetica Neue", "Helvetica", sans-serif;
margin: 0;
padding: 0;
font-size: 14px;
}
header {
background-color: #999;
color: #eee;
height: 0vh;
}
main {
background-color: #333;
color: #ddd;
height: 100vh;
overflow: scroll;
}
footer {
background-color: #666;
color: #eee;
height: 0vh;
}
h2,
th {
text-transform: capitalize;
}
.streets {
columns: 3;
}
table {
max-width:80vw;
margin: 1em auto;
background: #fff;
color: #000;
font-family: "Lexend","HelveticaNeue",sans-serif;
font-weight:300;
border-collapse: collapse;
}
td {
vertical-align: top;
border-right: 1px solid #0006;
border-bottom: 1px solid #0006;
padding: 0.25em;
}
th {
background: #333;
color:#eee;
font-size: 1.2em;
}
.name {
white-space: nowrap;
}
</style>
</head>
<body>
<main></main>
<script>
const $ = str => document.querySelector(str);
const $$ = str => document.querySelectorAll(str);
(function() {
const app = {
init: function() {
fetch("sf-street-history.json").then(response => response.json()).then(data => {
app.state.loaded = true;
console.dir(data);
app.state.data = data;
app.show('neighborhoods');
app.show('entities');
app.showStreets();
});
},
showStreets: function() {
let ent = '';
let keys = Object.keys(app.state.data.streets);
let out = `<div class='streets'>`;
const streets = app.state.data.streets;
keys.forEach((key, idx, keys) => {
if (streets[key].history) {
out += `<details><summary>${streets[key].name}</summary>${streets[key].history}</details>`;
} else if (streets[key].entityIds) {
ent = app.state.data.entities[streets[key].entityIds];
out += `<details><summary>${streets[key].name}</summary><h3>${ent.name}</h3>${ent.desc}</details>`;
}
});
out += "</div>";
$("main").innerHTML += out;
},
show: function(category) {
let items = app.state.data[category];
let arrkeys = Object.keys(items);
let out = `<h2>${category}</h2><table><thead><tr>`;
const fields = Object.keys(items[arrkeys[0]]);
fields.forEach((f) => {
out += `<th>${f}</th>`
});
out += `</tr></thead><tbody>`;
arrkeys.forEach((arrkey, idx, arr) => {
let item = items[arrkey];
out += `<tr>`;
for (let i = 0; i < fields.length-1; i++) {
out += `<td class='${fields[i].replace(/\s/g,'')}'>${item[fields[i]]}</td>`;
};
out += `<td class='${fields[fields.length-1].replace(/\s/g,'')}'><a href="${item[fields[fields.length-1]]}">link</a></td>`;
out += `</tr>`;
});
out += `</tbody></table>`;
$("main").innerHTML += out;
},
state: {
loaded: false,
data: {}
}
}
window.app = app;
app.init();
})();
</script>
</body>
</html>