<div id="sigma-container"></div>
import Graph from "graphology";
import Sigma from "sigma";
import { DEFAULT_STYLES } from "sigma/types";
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();
const graph = new Graph();
for (const node of dataset.nodes) {
graph.addNode(node.key, {
for (const [source, target] of dataset.edges) {
if (graph.hasNode(source) && graph.hasNode(target) && !graph.hasEdge(source, target)) {
graph.addEdge(source, target);
const clusterColors = Object.fromEntries(dataset.clusters.map((c) => [c.key, c.color]));
const { minScore, maxScore } = dataset.nodes.reduce(
({ minScore, maxScore }, { score }) => ({
minScore: Math.min(minScore, score),
maxScore: Math.max(maxScore, score),
{ minScore: Infinity, maxScore: -Infinity },
const renderer = new Sigma(graph, document.getElementById("sigma-container") as HTMLElement, {
size: { attribute: "score", min: 10, max: 50, minValue: minScore, maxValue: maxScore },
label: { attribute: "label" },
edges: [DEFAULT_STYLES.edges, { color: "#ccc", size: 5 }],