<div id="sigma-container"></div>
import { bindWebGLLayer, createHeatmapProgram } from "@sigma/layer-webgl";
import Graph from "graphology";
import { parse } from "graphology-gexf/browser";
import Sigma, { DEFAULT_DEPTH_LAYERS } from "sigma";
import { registerControls } from "../_controls";
const container = document.getElementById("sigma-container") as HTMLElement;
const res = await fetch("/data/arctic.gexf");
const gexf = await res.text();
const graph = parse(Graph, gexf);
// Style all nodes and edges white
graph.forEachNode((node) => {
graph.setNodeAttribute(node, "color", "#ffffff");
const renderer = new Sigma(graph, container, {
depthLayers: ["heatmap", ...DEFAULT_DEPTH_LAYERS],
edgeReducer: (_key, data) => (showEdges ? data : { ...data, visibility: "hidden" }),
const HEATMAP_COLOR_STOPS = [
{ value: 0.1, color: "#ffffff" },
{ value: 1, color: "#fdcc8a" },
{ value: 10, color: "#e34a33" },
{ value: 100, color: "#b30000" },
{ value: 1000, color: "#500000" },
const HEATMAP_SHADING = {
let cleanHeatmap: (() => void) | null = null;
function rebuildHeatmap() {
container.style.backgroundColor = "#333333";
container.style.backgroundColor = "#ffffff";
cleanHeatmap = bindWebGLLayer(
createHeatmapProgram(graph.nodes(), {
colorStops: HEATMAP_COLOR_STOPS,
getWeight: (node) => graph.degree(node),
shading: shadingOn ? HEATMAP_SHADING : undefined,
const { setToggle, setDisabled } = registerControls({
action: (active: boolean) => {
setDisabled("shading", !heatmapOn);
action: (active: boolean) => {
action: (active: boolean) => {