Public
Edited
Nov 9, 2022
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof table1 = Inputs.table(fullData)
Insert cell
Insert cell
pp = (d) => JSON.stringify(d.map(massageData), 2, 2)
Insert cell
pp1 = (d) => JSON.stringify(massageData(d), 2, 2)
Insert cell
Insert cell
massageData = d => {
let {id, name, occupation, gender, hpi, birthdate, deathdate, slug, bplace_country, description} = d;

let link = `https://wikipedia.org/wiki/${slug}`;

if (birthdate == "") {
birthdate = `${d.birthyear}-01-01`;
}
if (deathdate == "") {
deathdate = `${d.deathyear}-01-01`;
}

return {id, name, occupation, gender, hpi, birthdate, deathdate, slug, bplace_country, link, description};
}
Insert cell
initialPeople = ["George Washington","Winston Churchill","Abraham Lincoln","John D. Rockefeller","George III","Louis XVI","Thomas Edison","Johannes Gutenberg","Christopher Columbus","Kepler","Marco Polo","Isaac Newton","Benjamin Franklin","John Harrison","Napoleon","Queen Victoria","George VI","Elizabeth II","Galileo","Da Vinci","Martin Luther","Henry VIII","Oliver Cromwell","Jesus","Plato","Julius Caesar","Alexander the Great","Muhammad","Buddha"]
Insert cell
matched = {
const ms = [];
const names = new Set(top1k.map(p => p.name));
const slugs = new Set(top1k.map(p => p.slug))

const remaps = {
"Louis XVI": "Louis XVI of France",
"George III": "George III of the United Kingdom",
"Kepler": "Johannes Kepler",
"Galileo": "Galileo Galilei",
"Da Vinci": "Leonardo da Vinci",
"Henry VIII": "Henry VIII of England",
"Buddha": "Gautama Buddha",
}
return initialPeople.map(n => ({name: remaps[n] || n, needs_fetch: (!names.has(n) && !names.has(remaps[n]))}))
}
Insert cell
top1k_by_name = top1k.reduce((acc, d) => {acc[d.name] = d; return acc}, {})
Insert cell
Inputs.button("copy to clipboard", {value: null, reduce: () => navigator.clipboard.writeText(pp(enriched))})
Insert cell
enriched = {
const ds = matched.filter(d => !d.needs_fetch).map(d => top1k_by_name[d.name])

return ds;

}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
fetched[0].famous_for
Insert cell
fText = pp1(fetched[0])
Insert cell
Insert cell
viewof searchTop = Inputs.table(top1k.slice(0, 100))
Insert cell
Inputs.button("copy selection", {value: null, reduce: () => navigator.clipboard.writeText(pp(searchTop))})
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