data = {
const json = await FileAttachment("nations.json").json()
const bisectYear = d3.bisector(([year]) => year).left
function valueAt(values, year) {
const i = bisectYear(values, year, 0, values.length - 1)
const a = values[i]
if (i > 0) {
const b = values[i - 1]
const t = (year - a[0]) / (b[0] - a[0])
return a[1] * (1 - t) + b[1] * t
}
return a[1]
}
function dataAt(year) {
return json.map(d => ({
name: d.name,
region: d.region,
income: valueAt(d.income, year),
population: valueAt(d.population, year),
lifeExpectancy: valueAt(d.lifeExpectancy, year)
}))
}
return dataAt(year)
}