{
let data = d3.range(10).map(d3.randomInt(1, 10));
let M = d3.max(data);
let m = d3.min(data);
let plot = Plot.plot({
marks: [
Plot.barY(data, {
x: (_, i) => i,
fill: (d) => d,
title: (d) => d
}),
Plot.ruleY([0])
]
});
let nodes = d3
.select(plot)
.selectAll("rect")
.on("pointerenter", function () {
d3.select(this).attr("stroke-width", "2px").attr("stroke", "black");
})
.on("pointerleave", function () {
d3.select(this).attr("stroke", null);
})
.nodes()
.forEach(function (bar) {
let value = d3.select(bar).select("title").text();
if (value == M) {
tippy(bar, {
content: `The max is ${M}!`
});
} else if (value == m) {
tippy(bar, {
content: `The min is ${m}!`
});
}
});
d3.select(plot).selectAll("rect").select("title").remove();
return plot;
}