Public
Edited
Aug 6, 2024
2 stars
Insert cell
Insert cell
Insert cell
renderer = new Sigma.Sigma(graph, document.getElementById('sigma-container'));
Insert cell
Insert cell
Graph = require('graphology')
Insert cell
Sigma = require('https://bundle.run/sigma@2.0.0')
Insert cell
forceAtlas2 = require("https://bundle.run/graphology-layout-forceatlas2@0.8.1")
Insert cell
graphologyLayout = require("https://bundle.run/graphology-layout@0.4.0")
Insert cell
metrics = require('https://bundle.run/graphology-metrics@1.18.2')
Insert cell
Insert cell
assignLayouts = {
graphologyLayout.random.assign(graph); // Needs a starting layout for forceAtlas to work
let sensibleSettings = forceAtlas2.inferSettings(graph);
forceAtlas2.assign(graph, {iterations: 100, settings: sensibleSettings});
}
Insert cell
Insert cell
graph = {
let graph = new Graph({type: 'undirected'})
nodes.forEach(n => {
graph.addNode(n.Id);
});
edges.forEach(e => {
if (e.Weight > 10) {
graph.addEdge(e.Source,e.Target);
}
});
return graph
}
Insert cell
edges = FileAttachment("marvel-unimodal-edges.csv").csv()
Insert cell
nodes = FileAttachment("marvel-unimodal-nodes.csv").csv()
Insert cell
Insert cell
metrics.density(graph)
Insert cell
metrics.centrality.degree.assign(graph)
Insert cell
Insert cell
graph.forEachNode((n,attr) => {
graph.setNodeAttribute(n, "size", graph.degree(n)/10);
graph.setNodeAttribute(n, "label", n);
graph.setNodeAttribute(n, "color", colors[attr.community]);
});
Insert cell
graph.nodes().map(n => graph.getNodeAttributes(n));
Insert cell
Insert cell
louvain = require('https://bundle.run/graphology-communities-louvain@1.5.3')
Insert cell
louvain.assign(graph);
Insert cell
colors = ['#a6cee3','#1f78b4','#b2df8a','#33a02c','#fb9a99','#e31a1c']
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