{
const chart = Plot.plot({
marks: [
Plot.barY(byState, {
x: "state",
y: "population",
sort: { x: "y", reverse: true },
opacity: 0.1
}),
Plot.dot(
byState,
Plot.pointerX({
x: "state",
y: "population",
fill: "black",
r: 5,
sort: { x: "y", reverse: true },
render(index, scales, values, dimensions, context, next) {
const g = next(index, scales, values, dimensions, context);
g.addEventListener("pointermove", (event) => {
event.stopImmediatePropagation();
const i = event.target.__data__;
console.log({ i, index });
d3.select(context.ownerSVGElement)
.append("circle")
.attr("r", 10)
.attr("stroke", "red")
.attr("fill", "none")
.attr("cx", values.x[i] + scales.scales.x.bandwidth / 2)
.attr("cy", values.y[i]);
});
return g;
}
})
)
],
width
});
return chart;
}