function BumpChart(
data,
{
x = "month",
y = "rating",
z = "name",
interval = "month",
reverse = false,
title,
width
} = {}
) {
const rank = Plot.stackY2({ x, z, order: y, reverse: reverse });
const [xmin, xmax] = d3.extent(Plot.valueof(data, x));
return Plot.plot({
width,
title: title,
marginLeft: 70,
marginRight: 70,
x: {
[width < 480 ? "insetRight" : "inset"]: 120,
label: null,
grid: true
},
y: {
axis: null,
inset: 20,
reverse: true
},
color: {
scheme: "spectral"
},
marks: [
Plot.lineY(
data,
Plot.binX(
{ x: "first", y: "first", filter: null },
{
...rank,
stroke: z,
strokeWidth: 24,
curve: "bump-x",
sort: { color: "y", reduce: "first" },
interval,
render: halo({
stroke: "var(--theme-background-alt)",
strokeWidth: 27
})
}
)
),
Plot.text(data, {
...rank,
text: rank.y,
fill: "black",
stroke: z,
channels: {
[y]: y,
"title\0": (d) => d.title
},
tip: { format: { y: null, text: null } }
}),
width < 480
? null
: Plot.text(data, {
...rank,
filter: (d) => d[x] <= xmin,
text: z,
dx: -20,
textAnchor: "end"
}),
Plot.text(data, {
...rank,
filter: (d) => d[x] >= xmax,
text: z,
dx: 20,
textAnchor: "start"
})
]
});
}