Plot.plot({
width,
height: 800,
y: {
label: "↑ Unemployed (thousands)"
},
marks: [
Plot.line(
industries,
Plot.windowY({
x: "date",
y: "unemployed",
stroke: "lightgrey",
z: "industry",
k: 10
})
),
Plot.line(
industries,
Plot.pointerX(
Plot.windowY({
x: "date",
y: "unemployed",
z: "industry",
k: 10,
render: (index, scales, values, dimensions, context, next) => {
const path = d3
.select(context.ownerSVGElement)
.selectAll("[aria-label=line] path");
if (index.length) {
const z = values.z[index[0]];
path
.style("stroke", "black")
.filter(([i]) => values.z[i] != z)
.style("stroke", null)
.raise();
} else path.style("stroke", null);
return next(index, scales, values, dimensions, context);
}
})
)
),
Plot.tip(
industries,
Plot.pointerX(
Plot.windowY({
x: "date",
y: "unemployed",
z: "industry",
k: 10
})
)
),
Plot.ruleY([0])
]
})