Skip to content

Commit 973d1ed

Browse files
committed
Fix and stabilize co-attendance network visualization
- Add error handling and retry logic for library loading - Fix physics simulation: increase damping, reduce spring constant, auto-disable after stabilization - Add validation checks and improve timing - Simplify node/edge objects and add console logging The visualization now renders correctly and stabilizes to a static view after initial layout.
1 parent b69d41e commit 973d1ed

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

docs/script.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,23 @@ function initCoattendanceNetwork() {
195195
physics: {
196196
enabled: true,
197197
stabilization: {
198-
iterations: 200,
199-
updateInterval: 25,
198+
iterations: 250,
199+
updateInterval: 50,
200200
onlyDynamicEdges: false,
201201
fit: true
202202
},
203203
barnesHut: {
204-
gravitationalConstant: -2000,
205-
centralGravity: 0.3,
206-
springLength: 100,
207-
springConstant: 0.04,
208-
damping: 0.09,
209-
avoidOverlap: 0.5
210-
}
204+
gravitationalConstant: -3000,
205+
centralGravity: 0.1,
206+
springLength: 150,
207+
springConstant: 0.02,
208+
damping: 0.3,
209+
avoidOverlap: 1.0
210+
},
211+
maxVelocity: 10,
212+
minVelocity: 0.5,
213+
solver: 'barnesHut',
214+
timestep: 0.5
211215
},
212216
interaction: {
213217
hover: true,
@@ -229,6 +233,16 @@ function initCoattendanceNetwork() {
229233

230234
coattendanceNetwork = new vis.Network(container, data, options);
231235

236+
// Disable physics after stabilization to prevent constant movement
237+
coattendanceNetwork.once('stabilizationEnd', function() {
238+
console.log('Network stabilized - disabling physics');
239+
coattendanceNetwork.setOptions({
240+
physics: {
241+
enabled: false
242+
}
243+
});
244+
});
245+
232246
// Add event listeners for better interactivity
233247
coattendanceNetwork.on('click', function(params) {
234248
if (params.nodes.length > 0) {
@@ -248,6 +262,11 @@ function initCoattendanceNetwork() {
248262
container.style.cursor = 'default';
249263
});
250264

265+
// Optionally re-enable physics temporarily when dragging nodes
266+
coattendanceNetwork.on('dragStart', function(params) {
267+
// Physics can remain disabled during drag for stability
268+
});
269+
251270
console.log('Network visualization initialized successfully');
252271
} catch (error) {
253272
console.error('Error initializing network visualization:', error);

0 commit comments

Comments
 (0)