<div id="sigma-container"></div>
import Graph from "graphology";
import Sigma from "sigma";
import { extremityArrow, layerPlain, pathCurved, pathLine, pathStepCurved } from "sigma/rendering";
import { DEFAULT_STYLES } from "sigma/types";
import type { EdgeLabelFontSizeMode, EdgeLabelPosition } from "sigma/types";
import { registerControls } from "../_controls";
const container = document.getElementById("sigma-container") as HTMLElement;
// Each column demonstrates one label styling variation. The first four use
// text borders for readability; the last one uses a label background
// (ribbon) instead — both styles live side by side.
{ position: "over" as EdgeLabelPosition, background: false, label: "over / border" },
{ position: "above" as EdgeLabelPosition, background: false, label: "above / border" },
{ position: "below" as EdgeLabelPosition, background: false, label: "below / border" },
{ position: "auto" as EdgeLabelPosition, background: false, label: "auto / border" },
{ position: "over" as EdgeLabelPosition, background: true, label: "over / background" },
{ name: "straight", label: "Straight" },
{ name: "curved", label: "Curved" },
{ name: "stepCurved", label: "Step Curved" },
const EDGE_COLOR = "#5B8FF9";
const LABEL_BACKGROUND_COLOR = "#c3d2f1";
const { fontSizeMode, headType, tailType } = registerControls({
{ label: "Fixed", value: "fixed" },
{ label: "Scaled", value: "scaled" },
{ label: "None", value: "none" },
{ label: "Arrow", value: "arrow" },
{ label: "None", value: "none" },
{ label: "Arrow", value: "arrow" },
const graph = new Graph();
for (let row = 0; row < PATHS.length; row++) {
for (let col = 0; col < COLS.length; col++) {
const pathInfo = PATHS[row];
const colInfo = COLS[col];
const cellX = col * COL_SPACING;
const cellY = -row * ROW_SPACING;
const sourceId = `${pathInfo.name}-${col}-source`;
graph.addNode(sourceId, {
x: cellX - NODE_SPACING / 2,
const targetId = `${pathInfo.name}-${col}-target`;
graph.addNode(targetId, {
x: cellX + NODE_SPACING / 2,
y: cellY + NODE_SPACING / 2,
graph.addEdge(sourceId, targetId, {
label: `${pathInfo.label} / ${colInfo.label}`,
labelPosition: colInfo.position,
curvature: pathInfo.name === "curved" ? 0.3 : 0,
labelBackground: colInfo.background,
new Sigma(graph, container, {
paths: [pathLine(), pathCurved(), pathStepCurved({ cornerRadius: 1 })],
extremities: [extremityArrow()],
defaultHead: headType === "none" ? undefined : headType,
defaultTail: tailType === "none" ? undefined : tailType,
variables: { curvature: { type: "number", default: 0 } },
fontSizeMode: fontSizeMode as EdgeLabelFontSizeMode,
textBorder: { width: 12, color: "#ffffff" },
nodes: [DEFAULT_STYLES.nodes, { size: 6, color: "darkgrey", label: "" }],
path: { attribute: "path" },
labelVisibility: "visible",
labelPosition: { attribute: "labelPosition", defaultValue: "over" },
whenData: "labelBackground",
labelBackgroundColor: LABEL_BACKGROUND_COLOR,
labelBackgroundPadding: 4,
itemSizesReference: "positions",