Skip to content

Commit cbff816

Browse files
Feat/network examples (#34)
* add example datasets * update networks
1 parent addc79d commit cbff816

16 files changed

Lines changed: 33869 additions & 127 deletions

Tutorials/03_networks.ipynb

Lines changed: 26767 additions & 127 deletions
Large diffs are not rendered by default.

Tutorials/citibike.ipynb

Lines changed: 618 additions & 0 deletions
Large diffs are not rendered by default.

Tutorials/edges.geojson

Lines changed: 106 additions & 0 deletions
Large diffs are not rendered by default.

Tutorials/lines.pdf

6.22 KB
Binary file not shown.

Tutorials/nodes.geojson

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"type": "FeatureCollection",
3+
"name": "nodes",
4+
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
5+
"features": [
6+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.970711897643611, 40.77112661471849 ] } },
7+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.870886380176543, 40.608003189276864 ] } },
8+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.938341974357016, 40.794077608849037 ] } },
9+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.973070090201858, 40.884875418046974 ] } },
10+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.04580712039666, 40.599501257407979 ] } },
11+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.912463532160004, 40.730462933767136 ] } },
12+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.037447673242383, 40.736816772508732 ] } },
13+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.764936199530752, 40.72890076231635 ] } },
14+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.72180234369938, 40.58923265305625 ] } },
15+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.06993508870454, 40.881099604606796 ] } },
16+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.824964977150401, 40.678850151447051 ] } },
17+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.982663048148254, 40.838563468988447 ] } },
18+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.959173263343644, 40.779791710127 ] } },
19+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.744642017024404, 40.61897478034205 ] } },
20+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.257378365081266, 40.825519127880987 ] } },
21+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.247722420179073, 40.658602296338792 ] } },
22+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.287868961535807, 40.852441278844466 ] } },
23+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.80042809267124, 40.732509149054344 ] } },
24+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.833105949430092, 40.852694144741939 ] } },
25+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.777992711051908, 40.777012636031102 ] } },
26+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.712828994660342, 40.790101711927854 ] } },
27+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.820504861469971, 40.700529752770677 ] } },
28+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.023112382648236, 40.882433453889291 ] } },
29+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.831682494228133, 40.757596079691851 ] } },
30+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.229035344478632, 40.669542019423268 ] } },
31+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.916047387203491, 40.742557285651166 ] } },
32+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.213988027554564, 40.507677279323737 ] } },
33+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.733198649770259, 40.620629926669821 ] } },
34+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.986891006949961, 40.764069414997074 ] } },
35+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.051202836005686, 40.616031042884174 ] } },
36+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.141266632737228, 40.747206171599537 ] } },
37+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.83545978633947, 40.671507480378303 ] } },
38+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.026309800670077, 40.554189625688977 ] } },
39+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.958939630678813, 40.619312930382414 ] } },
40+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.288726119738186, 40.727985964280506 ] } },
41+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.929418701754471, 40.736349104499268 ] } },
42+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.932742566366542, 40.729730099539829 ] } },
43+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.929839601875145, 40.761280327942849 ] } },
44+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.73375115289123, 40.760841308000671 ] } },
45+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.890907820537905, 40.672567374173589 ] } },
46+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.084295259655732, 40.858618638340424 ] } },
47+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.037780827720397, 40.647024748019156 ] } },
48+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.88142128244364, 40.674345970106252 ] } },
49+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.263864717022429, 40.856769342006267 ] } },
50+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.899939970732603, 40.82247759561843 ] } },
51+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.897617278229106, 40.781555433416145 ] } },
52+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.173770463355694, 40.540090754924918 ] } },
53+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.22264422140708, 40.867793045497869 ] } },
54+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.110742989445484, 40.785696519819645 ] } },
55+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.081773537434429, 40.899538802627148 ] } },
56+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.957881937749278, 40.559779321863196 ] } },
57+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.036839091922602, 40.847250422947283 ] } },
58+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.706975697164467, 40.564997173870552 ] } },
59+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.238773113551176, 40.746223825713535 ] } },
60+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.174673946343091, 40.549527993139776 ] } },
61+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.203214289268999, 40.839203291728893 ] } },
62+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.908135004720762, 40.822927583490006 ] } },
63+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.148025038476135, 40.727640295445838 ] } },
64+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.020213536286221, 40.662873318890398 ] } },
65+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.153344644799034, 40.527666798182054 ] } },
66+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.204618249812683, 40.778971509257822 ] } },
67+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.23377491530141, 40.681417073071223 ] } },
68+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.906202246320831, 40.788822239788139 ] } },
69+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.217090229190831, 40.846552930371452 ] } },
70+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.182050582991963, 40.890208602001152 ] } },
71+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.078764897603421, 40.842321336957042 ] } },
72+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.807404062091237, 40.504685633674001 ] } },
73+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.241739234524161, 40.643991225791346 ] } },
74+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.797233055500726, 40.791996224969623 ] } },
75+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.242340955263614, 40.568651870904574 ] } },
76+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.714124320991971, 40.70841464248165 ] } },
77+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.018809279011379, 40.521735195335701 ] } },
78+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.713943347085802, 40.579998609958558 ] } },
79+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.937092688152973, 40.507408717784244 ] } },
80+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.856441852361016, 40.817479081342967 ] } },
81+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.276487324647405, 40.58956987522415 ] } },
82+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.130315822454151, 40.638140672278759 ] } },
83+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.227882063272091, 40.871232517386233 ] } },
84+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.122315881486713, 40.78176576076941 ] } },
85+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.228763368627455, 40.51273557181252 ] } },
86+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.109210092363611, 40.565877662599164 ] } },
87+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.051442203291202, 40.748591360599903 ] } },
88+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.261511502190729, 40.730891435441663 ] } },
89+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.884516728377989, 40.595157128549801 ] } },
90+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.960039127476051, 40.873685599169917 ] } },
91+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.14076630543633, 40.745586382386357 ] } },
92+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.986051167919982, 40.714253121209985 ] } },
93+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.243635693544931, 40.735963990541826 ] } },
94+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.954432102666289, 40.792048811806708 ] } },
95+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.742422281454267, 40.624777998191838 ] } },
96+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.108858628529205, 40.659288424886434 ] } },
97+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.89955377202179, 40.58393749959005 ] } },
98+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.220921282557356, 40.574477202352135 ] } },
99+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.870203677528863, 40.877748955993574 ] } },
100+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.126356344231681, 40.795820318019715 ] } },
101+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.190085182795727, 40.696183523447026 ] } },
102+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.948092239113947, 40.590965851189331 ] } },
103+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.287935472287501, 40.601742592708156 ] } },
104+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -73.802635982469582, 40.523211664129548 ] } },
105+
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -74.297182714284475, 40.67376665022325 ] } }
106+
]
107+
}

