Public
Edited
Feb 19
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
vals = d3.range(5)
Insert cell
dist = [0.2,0.3,.15,.25,.1]
Insert cell
avg = d3.sum(d3.zip(vals,dist).map(([a,b])=>a*b))
Insert cell
rcdist = d3.reverse(d3.cumsum(d3.reverse(dist)))
Insert cell
mutable choice=0
Insert cell
makeRects = (val) => [...rcdist,0].slice(val+1).map((cprob,i) =>
svg`<rect x=${val*rwidth} y=${cprob} width=${rwidth} height=${dist[val+i]} fill=${rcolor(val, val+i)}
style="stroke:white;stroke-width:0.01">`)
Insert cell
makeText = (x,y,t,s) => svg`<g transform="translate(${x},${y}) scale(0.004,-0.004)">
<text style="${s}font-family:sans-serif">${t}</text></g>`
Insert cell
rwidth = 1/vals.length
Insert cell
rc_avg = d3.sum(rcdist.slice(1))
Insert cell
cdist = d3.cumsum(dist)
Insert cell
c_avg = 4 - d3.sum(cdist.slice(0,-1))
Insert cell
color = d3.scaleOrdinal(d3.schemeCategory10)
Insert cell
rcolor = (v,i) => v==0?'#eeeeee': color(choice?i:v)
Insert cell
tcolor = (nr,i) => (choice==nr && i>0) ? color(i) : "#000000"
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