Public
Edited
Nov 28, 2020
Importers
5 stars
Insert cell
Insert cell
Insert cell
object2Tree = {
return function rec(node, name = 'node') {
if (Array.isArray(node)) {
const children = node.map((value, i) => rec(value, `#${i}`));
return { name, children };
} else if (typeof node == 'object') {
const children = Object.entries(node).map(([key, value]) =>
rec(value, key)
);
return { name, children };
} else {
const value = typeof node == 'string' ? `"${node}"` : node;
return { name: `${name} = ${value}`, value };
}
};
}
Insert cell
factory = notebookFactory("@d3/collapsible-tree")
Insert cell
objectTree = object => factory('chart', { data: object2Tree(object) })
Insert cell
objectTree({ test: 12, test2: [12, 13, 14], sub: { value: 'splonge' } })
Insert cell
import { notebookFactory } from '@asg017/notebook-factory'
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