summaryrefslogtreecommitdiff
path: root/client/data.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/data.js')
-rw-r--r--client/data.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/client/data.js b/client/data.js
new file mode 100644
index 0000000..4eab9d3
--- /dev/null
+++ b/client/data.js
@@ -0,0 +1,29 @@
+const files = [
+ "housing-costs-and-income-inequality",
+ "income-inequality-over-time",
+ "shares-of-wealth",
+ "weekly-earnings",
+ "household-wealth",
+]
+
+const dataPromises = files.map(name => {
+ return fetch('./data/' + name + '.csv').then(rows => {
+ return rows.text()
+ }).then(text => {
+ let lines = text.split('\n').map(line => line.split(','))
+ const h = lines.shift()
+ return {
+ name: name.replace(/-/g, ' '),
+ h,
+ lines: lines.filter(s => !!s)
+ }
+ })
+})
+const allPromises = Promise.all(dataPromises).then(data => {
+ return data.reduce((a,b) => { a[b.name.replace(/-/g, '_')] = b; return a }, {})
+})
+const load = () => {
+ return allPromises
+}
+
+export { load } \ No newline at end of file