feat(trail-view): map-first layout with elevation insights (#51, slice 1) #56

Closed
maximus wants to merge 0 commits from feat/51-trail-view-layout into deploy
Member

First slice of #51 (trail view page, /trail/view/@handle/id). Refs #51; this does not close it.

What changes

Layout (overview mode of TrailInfoPanel only; map and list modes keep their layout)

  • The map is now full width at about 55vh (min 18rem, max 40rem) right below the title and stats. It replaces the 18rem sticky side map.
  • The stats row is more prominent: values are 1.5rem and semibold, labels are small and grey.
  • The elevation profile sits directly under the map with a fixed height (12rem on phones, 15rem from sm up).
  • The new route insights block follows the profile (see below).
  • The description moves below the map, stats and insights, and is hidden when empty. "Empty" is markup-aware, so <p></p> counts as empty. Owners and editors get an "Add a description" button that opens the existing inline editor. Long descriptions keep the existing 300-character preview with "Read more".
  • If the trail has no photos, the 20rem empty-state header illustration is skipped. A plain back button takes its place, so the map moves up.
  • Phone width: horizontal padding goes from px-8 to px-4 below sm. The insights tiles use a 2-column grid and the legend wraps to 1 column on narrow screens. Light and dark themes use only the existing tokens (border-input-border, text-gray-500).

Komoot-style facts from the GPX we already have (trail_route_insights.svelte)

  • Highest and lowest point, each with its distance from the start.
  • Steepest climb and steepest descent, averaged over a 100 m sliding window (O(n)) so that a single noisy step doesn't count. The tile shows the section length and where it starts.
  • A gradient breakdown: distance per 5 % class as a stacked bar. Each class uses the colour the elevation profile already draws for it, so the bar also serves as the profile's missing legend.
  • The coloured profile and the hover sync were already there: hovering the profile moves the marker on the map, and hovering the track moves the profile crosshair. I left both as they were.
  • Elevations are smoothed with the same moving-average window as the chart, so the numbers match the line. The whole block is computed client-side in an effect: there is no extra GPX parse during SSR and no hydration mismatch. It is hidden when the GPX has no elevation, i.e. the track is 0 m everywhere.

Surface / way-type breakdown: UI only, no data source yet

  • route_breakdown_bar.svelte takes {type, distance}[] and draws a stacked bar plus a legend (distance and %). It merges repeated types, sorts by distance, shows unknown in grey, and renders nothing when there is no data.

  • TrailRouteInsights takes an optional breakdowns: Partial<Record<'surface' | 'way' | 'sac', BreakdownSegment[]>> and draws one bar per dimension that has data. Nothing passes it yet, so nothing renders. There is a TODO(#51) in trail_info_panel.svelte and in $lib/util/route_breakdown.ts.

  • Missing data source. Two candidates:

    1. BRouter (#5). The route GeoJSON's properties.messages table already has one row per change in way tags, with a distance and tags such as highway=path surface=unknown sac_scale=mountain_hiking trail_visibility=excellent. /api/v1/brouter/route passes it through, but valhalla_store keeps only the duration and elevations, so the tags are dropped today. This only covers BRouter-routed segments, and the tags would need to be stored with the trail.
    2. Server-side map matching with Valhalla trace_attributes (edge.use / edge.surface / edge.sac_scale). This works for any track: imported, recorded or Valhalla-routed. It is probably a separate, later PR.

    Whichever source lands first only has to produce RouteBreakdowns.

Files

  • web/src/lib/util/elevation_stats.ts (+ test): profileFromPositions, hasElevationData, elevationExtremes, steepestSections, gradeColorIndex, GRADE_CLASSES, gradeClassIndex, gradeBreakdown, trackPositions.
  • web/src/lib/util/route_breakdown.ts (+ test): summarizeBreakdown, palette, humanizeType, and the RouteBreakdowns type.
  • web/src/lib/components/trail/route_breakdown_bar.svelte, trail_route_insights.svelte (new).
  • web/src/lib/components/trail/trail_info_panel.svelte: the layout changes above. gallery is now $state because the gallery sits inside the conditional header.
  • web/src/lib/i18n/locales/en.json: 12 new keys. No other locale touched.

Notes for #49 (profile colouring)

GRADE_PALETTE and gradeColorIndex in elevation_stats.ts mirror the private gradeColor array and its bucketing in vendor/maplibre-elevation-profile/elevationprofile.ts. A test pins the bucketing. To avoid a conflict with the #49 profile-colouring work, I did not touch the vendored chart. Ideally the chart imports this palette so the legend can't drift from it.

Tests

  • vitest: 30 new tests across elevation_stats.test.ts and route_breakdown.test.ts. They cover min/max and ties, steepest-window averaging versus spikes, sparse points, tracks shorter than the window, flat, single-point and duplicate points, the 2.5 % colour buckets, the 5 % classes and their boundaries, jitter consolidation, a short final stretch, and breakdown merging, sorting, ignoring invalid distances and empty input.
  • Full suite locally: 864 passed, 13 skipped. There is one unhandled rejection from src/lib/server/trail_analyze.test.ts ("ReadableStream is already closed"). It is pre-existing and local-only: the file is untouched and CI is green on deploy e72a2cc5.
  • svelte-check: 0 errors. The 2 remaining warnings are pre-existing ones in trail/edit/[id]/+page.svelte.
  • vite build: OK.

Screenshots

I couldn't take any. The shared browser gets ERR_CONNECTION_REFUSED on wanderer.bearoverse.com, and the trail returns 403 without a session, so neither before/after nor phone/dark captures were possible. Please check the deploy preview at phone width and in dark mode.

Before: a 20rem header illustration when the trail has no photos, then title and stats, then "Description" (an empty-state illustration if empty), "Route" with the elevation profile, and the timeline in a left column, with a small 18rem map stuck to the right on xl.
After: title, larger stats, the full-width map, the profile, insight tiles (highest, lowest, steepest climb and descent) and the gradient bar, then the description only if it has content, then the timeline and tabs.

Left for #51

  • Surface, way-type and SAC data source (see above), plus their i18n labels. Types fall back to humanised OSM values such as fine_gravel → "Fine gravel".
  • Hover sync for breakdown segments: hovering a surface or gradient class should highlight its stretches on the map and the profile. The steepest tiles could also select their section in the profile. This needs a small API on map_with_elevation_maplibre (e.g. an exported highlightSegment(latlngs) that reuses the existing segment-highlight layer).
  • Colouring the profile by surface, once the data exists.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP

First slice of #51 (trail view page, `/trail/view/@handle/id`). Refs #51; this does not close it. ## What changes **Layout (overview mode of `TrailInfoPanel` only; map and list modes keep their layout)** - The map is now full width at about 55vh (min 18rem, max 40rem) right below the title and stats. It replaces the 18rem sticky side map. - The stats row is more prominent: values are 1.5rem and semibold, labels are small and grey. - The elevation profile sits directly under the map with a fixed height (12rem on phones, 15rem from `sm` up). - The new **route insights** block follows the profile (see below). - The description moves below the map, stats and insights, and is hidden when empty. "Empty" is markup-aware, so `<p></p>` counts as empty. Owners and editors get an "Add a description" button that opens the existing inline editor. Long descriptions keep the existing 300-character preview with "Read more". - If the trail has no photos, the 20rem empty-state header illustration is skipped. A plain back button takes its place, so the map moves up. - Phone width: horizontal padding goes from `px-8` to `px-4` below `sm`. The insights tiles use a 2-column grid and the legend wraps to 1 column on narrow screens. Light and dark themes use only the existing tokens (`border-input-border`, `text-gray-500`). **Komoot-style facts from the GPX we already have** (`trail_route_insights.svelte`) - Highest and lowest point, each with its distance from the start. - Steepest climb and steepest descent, averaged over a 100 m sliding window (O(n)) so that a single noisy step doesn't count. The tile shows the section length and where it starts. - A **gradient breakdown**: distance per 5 % class as a stacked bar. Each class uses the colour the elevation profile already draws for it, so the bar also serves as the profile's missing legend. - The coloured profile and the hover sync were already there: hovering the profile moves the marker on the map, and hovering the track moves the profile crosshair. I left both as they were. - Elevations are smoothed with the same moving-average window as the chart, so the numbers match the line. The whole block is computed client-side in an effect: there is no extra GPX parse during SSR and no hydration mismatch. It is hidden when the GPX has no elevation, i.e. the track is 0 m everywhere. **Surface / way-type breakdown: UI only, no data source yet** - `route_breakdown_bar.svelte` takes `{type, distance}[]` and draws a stacked bar plus a legend (distance and %). It merges repeated types, sorts by distance, shows `unknown` in grey, and renders nothing when there is no data. - `TrailRouteInsights` takes an optional `breakdowns: Partial<Record<'surface' | 'way' | 'sac', BreakdownSegment[]>>` and draws one bar per dimension that has data. Nothing passes it yet, so nothing renders. There is a `TODO(#51)` in `trail_info_panel.svelte` and in `$lib/util/route_breakdown.ts`. - **Missing data source.** Two candidates: 1. **BRouter (#5).** The route GeoJSON's `properties.messages` table already has one row per change in way tags, with a distance and tags such as `highway=path surface=unknown sac_scale=mountain_hiking trail_visibility=excellent`. `/api/v1/brouter/route` passes it through, but `valhalla_store` keeps only the duration and elevations, so the tags are dropped today. This only covers BRouter-routed segments, and the tags would need to be stored with the trail. 2. **Server-side map matching with Valhalla `trace_attributes`** (`edge.use` / `edge.surface` / `edge.sac_scale`). This works for any track: imported, recorded or Valhalla-routed. It is probably a separate, later PR. Whichever source lands first only has to produce `RouteBreakdowns`. ## Files - `web/src/lib/util/elevation_stats.ts` (+ test): `profileFromPositions`, `hasElevationData`, `elevationExtremes`, `steepestSections`, `gradeColorIndex`, `GRADE_CLASSES`, `gradeClassIndex`, `gradeBreakdown`, `trackPositions`. - `web/src/lib/util/route_breakdown.ts` (+ test): `summarizeBreakdown`, palette, `humanizeType`, and the `RouteBreakdowns` type. - `web/src/lib/components/trail/route_breakdown_bar.svelte`, `trail_route_insights.svelte` (new). - `web/src/lib/components/trail/trail_info_panel.svelte`: the layout changes above. `gallery` is now `$state` because the gallery sits inside the conditional header. - `web/src/lib/i18n/locales/en.json`: 12 new keys. No other locale touched. ## Notes for #49 (profile colouring) `GRADE_PALETTE` and `gradeColorIndex` in `elevation_stats.ts` mirror the private `gradeColor` array and its bucketing in `vendor/maplibre-elevation-profile/elevationprofile.ts`. A test pins the bucketing. To avoid a conflict with the #49 profile-colouring work, I did not touch the vendored chart. Ideally the chart imports this palette so the legend can't drift from it. ## Tests - `vitest`: 30 new tests across `elevation_stats.test.ts` and `route_breakdown.test.ts`. They cover min/max and ties, steepest-window averaging versus spikes, sparse points, tracks shorter than the window, flat, single-point and duplicate points, the 2.5 % colour buckets, the 5 % classes and their boundaries, jitter consolidation, a short final stretch, and breakdown merging, sorting, ignoring invalid distances and empty input. - Full suite locally: 864 passed, 13 skipped. There is one unhandled rejection from `src/lib/server/trail_analyze.test.ts` ("ReadableStream is already closed"). It is pre-existing and local-only: the file is untouched and CI is green on `deploy` e72a2cc5. - `svelte-check`: 0 errors. The 2 remaining warnings are pre-existing ones in `trail/edit/[id]/+page.svelte`. - `vite build`: OK. ## Screenshots I couldn't take any. The shared browser gets `ERR_CONNECTION_REFUSED` on wanderer.bearoverse.com, and the trail returns 403 without a session, so neither before/after nor phone/dark captures were possible. Please check the deploy preview at phone width and in dark mode. **Before:** a 20rem header illustration when the trail has no photos, then title and stats, then "Description" (an empty-state illustration if empty), "Route" with the elevation profile, and the timeline in a left column, with a small 18rem map stuck to the right on xl. **After:** title, larger stats, the full-width map, the profile, insight tiles (highest, lowest, steepest climb and descent) and the gradient bar, then the description only if it has content, then the timeline and tabs. ## Left for #51 - Surface, way-type and SAC data source (see above), plus their i18n labels. Types fall back to humanised OSM values such as `fine_gravel` → "Fine gravel". - Hover sync for breakdown segments: hovering a surface or gradient class should highlight its stretches on the map and the profile. The steepest tiles could also select their section in the profile. This needs a small API on `map_with_elevation_maplibre` (e.g. an exported `highlightSegment(latlngs)` that reuses the existing segment-highlight layer). - Colouring the profile by surface, once the data exists. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
Pure helpers for the trail view (#51): highest/lowest point, steepest
climb and descent over a 100 m sliding window, distance per 5 % gradient
class (coloured like the elevation profile), and a generic
{type, distance} breakdown summary for surface / way-type data once a
source exists.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
feat(trail-view): lead with map, profile and route facts
All checks were successful
CI / web (push) Successful in 59s
CI / go (push) Successful in 13m30s
799015dea1
On /trail/view the map (full width, ~55vh) and the stats now come first,
followed by the gradient-coloured elevation profile and a route-insights
block (highest/lowest point, steepest climb/descent, gradient breakdown
that doubles as the profile legend). The description moves below and is
hidden when empty (owners get an "Add a description" button). The
empty-state header illustration is skipped when a trail has no photos.

Map and list modes of the shared panel keep their layout.

Refs #51

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
Author
Member

Shipped via batch PR #64 (deploy 0d0d85a4), which merged this branch head unchanged; live since 2026-11-05 ~19:30 CET in wanderer-web:deploy-676a7c62 (homelab-flux #843). Forgejo does not mark stacked PRs as merged, so I am closing this by hand.

🤖 Generated with Claude Code

Shipped via batch PR #64 (`deploy` 0d0d85a4), which merged this branch head unchanged; live since 2026-11-05 ~19:30 CET in `wanderer-web:deploy-676a7c62` (homelab-flux #843). Forgejo does not mark stacked PRs as merged, so I am closing this by hand. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
maximus closed this pull request 2026-11-05 19:10:44 +00:00
All checks were successful
CI / web (push) Successful in 59s
Required
Details
CI / go (push) Successful in 13m30s
Required
Details

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/wanderer!56
No description provided.