viewof plot = {
const plot = Plot.plot({
marginBottom: 60,
height: 200,
width: 200,
x: { tickRotate: 45 },
y: { tickFormat: (d) => d3.format("0.2s")(d).replace(/G/, "B") },
style: {
backgroundColor: "white"
},
marks: [
Plot.barY(continents, {
fill: "Continent",
x: "Continent",
y: "Population",
sort: { x: "y", reverse: true },
title: (d) =>
`Continent: ${d.Continent}\nPopulation: ${d3.format(",")(
d.Population
)}\nCentroid ([lat,lng]): [${d.Latitude},${d.Longitude}]`
}),
Plot.ruleX([0])
]
});
d3.select(plot)
.selectAll("rect")
.on("click", function (event, i) {
plot.value = [continents[i].Latitude, continents[i].Longitude];
plot.dispatchEvent(new CustomEvent("input"));
});
plot.value = [];
return plot;
}