import React from 'react'; import { graphNodes } from './graphNodes'; import { isValidNode, PIXELS_TO_FEET, WALKING_SPEED } from './types'; type PathStatsProps = { startId: string; endId: string; }; /** * Calculates the direct path statistics between two nodes. * * @param startId - The ID of the starting node. * @param endId - The ID of the ending node. * * @returns The distance in feet and walking time in minutes between the two nodes. */ export const calcDirectPathStats = ({ startId, endId }: PathStatsProps) => { const startNode = graphNodes[startId]; const endNode = graphNodes[endId]; if (!isValidNode(startNode) || !isValidNode(endNode)) { return null; } // Calculate distance in pixels const distanceInPixels = Math.sqrt((endNode.x - startNode.x) ** 2 + (endNode.y - startNode.y) ** 2); // Convert to feet and calculate time const distanceInFeet = Math.round(distanceInPixels * PIXELS_TO_FEET); const walkingTimeMinutes = Math.ceil(distanceInFeet / WALKING_SPEED); return { distanceInFeet, walkingTimeMinutes, }; }; /** * Component to display statistics about a path between two nodes on a map. * * @param startId - The ID of the starting node. * @param endId - The ID of the ending node. * * @returns A JSX element displaying the path statistics, or null if the nodes are invalid. */ export const PathStats = ({ startId, endId }: PathStatsProps): JSX.Element | null => { const startNode = graphNodes[startId]; const endNode = graphNodes[endId]; if (!isValidNode(startNode) || !isValidNode(endNode)) { return null; } // Calculate distance in pixels const distanceInPixels = Math.sqrt((endNode.x - startNode.x) ** 2 + (endNode.y - startNode.y) ** 2); // Convert to feet and calculate time const distanceInFeet = Math.round(distanceInPixels * PIXELS_TO_FEET); const walkingTimeMinutes = Math.ceil(distanceInFeet / WALKING_SPEED); return (

Path Statistics

Distance: {distanceInFeet} ft
Walking Time: {walkingTimeMinutes} min
From: {startId}
To: {endId}
); };