topology-map/static/scripts/index.js

92 lines
2 KiB
JavaScript
Raw Permalink Normal View History

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-23 11:45:30 +00:00
{
selector: ".unmonitored",
style: {
"background-color": "#E57373",
"border-color": "#C62828"
}
}
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
}
2024-09-23 11:45:30 +00:00
// layout: {
// name: "cola",
// nodeDimensionsIncludeLabels: true,
// }
2024-09-17 16:39:53 +00:00
});
});
}
document.addEventListener('DOMContentLoaded', setupGraph);