-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
102 lines (89 loc) · 2.74 KB
/
script.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
async function fetchData() {
const response = await fetch('network_data.json?' + new Date().getTime()); // Add timestamp to URL to prevent caching
const data = await response.json();
return data;
}
function initializeCytoscape(data) {
const cy = cytoscape({
container: document.getElementById('cy'),
elements: data,
style: [
{
selector: 'node',
style: {
'label': 'data(label)',
'background-color': 'skyblue',
'font-size': '12px',
'text-valign': 'center',
'color': '#000',
'text-outline-width': 1,
'text-outline-color': '#fff'
}
},
{
selector: 'edge',
style: {
'width': 'data(weight)',
'line-color': '#ccc',
'target-arrow-color': '#ccc',
'target-arrow-shape': 'triangle',
'curve-style': 'bezier'
}
},
{
selector: 'node.major',
style: {
'background-color': 'red'
}
},
{
selector: 'node.secondary',
style: {
'background-color': 'gold'
}
},
{
selector: 'node.tertiary',
style: {
'background-color': 'pink'
}
}
],
layout: {
name: 'cose',
padding: 10,
animate: false, // Disable animation for accurate timing
fit: true,
randomize: true,
nodeRepulsion: 400000,
idealEdgeLength: 100,
edgeElasticity: 100,
gravity: 80,
numIter: 1000,
initialTemp: 200,
coolingFactor: 0.95,
minTemp: 1.0
}
});
cy.nodes().forEach(node => {
if (majorProfessors.includes(node.id())) {
node.addClass('major');
const neighbors = node.neighborhood().nodes();
neighbors.forEach((neighbor, index) => {
if (index === 0) neighbor.addClass('major');
else if (index === 1) neighbor.addClass('secondary');
else if (index === 2) neighbor.addClass('tertiary');
});
}
});
return cy;
}
document.getElementById('reload').addEventListener('click', () => {
fetchData().then(data => {
initializeCytoscape(data);
});
});
// Load the data initially
fetchData().then(data => {
initializeCytoscape(data);
});