Published
Edited
Sep 29, 2020
4 stars
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
num_employees = 30
Insert cell
employees = sequence(num_employees+1)
Insert cell
share_fib = sequence(num_employees+1, fibonacci)
Insert cell
share_total = total(share_fib)
Insert cell
share_percent = employees.map(e => Array(e).fill(0).map((v,i) => (share_fib[i+1] / share_total[e])))
Insert cell
newb_share = share_percent.slice(1).map((v,i) => ({x:i+1, y:v[0]}))
Insert cell
tail_start = 20
Insert cell
tail = share_percent.slice(tail_start,share_percent.length).map(v => (v.length > 1 ? [v[0],v[v.length-1]] : v.length > 0 ? [0, v[0]] : [0,0]))
Insert cell
share_dollars = (dollars, employee, share=1) => commas(nice(dollars * share_percent[employee][share-1], 0))
Insert cell
table_style = html`
<style>
table { font-family: Georgia, serif; }
table i { color: slategrey; font-size: smaller; }
td:first-child { color: firebrick; text-align: right; padding-right: .5em; }
td:nth-child(2) { text-align: center; }
td:nth-child(3) { padding-left: .5em; }
td:nth-child(4) { width: 60%; }
</style>
`
Insert cell
Insert cell
function fibonacci(n) {
if (n === 0 || n === 1) return n;
let f, g = [0,1];
while (n-- > 1) {
f = g[1] + g.shift();
g.push(f);
}
return f;
}
Insert cell
sequence = (n, f=(i=>i)) => Array(n).fill(0).map((v,i) => f(i));
Insert cell
total = (a) => a.map((v,i,a) => a.slice(0,i+1).reduce((a,c) => a+c, 0))
Insert cell
nice = (n, d=3, p=0) => {
const m = n - Math.floor(n);
const i = (d === 0 && m >= 0.5) ? Math.ceil(n) : Math.floor(n);
let si = i.toString();
while (si.length < p) si = '0' + si;
let sm = (Math.round(m * Math.pow(10, d)) / Math.pow(10, d)).toString().substring(2);
while (sm.length < d) sm += '0';
return si + (d > 0 ? '.' +sm : '');
}
Insert cell
[nice(1.4498354102), nice(1.449, 2), nice(1.9, 0, 3), nice(.009)]
Insert cell
commas = (n) => n.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
Insert cell
[commas(1), commas(123.98), commas(1234.56), commas(Math.pow(10,6))]
Insert cell
import {hbar_stack_norm} from '@ellemenno/horizontal-stacked-normalized-bar-chart'
Insert cell
import {line_chart} from '@ellemenno/line-chart'
Insert cell
d3 = require("d3@6")
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