Plot.plot(
(() => {
const n = 3;
const keys = Array.from(d3.union(industries.map((d) => d.industry)));
const index = new Map(keys.map((key, i) => [key, i]));
const fx = (key) => index.get(key) % n;
const fy = (key) => Math.floor(index.get(key) / n);
return {
height: 600,
axis: null,
y: { insetTop: 10, nice: false, grid: true },
fx: { padding: 0.1 },
fy: { padding: 0.25 },
marks: [
Plot.axisY({ anchor: "right" }),
Plot.lineY(industries, {
x: "date",
y: "unemployed",
fx: (d) => fx(d.industry),
fy: (d) => fy(d.industry)
}),
Plot.text(keys, {
fx,
fy,
frameAnchor: "top-left",
fontWeight: "bold",
fontSize: 13,
dx: 0,
dy: -5
})
]
};
})()
)