Public
Edited
Feb 19, 2024
Importers
2 stars
Insert cell
Insert cell
ForceGraph(graphologyToD3(d3ToGraphology(miserables)), {
nodeId: (d) => d.id, // node identifier, to match links
nodeGroup: (d) => d.group, // group identifier, for color
nodeTitle: (d) => d.id, // hover text
width,
height: 520,
invalidation // stop when the cell is re-run
})
Insert cell
miserables
Insert cell
graphologyMiserables = d3ToGraphology(miserables)
Insert cell
restoredMiserables = graphologyToD3(graphologyMiserables)
Insert cell
graphologyToD3 = (
graphologyGraph,
{ nodeList = "nodes", edgeList = "links" } = {}
) => {
const outJSON = graphologyGraph.toJSON();
const d3JSON = {
[nodeList]: outJSON.nodes.map((d) => d.attributes),
[edgeList]: outJSON.edges.map((d) => d.attributes)
};
return d3JSON;
}
Insert cell
d3ToGraphology = (
graphData,
{
nodeList = "nodes",
edgeList = "links",
nodeId = "id",
edgeSource = "source",
edgeTarget = "target",
graphAttributes = {}
} = {}
) => {
const graph = new graphology(graphAttributes);
const modifiedData = 1;
graph.import({
nodes: graphData[nodeList].map((n) => ({ key: n[nodeId], attributes: n })),
edges: graphData[edgeList].map((e) => ({
source: e[edgeSource],
target: e[edgeTarget],
attributes: e
})),
attributes: graphAttributes
});
return graph;
}
Insert cell
graphology = require("graphology")
Insert cell
import {ForceGraph} from "@d3/force-directed-graph"
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