<div id="sigma-container"></div>
import Graph from "graphology";
import Sigma from "sigma";
// Describe the dataset shape
nodes: { key: string; label: string; tag: string; cluster: string; x: number; y: number; score: number }[];
edges: [string, string][];
clusters: { key: string; color: string; clusterLabel: string }[];
const response = await fetch("/data/wikipedia.json");
const dataset: Dataset = await response.json();
// Index clusters by key for quick lookup
const clustersByKey = Object.fromEntries(dataset.clusters.map((c) => [c.key, c]));
// Build a graphology graph from the dataset
const graph = new Graph();
for (const node of dataset.nodes) {
const cluster = clustersByKey[node.cluster];
graph.addNode(node.key, {
color: cluster?.color ?? "#999",
size: 10 + node.score * 1000,
for (const [source, target] of dataset.edges) {
if (graph.hasNode(source) && graph.hasNode(target) && !graph.hasEdge(source, target)) {
graph.addEdge(source, target);
new Sigma(graph, document.getElementById("sigma-container") as HTMLElement);