Skip to content

Commit

Permalink
feat: Add 60-second timer and reduce routing delay in small world sim…
Browse files Browse the repository at this point in the history
…ulation
  • Loading branch information
sanity committed Nov 27, 2024
1 parent a38c0a1 commit 07706e6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion hugo-site/static/js/small-world-comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ waitForD3().then(() => {
const maxHops = 30;
let isPlaying = false;
let animationFrame;
let startTime;
const simulationDuration = 60000; // 60 seconds in milliseconds

// Setup canvases
const smallWorldCanvas = document.getElementById('smallWorldCanvas');
Expand Down Expand Up @@ -387,8 +389,17 @@ waitForD3().then(() => {
drawNetwork(rnCtx, randomNetwork, rnPath);
updateStats();

// Check if 60 seconds have elapsed
if (Date.now() - startTime >= simulationDuration) {
isPlaying = false;
const btn = document.getElementById('comparisonPlayPauseBtn');
const icon = btn.querySelector('i');
icon.className = 'fas fa-play';
return;
}

// Wait before next attempt
await new Promise(resolve => setTimeout(resolve, 1000));
await new Promise(resolve => setTimeout(resolve, 500));

if (isPlaying) {
animationFrame = requestAnimationFrame(() => simulateRouting());
Expand All @@ -402,6 +413,7 @@ waitForD3().then(() => {
icon.className = isPlaying ? 'fas fa-pause' : 'fas fa-play';

if (isPlaying) {
startTime = Date.now();
simulateRouting();
}
}
Expand Down

0 comments on commit 07706e6

Please sign in to comment.