Public
Edited
Nov 16, 2021
5 forks
6 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
noverlap = require("https://bundle.run/graphology-layout-noverlap@0.4.1")
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});
noverlap.assign(graph)
}
Insert cell
Insert cell
graph = {
let graph = new Graph({type: 'undirected'})
nodes.forEach(n => {
graph.addNode(n.id);
});
edges.forEach(e => {
graph.addEdge(e.source,e.target);
});
return graph
}
Insert cell
edges = FileAttachment("got-edges.csv").csv()
Insert cell
nodes = FileAttachment("got-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));
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
Insert cell
// Bind graph interactions:
renderer.on("enterNode", ({ node }) => {
graph.forEachNode((n,attr) => {
graph.setNodeAttribute(n, "color", "#999");
});
graph.forEachNeighbor(node, (n, attr) => {
graph.setNodeAttribute(n, "color", colors[attr.community]);
});
graph.setNodeAttribute(node, "color", colors[graph.getNodeAttribute(node, "community")]);
});

Insert cell
renderer.on("leaveNode", ({ node }) => {
graph.forEachNode((n,attr) => {
graph.setNodeAttribute(n, "color", colors[attr.community]);
});
});
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