From 32616b1a5843f64b062ba87638ad8c11a180b15d Mon Sep 17 00:00:00 2001 From: tariknz Date: Fri, 27 Jun 2025 17:54:57 +1200 Subject: [PATCH 1/2] fix: make sure weather direction to animate the shortest path --- src/frontend/components/Weather/Weather.tsx | 4 +- .../Weather/WindDirection/WindDirection.tsx | 43 ++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/frontend/components/Weather/Weather.tsx b/src/frontend/components/Weather/Weather.tsx index 3526c8a..ccca4d7 100644 --- a/src/frontend/components/Weather/Weather.tsx +++ b/src/frontend/components/Weather/Weather.tsx @@ -7,6 +7,7 @@ import { WeatherTrackRubbered } from './WeatherTrackRubbered/WeatherTrackRubbere import { WindDirection } from './WindDirection/WindDirection'; import { useTrackRubberedState } from './hooks/useTrackRubberedState'; import { useWeatherSettings } from './hooks/useWeatherSettings'; +import { useTelemetryValue } from '@irdashies/context'; export const Weather = () => { 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) : '-'}
From d60eefe3432ac2569d0306d19439bc5e9a0de0f0 Mon Sep 17 00:00:00 2001 From: tariknz Date: Fri, 27 Jun 2025 22:30:23 +1200 Subject: [PATCH 2/2] remove full height to allow background to cover container --- src/frontend/components/Standings/Relative.tsx | 2 +- src/frontend/components/Standings/Standings.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 (