Published
Edited
Jan 16, 2022
22 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
cpi = (await FileAttachment("CPIAUCSL.csv").csv({ typed: true })).map((d) => ({
date: d.DATE,
value: d.CPIAUCSL
}))
Insert cell
cpiMap = d3.rollup(
cpi.filter(inBounds),
(arr) => arr[0].value, // or should it average the months?
(d) => d3.utcYear.floor(d.date)
)
Insert cell
boxoffice = (
await FileAttachment("Box Office Gross - box office.csv").csv({ typed: true })
).map((d) => ({
date: new Date(Date.UTC(d.year, 0, 1)),
value: d.total_gross
}))
Insert cell
boxofficeAdjusted = boxoffice.map(({ date, value }) => ({
date,
value: real ? value / (cpiMap.get(date) / index) : value
}))
Insert cell
ticks = d3.range(...valueExtent, 1e9)
Insert cell
adjustedTicks = real
? d3.range(
0,
valueExtent[1] ** 2 /
d3.min(
cpi
.filter(inBounds)
.map((d) => valueExtent[1] / (d.value / indexStart))
),
1e9
)
: ticks
Insert cell
gridlines = cpi
.filter(inBounds)
.flatMap((d) =>
adjustedTicks.map((tick) => ({
date: d.date,
value: real
? tick / (d.value / indexStart)
: tick * (d.value / indexStart),
tick
}))
)
.filter((d) => d.value <= valueExtent[1])
Insert cell
index = cpiMap.get(new Date(Date.UTC(year, 0, 1)))
Insert cell
indexStart = cpiMap.get(dateExtent[0])
Insert cell
dateExtent = d3.extent(boxoffice, d => d.date)
Insert cell
valueExtent = [0, d3.max(boxoffice, d => d.value)]
Insert cell
inBounds = d => d.date >= dateExtent[0] && d.date <= dateExtent[1]
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more