perf(traffic): shorten sidebar graph animation

This commit is contained in:
Tunglies
2026-11-23 22:54:56 +08:00
parent e8aafac962
commit 80e5aed793
+3 -6
View File
@@ -13,7 +13,8 @@ const upLineWidth = 4
const downLineAlpha = 1
const downLineWidth = 4
const sampleIntervalMs = 1000
const animationDurationMs = sampleIntervalMs
const animationDurationMs = 150
const scrollTransform = `translateX(${-100 / (maxPoint + 1)}%)`
const zeroTraffic: Traffic = { up: 0, down: 0, upTotal: 0, downTotal: 0 }
const createDefaultList = () =>
@@ -203,12 +204,8 @@ export function TrafficGraph({ ref }: { ref?: Ref<TrafficRef> }) {
performance.now() - animationStartRef.current,
animationDurationMs,
)
const step = canvas.getBoundingClientRect().width / (maxPoint + 1)
animation = canvas.animate(
[
{ transform: 'translateX(0)' },
{ transform: `translateX(${-step}px)` },
],
[{ transform: 'translateX(0)' }, { transform: scrollTransform }],
{ duration: animationDurationMs, easing: 'linear', fill: 'forwards' },
)
animation.currentTime = elapsed