Tutorials/subway_graph/index.html

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>GEXF Graph with BFS using Sigma.js</title>
6+
<style>
7+
body,
8+
html {
9+
margin: 0;
10+
height: 100%;
11+
font-family: sans-serif;
12+
}
13+
#container {
14+
position: absolute;
15+
top: 0;
16+
left: 0;
17+
right: 0;
18+
bottom: 0;
19+
}
20+
#controls {
21+
position: absolute;
22+
top: 10px;
23+
left: 10px;
24+
background: white;
25+
padding: 8px;
26+
border-radius: 6px;
27+
box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
28+
z-index: 10;
29+
}
30+
</style>
31+
</head>
32+
<body>
33+
<div id="controls">
34+
<label for="bfsDepth">BFS Depth (n): </label>
35+
<input type="number" id="bfsDepth" value="1" min="1" />
36+
</div>
37+
<div id="container"></div>
38+
39+
<!-- Graphology & Sigma.js CDN -->
40+
<script src="https://unpkg.com/graphology@0.25.0/dist/graphology.min.js"></script>
41+
<script src="https://unpkg.com/graphology-layout-forceatlas2/build/forceatlas2.min.js"></script>
42+
<script src="https://unpkg.com/graphology-gexf/browser.js"></script>
43+
<script src="https://unpkg.com/graphology-traversal/bfs.js"></script>
44+
<script src="https://unpkg.com/sigma/build/sigma.min.js"></script>
45+
46+
<script>
47+
// 🔗 Change this to point to your GEXF file
48+
const GEXF_FILE_URL = "./subway_network.gexf";
49+
// Reference the global graphology object from the CDN
50+
const graphology = window.graphology;
51+
const container = document.getElementById("container");
52+
const bfsDepthInput = document.getElementById("bfsDepth");
53+
// Create an empty graph instance
54+
const graph = new graphology.Graph();
55+
56+
fetch(GEXF_FILE_URL)
57+
.then((res) => res.text())
58+
.then((gexfText) => {
59+
const parser = new DOMParser();
60+
const xml = parser.parseFromString(gexfText, "application/xml");
61+
console.log("Parsed GEXF XML:", gexfText);
62+
// Load GEXF into graph
63+
const loaded = graphology.Graph.fromGEXF(xml, {
64+
attributes: true,
65+
edges: true,
66+
nodes: true,
67+
});
68+
graph.merge(loaded);
69+
70+
// Optional: run layout if no coords in GEXF
71+
if (!graph.getNodeAttributes(graph.nodes()[0]).x) {
72+
const forceAtlas2 = graphologyLayoutForceAtlas2;
73+
forceAtlas2.assign(graph, { iterations: 100 });
74+
}
75+
76+
// Default styles
77+
graph.forEachNode((node, attrs) => {
78+
graph.setNodeAttribute(node, "color", "#999");
79+
graph.setNodeAttribute(node, "size", 5);
80+
});
81+
82+
// Sigma instance
83+
const renderer = new sigma.Sigma(graph, container);
84+
85+
// Handle node click
86+
renderer.on("clickNode", ({ node }) => {
87+
const depth = parseInt(bfsDepthInput.value, 10) || 1;
88+
89+
const bfs = graphologyTraversal.bfs;
90+
const visited = new Set();
91+
92+
bfs(graph, node, (n, attr, depthVal) => {
93+
if (depthVal <= depth) visited.add(n);
94+
});
95+
96+
// Update node colors based on BFS result
97+
graph.forEachNode((n) => {
98+
graph.setNodeAttribute(
99+
n,
100+
"color",
101+
visited.has(n) ? "#f00" : "#ccc"
102+
);
103+
graph.setNodeAttribute(n, "size", visited.has(n) ? 8 : 3);
104+
});
105+
106+
renderer.refresh();
107+
});
108+
})
109+
.catch((err) => {
110+
console.error("Failed to load or parse GEXF file", err);
111+
});
112+
</script>
113+
</body>
114+
</html>

0 commit comments

Comments
 (0)