summaryrefslogtreecommitdiff
path: root/client/data.js
blob: 4eab9d3870af7535577df8a78c7b79a660a3bfd7 (plain)
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
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 }