-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (37 loc) · 1.32 KB
/
Copy pathapp.js
File metadata and controls
41 lines (37 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// app.js
import cytoscape from 'cytoscape';
async function uploadAndVisualize(file) {
const formData = new FormData();
formData.append('file', file);
const response = await fetch('/analyze', { method: 'POST', body: formData });
const rings = await response.json();
// Prepare elements for Cytoscape
const elements = [];
rings.forEach(ring => {
ring.members.forEach(id => {
elements.push({ data: { id, label: id } });
});
// Create edges for the ring
for (let i = 0; i < ring.members.length; i++) {
const source = ring.members[i];
const target = ring.members[(i + 1) % ring.members.length];
elements.push({ data: { id: `${source}-${target}`, source, target } });
}
});
// Initialize the Graph
const cy = cytoscape({
container: document.getElementById('cy'),
elements: elements,
style: [
{
selector: 'node',
style: { 'background-color': '#ff4d4d', 'label': 'data(id)', 'color': '#fff' }
},
{
selector: 'edge',
style: { 'width': 3, 'line-color': '#ccc', 'target-arrow-shape': 'triangle' }
}
],
layout: { name: 'circle' }
});
}