<div id="sigma-container"></div>
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@4.5.0/dist/maplibre-gl.css" />
<style>
#sigma-container {
width: 100%;
height: 100%;
}
</style>
<script>
import bindMaplibreLayer from "@sigma/layer-maplibre";
import Graph from "graphology";
import { nodeExtent } from "graphology-metrics/graph";
import type { Attributes, SerializedGraph } from "graphology-types";
import Sigma from "sigma";
import { DEFAULT_STYLES } from "sigma/types";
const container = document.getElementById("sigma-container") as HTMLElement;
const res = await fetch("/data/airports.json");
const data = await res.json();
const graph = Graph.from(data as SerializedGraph);
graph.updateEachNodeAttributes((node, attributes) => ({
...attributes,
label: attributes.fullName,
degree: graph.degree(node),
x: 0,
y: 0,
}));
const [minDegree, maxDegree] = nodeExtent(graph, "degree");
const renderer = new Sigma(graph, container, {
settings: {
labelRenderedSizeThreshold: 20,
minEdgeThickness: 1,
},
styles: {
edges: [DEFAULT_STYLES.edges, { color: "#ffaeaf", size: 0.0001 }],
nodes: [
DEFAULT_STYLES.nodes,
{
color: "#e22352",
size: {
attribute: "degree",
min: 0.001,
max: 0.005,
minValue: minDegree,
maxValue: maxDegree,
},
},
],
},
});
bindMaplibreLayer(renderer, {
getNodeLatLng: (attrs: Attributes) => ({ lat: attrs.latitude, lng: attrs.longitude }),
});
</script>