Published
Edited
Oct 22, 2019
Importers
4 stars
Insert cell
Insert cell
function flatten(tree, sep = "/") {
const m = new Map();
for (const [key, value] of tree) {
if (value instanceof Map) {
for (const [key2, value2] of flatten(value, sep)) {
m.set(`${key}${sep}${key2}`, value2);
}
} else m.set(key, value);
}
return m;
}
Insert cell
data = Array.from({ length: 150000 }, word)
Insert cell
tree = d3.group(data, d => d[0], d => d[1], d => d[2])
Insert cell
flatten(tree)
Insert cell
Insert cell
flat = d3.group(data, d => d[0] + "/" + d[1] + "/" + d[2])
Insert cell
Insert cell
{
await visibility();
const sep = String.fromCharCode(0);
for (const [key, value] of flatten(tree, sep)) yield [key.split(sep), value];
}
Insert cell
Insert cell
d3 = require("d3-array@2")
Insert cell
char = () => String.fromCharCode(("a".charCodeAt(0) + 26 * Math.random()) | 0)
Insert cell
word = () => [char(), char(), char(), char(), char()].join("")
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