Skip to content

Commit

Permalink
feat: Add reset functionality for small-world routing visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Nov 27, 2024
1 parent 2997695 commit f3c8e56
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions hugo-site/static/js/small-world-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,39 @@ async function initVisualization() {
animatePath();
}

function resetVisualization() {
// Stop any ongoing animation
isPlaying = false;
const playPauseBtn = document.getElementById('routingPlayPauseBtn');
if (playPauseBtn) {
const icon = playPauseBtn.querySelector('i');
if (icon) {
icon.className = 'fas fa-play';
}
}

// Clear current state
if (routeTimeout) {
clearTimeout(routeTimeout);
routeTimeout = null;
}
if (animationFrame) {
cancelAnimationFrame(animationFrame);
animationFrame = null;
}

// Reset visualization state
currentPath = [];
sourceNode = null;
targetNode = null;
currentPathSegment = 0;
animationProgress = 0;

// Reinitialize network and redraw
initializeNetwork();
draw();
}

function togglePlayPause() {
isPlaying = !isPlaying;
const btn = document.getElementById('routingPlayPauseBtn');
Expand Down Expand Up @@ -387,6 +420,16 @@ async function initVisualization() {
try {
playPauseBtn.addEventListener('click', togglePlayPause);
console.log('Successfully added click listener');

// Add reset button listener
const resetBtn = document.getElementById('resetRoutingBtn');
if (resetBtn) {
resetBtn.addEventListener('click', resetVisualization);
console.log('Successfully added reset button listener');
} else {
console.error('Reset button not found');
}

isPlaying = false; // Ensure initial state
togglePlayPause(); // Start the animation
} catch (err) {
Expand Down

0 comments on commit f3c8e56

Please sign in to comment.