diff --git a/src/frontend/components/Standings/Relative.tsx b/src/frontend/components/Standings/Relative.tsx index c77f618..547e4ce 100644 --- a/src/frontend/components/Standings/Relative.tsx +++ b/src/frontend/components/Standings/Relative.tsx @@ -73,7 +73,7 @@ export const Relative = () => { return (
{ const settings = useStandingsSettings(); return (
{ const [parent] = useAutoAnimate(); @@ -16,6 +17,7 @@ export const Weather = () => { const relativeWindDirection = (weather.windDirection ?? 0) - (weather.windYaw ?? 0); const trackRubbered = useTrackRubberedState(); const settings = useWeatherSettings(); + const unit = useTelemetryValue('DisplayUnits'); return (
{
- +
diff --git a/src/frontend/components/Weather/WindDirection/WindDirection.tsx b/src/frontend/components/Weather/WindDirection/WindDirection.tsx index 4359927..e1ff487 100644 --- a/src/frontend/components/Weather/WindDirection/WindDirection.tsx +++ b/src/frontend/components/Weather/WindDirection/WindDirection.tsx @@ -1,14 +1,44 @@ -import { useAutoAnimate } from '@formkit/auto-animate/react'; import { WindIcon } from '@phosphor-icons/react'; +import { useRef, useEffect, useState } from 'react'; export interface WindDirectionProps { speedMs?: number; direction?: number; + metric?: boolean; } -export const WindDirection = ({ speedMs, direction }: WindDirectionProps) => { - const speed = speedMs !== undefined ? speedMs * (18 / 5) : undefined; - const [parent] = useAutoAnimate(); +export const WindDirection = ({ + speedMs, + direction, + metric = true, +}: WindDirectionProps) => { + // Convert m/s to user's preferred unit + const speed = + speedMs !== undefined + ? speedMs * (metric ? 3.6 : 2.23694) // km/h or mph + : undefined; + + const [normalizedAngle, setNormalizedAngle] = useState(0); + const prevAngleRef = useRef(0); + + useEffect(() => { + if (direction === undefined) return; + + const currentAngle = direction; + const prevAngle = prevAngleRef.current; + + // Calculate the shortest path difference + let diff = currentAngle - prevAngle; + + // Normalize to [-π, π] range + while (diff > Math.PI) diff -= 2 * Math.PI; + while (diff < -Math.PI) diff += 2 * Math.PI; + + // Update the normalized angle + setNormalizedAngle((prev) => prev + diff); + prevAngleRef.current = currentAngle; + }, [direction]); + return (
@@ -17,7 +47,6 @@ export const WindDirection = ({ speedMs, direction }: WindDirectionProps) => {
{ viewBox="0 0 60 60" className="absolute stroke-current stroke-[3] w-full h-full box-border fill-none origin-center transform-gpu transition-transform duration-1000 ease-out" style={{ - rotate: `calc(${direction ?? 0} * 1rad + 0.5turn)`, + rotate: `calc(${normalizedAngle} * 1rad + 0.5turn)`, }} >
- {speed !== undefined ? speed.toFixed(1) : '-'} + {speed !== undefined ? Math.round(speed) : '-'}