Repository navigation
Add sun position, sunrise/sunset, and day/night shading to tide charts - #11
Conversation
Shade the tide chart with a day → twilight → night gradient and mark the exact sunrise/sunset instants with faint hairlines, plus the times in text under the day's extremes for mobile (no hover there). Sun position is pure astronomy from the selected point's lat/lon, so it's computed on-device (new src/engine/sun.ts) rather than fetched — no network, works offline and in the prerendered pages, and fits the DOM-free engine. - engine/sun.ts: sunAltitude(), sunTimes() (with polar day/night flags), and sunBandStops() which samples altitude and collapses flat runs into a small set of SVG gradient stops. Handles polar day/night and white nights with no special-casing. - TideChart: night-band rect behind the curve + sunrise/sunset hairlines with accessible <title> tooltips. Curve is still exactly two <path>s. - Home: sunrise/sunset text line in the day card; passes the chosen point's coords (not the snapped gauge) to the chart. - app.css: --night theme colour for both themes. - Tests: engine unit tests (almanac cross-checks + polar/edge cases) and an e2e spec for the text, band, and hairlines. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UZFFjCf4Q2ZfogfCrdgeyp
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0f25ac27a3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| {#if sun.sunrise && sun.sunset} | ||
| <span title="Sunrise">☀︎ {formatTime(sun.sunrise, tz, $settings.timeFormat)}</span> | ||
| <span class="sep">·</span> | ||
| <span title="Sunset">☾︎ {formatTime(sun.sunset, tz, $settings.timeFormat)}</span> |
There was a problem hiding this comment.
Clamp sun times to the displayed day
For high-latitude days near the midnight-sun boundary, only one horizon crossing may fall inside the local 24h chart window; sunTimes(...) can still return the paired event just after dayEnd (for example Tromsø on May 17 returns a sunset around 00:05 on May 18). The chart already suppresses out-of-window marks, but this branch prints both non-null times, so the side card can list a sunset that is not on the displayed day and does not appear in the chart. Please check each returned time against [dayStart, dayEnd] before using the two-time display.
Useful? React with 👍 / 👎.
Summary
Adds on-device solar calculations to display sunrise/sunset times and a day/night gradient shading on tide charts. The sun module uses standard NOAA/SunCalc astronomy (mean anomaly → ecliptic longitude → declination → hour angle) to compute sun altitude from coordinates and date, accurate to ~1–3 minutes for display purposes. No network requests or DOM dependencies.
Key changes
New
src/engine/sun.ts: Pure, DOM-free solar calculationssunAltitude(date, lat, lon)— sun altitude in radians above the horizon at an instantsunTimes(noon, lat, lon)— sunrise/sunset for the local day, with polar day/night detectionsunBandStops(startMs, endMs, lat, lon)— gradient stops (0..1 offsets, 0..1 night intensity) for SVG<linearGradient>, collapsing flat runs to minimize stopsTideChart.svelteenhancements:sunLat/sunLonprops (null hides shading)<linearGradient id="nightBand">with computed stops, applied to a background<rect><title>Home.svelteintegration:sunTimesfor the displayed day at the selected locationTideChartformatTimeto show times in the location's timezoneStyling (
app.css):--nightcolor variable (#050a16, deep indigo) for the shading bandE2E tests (
tests/e2e/sun.spec.ts):Unit tests (
src/engine/sun.test.ts):Implementation notes
Dateinstants, matching the predictor's contract; timezone conversion happens only in the view layer (formatTime)alwaysUporalwaysDownis set and times arenullhttps://claude.ai/code/session_01UZFFjCf4Q2ZfogfCrdgeyp