Published
Edited
Jul 22, 2021
2 forks
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
nodelink(links)
Insert cell
Insert cell
Insert cell
nodelink(treeifyLinks(links))
Insert cell
Insert cell
activeNodeIds = ['tidal creek', 'river', 'hypoxic lake']
Insert cell
pruneIrrelevantNodes = (links, activeNodeIds) => {
const g = new Graph(links);

activeNodeIds.forEach(nodeId => {
let currentNode = g.nodeMap[nodeId];
while (currentNode) {
currentNode.relevant = true;
currentNode = g.nodeMap[currentNode.out[0]];
}
});
Object.values(g.nodeMap).forEach(node => {
if (!node.relevant) {
g.removeNode(node);
}
});
return g.toLinks();
}
Insert cell
nodelink(pruneIrrelevantNodes(treeifyLinks(links), activeNodeIds))
Insert cell
shortenPaths = (links, activeNodeIds) => {
const g = new Graph(links);

let changed = true;
while (changed) {
changed = false;
let nodes = Object.values(g.nodeMap);
for (let node of nodes) {
if (node.in.length === 1 && node.out.length === 1) {
const nodeIn = g.nodeMap[node.in[0]];
const nodeOut = g.nodeMap[node.out[0]];
if (!activeNodeIds.includes(node.id)) {
g.removeNode(node);
g.addLink(nodeIn, nodeOut);
delete g.nodeMap[node.id];
changed = true;
}
}
}
}

return g.toLinks();
}
Insert cell
Insert cell
simplifyOntology = (links, activeNodesIds) => {
return shortenPaths(pruneIrrelevantNodes(treeifyLinks(links), activeNodeIds), activeNodeIds);
}
Insert cell
nodelink(simplifyOntology(links, activeNodeIds))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
height = 500
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more