<div id="sigma-container"></div>
import Graph from "graphology";
import Sigma from "sigma";
import { registerControls } from "../_controls";
import { sdfSquare } from "sigma/rendering";
import { DEFAULT_STYLES } from "sigma/types";
const container = document.getElementById("sigma-container") as HTMLElement;
const { autoRescale, itemSizesReference, zoomScaling } = registerControls({
{ label: "true", value: "true" },
{ label: "false", value: "false" },
{ label: "once", value: "once" },
label: "itemSizesReference",
{ label: "screen", value: "screen" },
{ label: "positions", value: "positions" },
label: "zoomToSizeRatioFunction",
{ label: "sqrt (default)", value: "sqrt" },
{ label: "linear", value: "linear" },
{ label: "constant", value: "constant" },
const ZOOM_FUNCTIONS: Record<string, (ratio: number) => number> = {
linear: (ratio: number) => ratio,
const graph = new Graph();
// Grid layout with varying sizes
const COLORS = ["#e22653", "#277da1", "#33cc33", "#ff9900", "#9b59b6", "#1abc9c"];
for (let row = 0; row < ROWS; row++) {
for (let col = 0; col < COLS; col++) {
const id = `${row}-${col}`;
color: COLORS[(row + col) % COLORS.length],
if (col > 0) graph.addEdge(`${row}-${col - 1}`, id);
if (row > 0) graph.addEdge(`${row - 1}-${col}`, id);
let autoRescaleValue: boolean | "once";
if (autoRescale === "true") autoRescaleValue = true;
else if (autoRescale === "once") autoRescaleValue = "once";
else autoRescaleValue = false;
new Sigma(graph, container, {
autoRescale: autoRescaleValue,
itemSizesReference: itemSizesReference as "screen" | "positions",
zoomToSizeRatioFunction: ZOOM_FUNCTIONS[zoomScaling],