Published
Edited
Jul 4, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
colors=[ "#b0d5df","#64acbe", "#225886", "#e4acac", "#c85a5a", "#574249"]
Insert cell
swatches(colors)
Insert cell
Insert cell
x = d3.scaleQuantile(Array.from(municipalityData.values()), d3.range(n))
Insert cell
color = {
return value => {
if (!value) return "#e8e8e8";
return colors[x(value)];
};
}
Insert cell
colorGnBu = value => {
if (!value) return "#e8e8e8";
return d3.scaleSequential([0, d3.max(municipalityData.values())], d3.interpolateYlGnBu)(value)
}
Insert cell
Insert cell
Insert cell
swissEnergy = FileAttachment("swiss-energy-with-canton.json").json()
Insert cell
data = swissEnergy.results.bindings
Insert cell
municipalityData = new Map(data.map(x=> [+x.d_municipality_id.value, +x.d_total.value]))
Insert cell
cantonAvg = d3.rollup(data, v => {
return d3.mean(v, d=>+d.d_total?.value??0)
}, d => +d.d_canton_id?.value ?? 0)
Insert cell
cantonEnergyData = d3.group(data, d => d.d_canton_id?.value ?? 0)
Insert cell
Insert cell
mapData = ch_url
Insert cell
dataUrl = "https://swiss-maps-git-maintainance-ixt1.vercel.app/api/v0?year=2022&shapes=country,cantons,municipalities,lakes"
Insert cell
Insert cell
Insert cell
Insert cell
ch_url = d3.json(dataUrl)
Insert cell
Insert cell
ch_file = FileAttachment("ch.topojson.json").json()
Insert cell
Insert cell
function swatches(colors) {
return html`${colors.map(c => `<div title="${c}" style="
display: inline-block;
margin-right: 3px;
width: 33px;
height: 33px;
background: ${c};
"></div>`)}`;
}
Insert cell
Insert cell
Insert cell
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