Public
Edited
May 8, 2022
2 stars
Insert cell
Insert cell
<svg width="600" height="600">
<g id="packCircles"></g>
<g id="donuts"></g>
</svg>
Insert cell
Insert cell
Insert cell
Insert cell
rollupData = d3.rollups(powerplants_2019, v => d3.sum(v, d => toNum(d["Plant annual net generation (MWh)"])), d => d["Plant state abbreviation"]).sort((a,b) => d3.descending(a[1],b[1]))
Insert cell
dataLayout = layoutChildren("powerplants", rollupData);
Insert cell
pcLayer = d3.select(svgContainer).select("#packCircles")
Insert cell
packCircles = dvPackCircles(pcLayer,dataLayout,600,600,'',options)
Insert cell
options = ({
padding: 1,
textLabelField: "Plant state abbreviation"
})
Insert cell
Insert cell
Insert cell
donutLayer = d3.select(svgContainer).select("#donuts")
Insert cell
Insert cell
stateFuels = d3.rollups(powerplants_2019, v => d3.sum(v, d => toNum(d["Plant annual net generation (MWh)"])), d => d["Plant state abbreviation"], d => d["Plant primary fuel generation category"])
Insert cell
Insert cell
pcLayer.selectAll("circle").each((d,i,nodes) => {
if (packCircles) {} // a dummy dependency to have it wait until the packCircles is done.

if (Array.isArray(d.data)) {
let thisState = d.data[0];
let thisX = d.x; // just to call these out specifically to understand what we're doing.
let thisY = d.y;
let thisR = d.r;
let thisStateData = stateFuels.find(s => s[0] == thisState)[1];
let donutGroup = donutLayer.select("g[id=d_thisState]").node()
? donutLayer.select("g[id=d_thisState]")
: donutLayer.append("g").attr("id","d_"+thisState);
donutGroup.attr("transform", "translate(" + thisX + " " + thisY + ")");
let options = {
translateXY:{x:0,y:0}
}
let donut = dvDonut(donutGroup, thisStateData, thisR, thisR/2,options);
}
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more