Plot.plot({
width,
height: 800,
marks: [
Plot.dot(filteredPenguins, {
x: "culmen_length_mm",
y: "culmen_depth_mm"
}),
Plot.dot(
filteredPenguins,
Plot.pointer({
x: "culmen_length_mm",
y: "culmen_depth_mm",
render: (index, scales, values, dimensions, context, next) => {
const svg = d3.select(context.ownerSVGElement);
const circles = svg.selectAll("[aria-label=dot] circle");
if (index.length) {
const x = values.x[index[0]];
const y = values.y[index[0]];
circles
.style("stroke", "blue")
.style("fill", "red")
.attr("r", 8)
.filter((i) => values.x[i] != x || values.y[i] != y)
.style("stroke", null)
.style("fill", null)
.attr("r", 3)
.raise();
} else circles.style("stroke", null).style("fill", null).attr("r", 3);
return next(index, scales, values, dimensions, context);
}
})
),
Plot.tip(
filteredPenguins,
Plot.pointer({
x: "culmen_length_mm",
y: "culmen_depth_mm"
})
)
]
})