From 07706e6c8c3dec7626dd76bf6fbd08a4eb95aa14 Mon Sep 17 00:00:00 2001 From: "Ian Clarke (aider)" Date: Wed, 27 Nov 2024 00:49:39 -0600 Subject: [PATCH] feat: Add 60-second timer and reduce routing delay in small world simulation --- hugo-site/static/js/small-world-comparison.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hugo-site/static/js/small-world-comparison.js b/hugo-site/static/js/small-world-comparison.js index 0f9f0ed7..cb0649ee 100644 --- a/hugo-site/static/js/small-world-comparison.js +++ b/hugo-site/static/js/small-world-comparison.js @@ -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'); @@ -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()); @@ -402,6 +413,7 @@ waitForD3().then(() => { icon.className = isPlaying ? 'fas fa-pause' : 'fas fa-play'; if (isPlaying) { + startTime = Date.now(); simulateRouting(); } }