{
var monthFormat = d3.timeFormat('%Y-%m')
const boroughGrouped = d3.group(deduplicatedData, d => d.boro)
const BronxInspectionsByTime = Array.from(d3.rollup(boroughGrouped.get("Bronx"),
v => v.length,
d => monthFormat(d.date)),
([month, inspections]) => ({month, inspections}))
.sort((a,b) => d3.ascending(a.month, b.month))
const BrooklynInspectionsByTime = Array.from(d3.rollup(boroughGrouped.get("Brooklyn"),
v => v.length,
d => monthFormat(d.date)),
([month, inspections]) => ({month, inspections}))
.sort((a,b) => d3.ascending(a.month, b.month))
const QueensInspectionsByTime = Array.from(d3.rollup(boroughGrouped.get("Queens"),
v => v.length,
d => monthFormat(d.date)),
([month, inspections]) => ({month, inspections}))
.sort((a,b) => d3.ascending(a.month, b.month))
const ManhattanInspectionsByTime = Array.from(d3.rollup(boroughGrouped.get("Manhattan"),
v => v.length,
d => monthFormat(d.date)),
([month, inspections]) => ({month, inspections}))
.sort((a,b) => d3.ascending(a.month, b.month))
const StatenIslandInspectionsByTime = Array.from(d3.rollup(boroughGrouped.get("Staten Island"),
v => v.length,
d => monthFormat(d.date)),
([month, inspections]) => ({month, inspections}))
.sort((a,b) => d3.ascending(a.month, b.month))
const BrooklynChart = vl.markLine()
.data(BrooklynInspectionsByTime)
.title("Inspections over time in Brooklyn")
.encode(
vl.x().fieldT("month"),
vl.y().fieldQ("inspections")
)
const BronxChart = vl.markLine()
.data(BronxInspectionsByTime)
.title("Inspections over time in Bronx")
.encode(
vl.x().fieldT("month"),
vl.y().fieldQ("inspections")
)
const QueensChart = vl.markLine()
.data(QueensInspectionsByTime)
.title("Inspections over time in Queens")
.encode(
vl.x().fieldT("month"),
vl.y().fieldQ("inspections")
)
const ManhattanChart = vl.markLine()
.data(ManhattanInspectionsByTime)
.title("Inspections over time in Manhattan")
.encode(
vl.x().fieldT("month"),
vl.y().fieldQ("inspections")
)
const StatenIslandChart = vl.markLine()
.data(StatenIslandInspectionsByTime)
.title("Inspections over time in Staten Island")
.encode(
vl.x().fieldT("month"),
vl.y().fieldQ("inspections")
)
return vl.vconcat(BrooklynChart, BronxChart, QueensChart, ManhattanChart, StatenIslandChart).render()
}