Published
Edited
May 31, 2022
Insert cell
Insert cell
Plot.plot({
width: width,
marginBottom: 50,
grid: true,
y: { percent: true, domain: [0, 100] },
marks: [
Plot.areaY(
dprs,
{ x: "dpr", y: "cumulativePercentOfSessions", fill: "steelblue", opacity: 0.75 }
),
Plot.ruleY([0])
]
})
Insert cell
data = FileAttachment("gov_uk_width_dpr.json").json()
Insert cell
processedData = data.map(o => ({
dpr: o.dpr,
sessionsPercent: o.sessions / totalSessions
}))
Insert cell
dprs = {
let results = [];
for( let i = 0.01; i < maxDPR; i += 0.01 ) {
results.push( {
dpr: i,
cumulativePercentOfSessions: processedData
.filter( d => d.dpr <= i )
.reduce( ( acc, cv ) => acc += cv.sessionsPercent, 0 )
} );
}
return results;
}
Insert cell
totalSessions = data.reduce( ( totalSessions, o ) => {
return totalSessions + o.sessions;
}, 0 )
Insert cell
maxDPR = d3.max( data, d => d.dpr )
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