<div id="sigma-container"></div>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
#sigma-container {
width: 100%;
height: 100%;
}
</style>
<script>
import bindLeafletLayer from "@sigma/layer-leaflet";
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,
},
},
],
},
});
bindLeafletLayer(renderer, {
tileLayer: {
urlTemplate: "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png",
attribution:
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="https://carto.com/attributions">CARTO</a>',
},
getNodeLatLng: (attrs: Attributes) => ({ lat: attrs.latitude, lng: attrs.longitude }),
});
</script>