Published
Edited
Apr 19, 2022
1 fork
2 stars
Insert cell
Insert cell
Insert cell
data = FileAttachment("bandcamp-oneday.csv").csv({typed: true})
Insert cell
Inputs.table(data)
Insert cell
Insert cell
d3.group(data, d => d.country)
Insert cell
d3.rollup(data, v => v, d => d.country)
Insert cell
d3.rollup(data, v => v.length, d => d.country)
Insert cell
d3.rollup(data, v => d3.sum(v, val => val.amount_paid), d => d.country)
Insert cell
import {Treemap} from "@d3/treemap"
Insert cell
Now we can actually render our treemap
Insert cell
// type your code here:

Insert cell
Insert cell
rolled = d3.rollup(data, v => {
return {
count: v.length,
total_paid: d3.sum(v, o => o.amount_paid),
type: v[0].type
}},
d => d.type)
Insert cell
// type your code here:

Insert cell
Insert cell
// type your code here:

Insert cell
Insert cell
Insert cell
rolled2 = d3.rollup(data,
v => {
return {
count: v.length,
total_paid: d3.sum(v, o => o.amount_paid),
type: v[0].type,
account: v[0].account
}
},
d => d.type,
d => d.account,
)
Insert cell
Treemap(rolled2, {
value: d => d[1].count,
group: d => d[1].type,
label: d => d[1].account,
title: d => `${d[1].type} ${d[1].count}`,
fillOpacity: 1
})
Insert cell
Insert cell
import { BubbleChart } from "@d3/bubble-chart"
Insert cell
// type your code here:

Insert cell
Insert cell
Insert cell
import { Pack } from "@d3/pack"
Insert cell
// type your code here:

Insert cell
Insert cell
Insert cell
bardata = Array.from(rolled.values())
Insert cell
import { BarChart } from "@d3/bar-chart-transitions"
Insert cell
// type your code here:

Insert cell
Insert cell
viewof country = Inputs.select(new Set(data.map(d => d.country)), { label: "Select country:" })
Insert cell
Insert cell
// type your code here:

Insert cell
Insert cell
Insert cell
// type your code here:

Insert cell
Insert cell
// we will end up wanting to keep the order of the x domain the same
typelist = ["bundle", "merch", "track", "album"]
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more