Skip to content

Commit 2b7ca0c

Browse files
committed
Improve network visualization stability and spacing
- Reduce node movement speed (damping 0.5, maxVelocity 5, timestep 0.3) - Increase node spacing (springLength 250, avoidOverlap 1.2) - Optimize stabilization (150 iterations, 3s timeout) - Add safety flag for physics disabling Visualization now settles smoothly with better spacing and guaranteed stop within 3 seconds.
1 parent 82b6d8f commit 2b7ca0c

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

docs/script.js

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,23 +195,23 @@ function initCoattendanceNetwork() {
195195
physics: {
196196
enabled: true,
197197
stabilization: {
198-
iterations: 250,
199-
updateInterval: 50,
198+
iterations: 150,
199+
updateInterval: 100,
200200
onlyDynamicEdges: false,
201201
fit: true
202202
},
203203
barnesHut: {
204-
gravitationalConstant: -3000,
205-
centralGravity: 0.1,
206-
springLength: 150,
207-
springConstant: 0.02,
208-
damping: 0.3,
209-
avoidOverlap: 1.0
204+
gravitationalConstant: -5000,
205+
centralGravity: 0.05,
206+
springLength: 250,
207+
springConstant: 0.01,
208+
damping: 0.5,
209+
avoidOverlap: 1.2
210210
},
211-
maxVelocity: 10,
212-
minVelocity: 0.5,
211+
maxVelocity: 5,
212+
minVelocity: 0.1,
213213
solver: 'barnesHut',
214-
timestep: 0.5
214+
timestep: 0.3
215215
},
216216
interaction: {
217217
hover: true,
@@ -234,15 +234,33 @@ function initCoattendanceNetwork() {
234234
coattendanceNetwork = new vis.Network(container, data, options);
235235

236236
// Disable physics after stabilization to prevent constant movement
237+
let physicsDisabled = false;
238+
237239
coattendanceNetwork.once('stabilizationEnd', function() {
238-
console.log('Network stabilized - disabling physics');
239-
coattendanceNetwork.setOptions({
240-
physics: {
241-
enabled: false
242-
}
243-
});
240+
if (!physicsDisabled) {
241+
physicsDisabled = true;
242+
console.log('Network stabilized - disabling physics');
243+
coattendanceNetwork.setOptions({
244+
physics: {
245+
enabled: false
246+
}
247+
});
248+
}
244249
});
245250

251+
// Fallback: disable physics after 3 seconds regardless of stabilization status
252+
setTimeout(function() {
253+
if (!physicsDisabled) {
254+
physicsDisabled = true;
255+
console.log('Force disabling physics after timeout');
256+
coattendanceNetwork.setOptions({
257+
physics: {
258+
enabled: false
259+
}
260+
});
261+
}
262+
}, 3000);
263+
246264
// Add event listeners for better interactivity
247265
coattendanceNetwork.on('click', function(params) {
248266
if (params.nodes.length > 0) {

0 commit comments

Comments
 (0)