2024-09-17 16:39:53 +00:00
|
|
|
// import cola from 'cytoscape-cola';
|
|
|
|
|
|
|
|
async function getData() {
|
|
|
|
try {
|
|
|
|
const resp = await fetch("/api/data");
|
|
|
|
if (!resp.ok) {
|
|
|
|
throw new Error(`Response status: ${resp.status}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const json = await resp.json();
|
|
|
|
return json;
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupGraph() {
|
|
|
|
|
|
|
|
getData()
|
|
|
|
.catch(function (err) { console.error(err) })
|
|
|
|
.then(function (elements) {
|
|
|
|
|
|
|
|
var cy = window.cy = cytoscape({
|
2024-09-22 08:27:05 +00:00
|
|
|
container: document.getElementById('map-container'),
|
2024-09-17 16:39:53 +00:00
|
|
|
elements: elements,
|
|
|
|
|
|
|
|
style: [ // the stylesheet for the graph
|
|
|
|
{
|
|
|
|
selector: 'node',
|
|
|
|
style: {
|
2024-09-22 08:27:05 +00:00
|
|
|
'background-color': '#E1F5FE',
|
|
|
|
'border-color': '#03A9F4',
|
|
|
|
'border-width': 0.5,
|
|
|
|
'label': 'data(label)'
|
2024-09-17 16:39:53 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
selector: 'edge',
|
|
|
|
style: {
|
|
|
|
'width': 1,
|
2024-09-22 08:27:05 +00:00
|
|
|
'line-color': '#42A5F5',
|
2024-09-17 16:39:53 +00:00
|
|
|
'target-arrow-color': '#1E88E5',
|
|
|
|
'target-arrow-shape': 'none',
|
|
|
|
'curve-style': 'bezier'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2024-09-22 08:27:05 +00:00
|
|
|
selector: ".link-virtual",
|
2024-09-17 16:39:53 +00:00
|
|
|
style: {
|
|
|
|
"line-color": "#BDBDBD",
|
|
|
|
"line-style": "dashed",
|
2024-09-22 08:27:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: ".link-fast",
|
|
|
|
style: {
|
|
|
|
"width": 1.5,
|
|
|
|
"line-color": "#1565C0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
selector: ".link-slow",
|
|
|
|
style: {
|
|
|
|
"line-color": "#FFC107",
|
|
|
|
},
|
|
|
|
},
|
2024-09-17 16:39:53 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
layout: {
|
2024-09-22 08:27:05 +00:00
|
|
|
name: 'cose',
|
|
|
|
nodeDimensionsIncludeLabels: true,
|
2024-09-17 16:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', setupGraph);
|