Optimized graph layout animation parameters, Smoothed overlapping animations

- Reduced animation duration to 300ms
- Decreased update interval to 200ms
- Extended auto-stop timeout to 3 seconds
This commit is contained in:
yangdx
2025-03-17 20:00:14 +08:00
parent e03e1206c7
commit 971034fbba

View File

@@ -53,7 +53,7 @@ const WorkerLayoutControl = ({ layout, autoRunFor, mainLayout }: ExtendedWorkerL
// Animate nodes to new positions // Animate nodes to new positions
// console.log('Updating node positions with layout algorithm') // console.log('Updating node positions with layout algorithm')
animateNodes(graph, positions, { duration: 400 }) // Increase duration for smoother transitions animateNodes(graph, positions, { duration: 300 }) // Reduced duration for more frequent updates
} catch (error) { } catch (error) {
console.error('Error updating positions:', error) console.error('Error updating positions:', error)
// Stop animation if there's an error // Stop animation if there's an error
@@ -99,14 +99,14 @@ const WorkerLayoutControl = ({ layout, autoRunFor, mainLayout }: ExtendedWorkerL
// Set up interval for continuous updates // Set up interval for continuous updates
animationTimerRef.current = window.setInterval(() => { animationTimerRef.current = window.setInterval(() => {
updatePositions() updatePositions()
}, 400) // Match interval with animation duration for smoother transitions }, 200) // Reduced interval to create overlapping animations for smoother transitions
setIsRunning(true) setIsRunning(true)
// Set a timeout to automatically stop the animation after 2 seconds // Set a timeout to automatically stop the animation after 3 seconds
setTimeout(() => { setTimeout(() => {
if (animationTimerRef.current) { if (animationTimerRef.current) {
console.log('Auto-stopping layout animation after 2 seconds') console.log('Auto-stopping layout animation after 3 seconds')
window.clearInterval(animationTimerRef.current) window.clearInterval(animationTimerRef.current)
animationTimerRef.current = null animationTimerRef.current = null
setIsRunning(false) setIsRunning(false)
@@ -122,7 +122,7 @@ const WorkerLayoutControl = ({ layout, autoRunFor, mainLayout }: ExtendedWorkerL
console.error('Error stopping layout algorithm:', error) console.error('Error stopping layout algorithm:', error)
} }
} }
}, 2000) }, 3000)
} }
}, [isRunning, layout, updatePositions]) }, [isRunning, layout, updatePositions])
@@ -146,7 +146,7 @@ const WorkerLayoutControl = ({ layout, autoRunFor, mainLayout }: ExtendedWorkerL
// Set up interval for continuous updates // Set up interval for continuous updates
animationTimerRef.current = window.setInterval(() => { animationTimerRef.current = window.setInterval(() => {
updatePositions() updatePositions()
}, 400) // Match interval with animation duration for smoother transitions }, 200) // Reduced interval to create overlapping animations for smoother transitions
setIsRunning(true) setIsRunning(true)
@@ -270,7 +270,7 @@ const LayoutsControl = () => {
const pos = positions() const pos = positions()
console.log('Positions calculated, animating nodes') console.log('Positions calculated, animating nodes')
animateNodes(graph, pos, { duration: 500 }) animateNodes(graph, pos, { duration: 400 })
setLayout(newLayout) setLayout(newLayout)
} catch (error) { } catch (error) {
console.error('Error running layout:', error) console.error('Error running layout:', error)