chart = addTooltips(
Plot.plot({
projection: "albers-usa",
marks: [
Plot.geo(states, { fill: "#dbdbdb", stroke: "white" }),
Plot.dot(power_plants, {
x: "longitude",
y: "latitude",
r: "total_capacity",
fill: "primary_source",
title: (d) =>
`Plant name: ${d.plant}\nPrimary source: ${
d.primary_source
}\nTotal capacity: ${d3.format(",")(d.total_capacity)} MW`,
opacity: 0.5
}),
Plot.text(
states.features,
Plot.centroid({
fill: "currentColor",
fontWeight: 600,
strokeWidth: 1.5,
stroke: "white",
filter: (d) => !pick.includes(d.properties.name),
text: (d) => abbreviations.get(d.properties.name)
})
),
Plot.text(
states.features,
Plot.centroid({
textAnchor: "start",
dx: 10,
fill: "currentColor",
fontWeight: 600,
strokeWidth: 1.5,
stroke: "white",
filter: (d) => pick.includes(d.properties.name),
text: (d) => abbreviations.get(d.properties.name)
})
),
legendBubble2([50, 500, 2000, 5000]),
sources.map(
(source, i) => [
Plot.dot([1], {
frameAnchor: "left",
r: 7,
fill: [source],
dy: i * 20 - 45,
dx: 695
}),
Plot.text([1], {
frameAnchor: "left",
text: [source.replaceAll(/\b\w/g, (l) => l.toUpperCase())],
dy: i * 20 - 45,
dx: 705
})
]
)
],
r: { range: [0, maxBubbleSize] },
color: {
domain: sources,
range: [
"#f78a29",
"#535353",
"#ce499a",
"#027fc5",
"#ed1a25",
"#11b14b",
"#d5c843",
"#ffecd7"
]
},
height: Math.round(mapWidth * 5 / 8),
width: mapWidth,
marginRight: 60
})
)