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

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