Public
Edited
Apr 12, 2022
1 fork
1 star
Insert cell
Insert cell
<svg id="base" width="1000" height="650">
<g id="layer1"></g>
</svg>
Insert cell
Insert cell
import {powerplants_2019} from "@emfielduva/dvlib_sampledata"
Insert cell
Insert cell
rollupData = d3.rollups(powerplants_2019, v => d3.sum(v, d => toNum(d["Plant annual net generation (MWh)"])), d => d["Plant primary fuel generation category"]).sort((a,b)=>d3.descending(a[1],b[1]));
Insert cell
Insert cell
import {layoutChildren} from "@emfielduva/dvlib_layout"
Insert cell
dataLayout1 = layoutChildren("powerplants",rollupData)
Insert cell
tmElem = d3.select(svgContainer).select("#layer1")
Insert cell
tm1 = dvTreemap(tmElem,dataLayout1,800,600,'',options1)
Insert cell
options1 = ({
textLabelField: 'name'
})
Insert cell
Insert cell
Insert cell
Insert cell
sortedData = d3.sort(powerplants_2019, (a,b) => d3.ascending(a["Plant primary fuel generation category"],b["Plant primary fuel generation category"]))
Insert cell
dataLayout2 = layoutChildren("powerplants", sortedData);
Insert cell
options2 = ({
classField: 'Plant primary fuel generation category'
})
Insert cell
tm2 = dvTreemap(tmElem2,dataLayout2,800,600,"Plant annual net generation (MWh)",options2)
Insert cell
tmElem2 = d3.select(svgContainer2).select("#layer1")
Insert cell
Insert cell
<svg id="base" width="1000" height="650">
<g id="layer1"></g>
</svg>
Insert cell
Insert cell
Insert cell
rollupDataTwoLevel = 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
dataLayout3 = layoutChildren("powerplants",rollupDataTwoLevel)
Insert cell
options3 = ({
textLabelField: 'name',
paddingInner: 3
})
Insert cell
tmElem3 = d3.select(svgContainer3).select("#layer1")
Insert cell
tm3 = dvTreemap(tmElem3,dataLayout3,800,600,'',options3)
Insert cell
<svg id="base" width="1000" height="650">
<g id="layer1"></g>
</svg>
Insert cell
Insert cell
import {toNum} from "@emfielduva/dvlib"
Insert cell
import {dvTreemap} from "@emfielduva/dvlib_layout"
Insert cell
<style>
.COAL {fill:#000000; background-color:#000000; color: #dddddd;} /* black */
.BIOMASS {fill:#00ff00; background-color:#00ff00;} /* green */
.HYDRO {fill:#0000ff; background-color:#0000ff; color: #dddddd;} /* blue */
.OIL {fill:#777700; background-color:#777700;} /* brown */
.GAS {fill:#E8BD0C; background-color:#E8BD0C;} /* orange */
.NUCLEAR {fill:#00ffff; background-color:#00ffff;} /* cyan */
.GEOTHERMAL {fill:#A6A277; background-color:#A6A277;} /* brown */
.WIND {fill: #FF66FF; background-color: #FF66FF;} /* pink */
.SOLAR {fill: #ffff00; background-color: #ffff00;} /* yellow */
.OFSL {fill: #888888; background-color: #888888;} /* gray */
.OTHF {fill: #aa0000; background-color: #aa0000;} /* gray */
.OTHRFOSL {fill: #888888; background-color: #888888;} /* gray */
.WSTHTOTPUR {fill: #aa0000; background-color: #aa0000;} /* gray */
.node text {font-size: 12px; fill: white;}
</style>
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more