Published
Edited
Jun 9, 2021
Insert cell
Insert cell
html`<div id="test" style="width:800px; height: 500px; border: 1px solid #888; background: #FCFCFC" />`

Insert cell
renderGraph(graphData)
Insert cell
md `## Build Hierarchical Graph`
Insert cell
graphData = ({ nodes: [nodesHierarchy], edges: GroMetGraph.edges });
Insert cell
constructRootNode(nodesHierarchy)
Insert cell
nodesHierarchy = hierarchyFn(GroMetGraph.nodes); // Transform the flat nodes structure into a hierarchical one

Insert cell
md `## Parse GroMEt`
Insert cell
GroMetGraph = {
const map = await mapGroMEt(gromet);
const graph = buildGraph(map);
return graph
}
Insert cell
Insert cell
hierarchyFn = d3.stratify()
.id((d) => d.id)
.parentId((d) => d.parent);
Insert cell
function changeKey (obj, before, after) {
if ({}.hasOwnProperty.call(obj, before)) {
obj[after] = obj[before];
delete obj[before];
obj[after].forEach(child => {
changeKey(child, before, after);
});
}
};
Insert cell
function constructRootNode(root) {
root.label = root.data.label;
root.concept = root.data.concept;
changeKey(root, 'children', 'nodes');

if (root.nodes) {
for (let i = 0; i < root.nodes.length; i++) {
constructRootNode(root.nodes[i]);
}
}
};
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gromet = (await FileAttachment("SimpleSIR_gromet_FunctionNetwork.json")).json()
Insert cell
Insert cell
import {renderGraph} from "@rosaromerogomez/svg-flow-graph-test"
Insert cell
import {parseJSONL} from "@darionco/parsejsonl"
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