Public
Edited
Jul 14, 2020
10 forks
Importers
36 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {
const root = {value: [0, 1]};
const queue = [root];
let p, size = 0, n = 1 << 6;
while (++size < n && (p = queue.shift())) {
const k = p.value.length - 1;
const a = {value: p.value.slice(0, k).concat(p.value[k] + 1)};
const b = {value: p.value.slice(0, k).concat(p.value[k] - 1, 2)};
p.children = k & 1 ? [a, b] : [b, a];
queue.push(a, b);
}
return root;
}
Insert cell
function collapse(f) {
let n = 1, d = 0, i = f.length;
while (--i >= 0) [n, d] = [f[i] * n + d, n];
return [n, d];
}
Insert cell
tree = data => d3.tree()
.size([width, height - margin * 2])
.separation(() => 1)
(d3.hierarchy(data))
Insert cell
width = 954
Insert cell
height = 600
Insert cell
margin = 20
Insert cell
d3 = require("d3@5")
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