feat(tours): compare a tour's plan with the track it was actually done with (ACT-02)

Each actual track in a tour's detail now stands beside the plan instead of
on its own: a table names the plan and the actual track as columns, each with
the line it is drawn as on the map, and sets distance, ascent, descent and the
time with breaks side by side. The difference is shown, signed and with an
arrow, only where both values are known and mean the same thing; a planned
total that leaves a stay out reads "at least" and is not subtracted from. A
value one side does not carry is named as missing ("Not in the plan", "Not in
the track", "No time stamps"), never estimated. Below the table, how far the
track left the planned line: its farthest point and the recorded stretches
more than 50 m away, or that there is no line to compare.

On the desktop plan map, "Compare on map" draws the actual track dotted in
the colour of done next to the plan, which stays picked in its own track
colour (and is put back should it be hidden on the map). The recording leaves
the map as a tour of its own meanwhile, so it is never drawn twice or in a
plan's colour. A frosted legend over the map names both lines and ends the
comparison; so do closing the detail, comparing another track, or the track
being unlinked. Comparing only reads: neither the plan nor the track changes.

The track is laid into the day's route lines the map already draws, so both
renderers show it without a layer of their own. distancesToLine in the shared
route corridor measures many points against one line laid flat once; a long
recording is measured in at most 1500 samples.
This commit is contained in:
Maurice
2026-10-20 13:06:17 +02:00
parent a8be1c5b45
commit 6a0c54cb2f
51 changed files with 1699 additions and 56 deletions
+1 -1
View File
@@ -275,7 +275,7 @@ function TripPlannerPageDesktop(): React.ReactElement | null {
{activeTab === 'plan' && (
<div style={{ position: 'absolute', inset: 0 }}>
<PlanMapStage
tripId={tripId} trip={trip} can={can} days={days} reservations={reservations} isMobile={isMobile}
tripId={tripId} trip={trip} can={can} days={days} places={places} reservations={reservations} isMobile={isMobile}
selectedDayId={selectedDayId} selectedPlaceId={selectedPlaceId} selectedPlace={selectedPlace} showDayDetail={showDayDetail} handleSelectDay={handleSelectDay}
mapPlaces={mapPlaces} dayPlaces={dayPlaces} dayOrderMap={dayOrderMap} mapTileUrl={mapTileUrl} fitKey={fitKey} mapLocked={mapLocked} toggleMapLocked={toggleMapLocked} mapFocusPoints={mapFocusPoints}
route={route} routeWalking={routeWalking} routeSegments={routeSegments} routeVias={routeVias} transitRoutesShown={transitRoutesShown}
@@ -1,4 +1,4 @@
// FE-PAGE-PLANNER-MAPSTAGE-001 to FE-PAGE-PLANNER-MAPSTAGE-010
// FE-PAGE-PLANNER-MAPSTAGE-001 to FE-PAGE-PLANNER-MAPSTAGE-011
//
// The plan tab's map and its floating controls, rendered on their own. The map
// and the pills are stubs that record their props, so each mode the stage
@@ -6,6 +6,7 @@
import React from 'react'
import { render, screen } from '../../../tests/helpers/render'
import { buildTrip, buildPlace, buildReservation } from '../../../tests/helpers/factories'
import { useTourActivityCompareStore } from '../../store/tourActivityCompareStore'
import { PlanMapStage, type PlanMapStageProps } from './PlanMapStage'
type Recorded = Record<string, unknown> & Record<`on${string}`, (...args: unknown[]) => unknown>
@@ -68,6 +69,7 @@ function renderStage(overrides: Partial<Record<keyof PlanMapStageProps, unknown>
beforeEach(() => {
for (const key of Object.keys(captured)) delete captured[key]
useTourActivityCompareStore.getState().clear()
})
describe('PlanMapStage', () => {
@@ -210,4 +212,20 @@ describe('PlanMapStage', () => {
loadingKeys: poi.loadingKeys, errorKeys: poi.errorKeys, moved: false, onSearchArea: poi.searchArea,
})
})
it('FE-PAGE-PLANNER-MAPSTAGE-011: a tour compared with its actual track draws the track dotted and explains both lines (ACT-02)', () => {
const plan = buildPlace({ id: 7, name: 'Ridge' })
const track = buildPlace({ id: 20, name: 'Watch export', route_geometry: JSON.stringify([[47, 11], [47.01, 11]]) })
useTourActivityCompareStore.getState().show({ tourPlaceId: 7, trackPlaceId: 20 })
const compared = { places: [plan, track], mapPlaces: [plan, track], selectedPlaceId: 7, route: null, routeWalking: [] }
const { rerender } = renderStage(compared)
expect(recorded('map')).toMatchObject({ places: [plan], route: [[[47, 11], [47.01, 11]]], routeWalking: [true] })
expect(screen.getByTestId('activity-compare-legend')).toHaveTextContent('Watch export')
// The road trip and the trip overview draw other lines; nothing is compared there.
rerender(<PlanMapStage {...stageProps({ ...compared, overviewActive: true })} />)
expect(recorded('map')).toMatchObject({ route: ['overview'] })
expect(screen.queryByTestId('activity-compare-legend')).toBeNull()
})
})
+14 -6
View File
@@ -5,6 +5,8 @@ import { MapCompassPill, type CompassMap } from '../../components/Map/MapCompass
import { TripRouteOverviewPill, TripRouteOverviewPanel } from '../../components/Map/TripRouteOverview'
import { DawarichTrailPill } from '../../components/Map/DawarichTrailPill'
import PoiCategoryPill from '../../components/Map/PoiCategoryPill'
import ActivityCompareLegend from '../../components/Tours/activity/ActivityCompareLegend'
import { useActivityCompareMap } from '../../components/Tours/activity/useActivityCompareMap'
import type { Poi } from '../../components/Map/poiCategories'
import type { Settings } from '../../types'
import { RoadtripAlternativesBar } from './plannerLazy'
@@ -16,7 +18,7 @@ type Planner = ReturnType<typeof useTripPlanner>
type PageState = ReturnType<typeof useTripPlannerPage>
// Picked per concern so the key lists stay short and typed by the hook that owns them.
type StageTrip = Pick<Planner, 'tripId' | 'trip' | 'can' | 'days' | 'reservations' | 'isMobile' | 'selectedDayId' | 'selectedPlaceId' | 'selectedPlace' | 'showDayDetail' | 'handleSelectDay'>
type StageTrip = Pick<Planner, 'tripId' | 'trip' | 'can' | 'days' | 'places' | 'reservations' | 'isMobile' | 'selectedDayId' | 'selectedPlaceId' | 'selectedPlace' | 'showDayDetail' | 'handleSelectDay'>
type StageMap = Pick<Planner,
| 'mapPlaces' | 'dayPlaces' | 'dayOrderMap' | 'mapTileUrl' | 'fitKey' | 'mapLocked' | 'toggleMapLocked' | 'mapFocusPoints'
| 'route' | 'routeWalking' | 'routeSegments' | 'routeVias' | 'transitRoutesShown'
@@ -57,7 +59,7 @@ export interface PlanMapStageProps
* exactly what they were when this lived in the page.
*/
export function PlanMapStage({
tripId, trip, can, days, reservations, isMobile,
tripId, trip, can, days, places, reservations, isMobile,
selectedDayId, selectedPlaceId, selectedPlace, showDayDetail, handleSelectDay,
mapPlaces, dayPlaces, dayOrderMap, mapTileUrl, fitKey, mapLocked, toggleMapLocked, mapFocusPoints,
route, routeWalking, routeSegments, routeVias, transitRoutesShown,
@@ -73,17 +75,22 @@ export function PlanMapStage({
poi, tourMap, leftPanelPx, rightPanelPx, mapInsetLeft, mapInsetRight,
glMap, setGlMap, poiPillEnabled, mapPois, distanceUnit,
}: Readonly<PlanMapStageProps>): ReactElement {
// ACT-02: a tour compared with its actual track lays the track into the day's lines, dotted.
const compared = useActivityCompareMap({
enabled: !roadtripActive && !overviewActive && !isMobile,
places, mapPlaces, route, routeWalking, selectedPlaceId,
})
return (
<>
<MapView
tripId={tripId}
dawarichTrack={dawarichTrail.track}
dawarichHiddenDates={dawarichHiddenDates}
places={roadtripActive ? roadtripMapPlaces : mapPlaces}
places={roadtripActive ? roadtripMapPlaces : compared.places}
dayPlaces={dayPlaces}
route={roadtripActive ? roadtripMapLines : overviewActive ? tripOverview.lines : route}
routeColors={roadtripActive ? roadtripLineColors : overviewActive ? tripOverview.lineColors : undefined}
routeWalking={roadtripActive || overviewActive ? undefined : routeWalking}
route={roadtripActive ? roadtripMapLines : overviewActive ? tripOverview.lines : compared.route}
routeColors={roadtripActive ? roadtripLineColors : overviewActive ? tripOverview.lineColors : compared.routeColors}
routeWalking={roadtripActive || overviewActive ? undefined : compared.routeWalking}
followSelection={!mapLocked || isMobile}
onToggleFollow={isMobile ? undefined : toggleMapLocked}
routeVias={roadtripActive ? roadtripMapVias : routeVias}
@@ -172,6 +179,7 @@ export function PlanMapStage({
position: 'absolute', bottom: 18, right: mapInsetRight + 14, zIndex: 26, // rtl-lint-disable: measured from the right panel's inset
pointerEvents: 'none', flexDirection: 'column', alignItems: 'flex-end', gap: 8,
}}>
{compared.legend && <ActivityCompareLegend legend={compared.legend} />}
{!roadtripActive && overviewActive && (
<TripRouteOverviewPanel
overview={tripOverview}