From dedc303062c2b363db6cf8144d50e584ff505ede Mon Sep 17 00:00:00 2001 From: Thazzr <22547926+Thazzr@users.noreply.github.com> Date: Sun, 15 Nov 2026 09:38:06 +0000 Subject: [PATCH 1/2] =?UTF-8?q?fix(weather):=20Temperaturdiagramm=20so=20s?= =?UTF-8?q?charf=20wie=20der=20=C3=BCbrige=20Text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Anlass (Foto vom Spiegel): Das Diagramm wirkte weiterhin weniger scharf als der Rest. Werte, Skala und Regenprozente waren SVG-Text; Chromium zeichnet ihn ohne die Schriftglättung und in dünnerer Schrift als normalen HTML-Text. Die 2,5-px-Linie verstärkte den Eindruck. Lösung: Alle Diagrammtexte sind HTML in einer Ebene über dem SVG, mit Schrift und Stärke wie die Stundenleiste; die Skala steht rechtsbündig vor dem ersten Punkt und knapp über ihren Linien, damit sie die Regenwerte nicht berührt. Linie 3 px mit geometricPrecision, Punkte mit schwarzem Rand, dazu eine dezente Verlaufsfläche unter der Kurve (in der Vergangenheit abgedunkelt wie die Linie). Prüfung: Tests (kein SVG-Text, Labels an den Punkten, Skala in der Lücke und über den Linien, Fläche mit Verlauf, Punktrand); Gegenproben schlagen an; Screenshot bei 1440×2560; npm run verify -- --race grün. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BbBgi6nWM5aU7VDrf62V1r --- .../features/modules/weather/Widget.test.tsx | 83 ++++++++++- web/src/features/modules/weather/Widget.tsx | 132 ++++++++++++------ web/src/features/modules/weather/weather.css | 14 +- 3 files changed, 178 insertions(+), 51 deletions(-) diff --git a/web/src/features/modules/weather/Widget.test.tsx b/web/src/features/modules/weather/Widget.test.tsx index 862715a..69cbfc3 100644 --- a/web/src/features/modules/weather/Widget.test.tsx +++ b/web/src/features/modules/weather/Widget.test.tsx @@ -1,3 +1,5 @@ +import { readFileSync } from 'node:fs' +import { resolve } from 'node:path' import { screen, waitFor, within } from '@testing-library/react' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { json, mockApi, problem } from '../../../test/mockApi.ts' @@ -80,7 +82,7 @@ describe('weather widget', () => { await screen.findByText('17°') const bars = container.querySelectorAll('.mirror-weather__rain-bars rect') expect(bars).toHaveLength(1) - expect(within(container.querySelector('.mirror-weather__rain-bars') as HTMLElement).getByText('40%')).toBeInTheDocument() + expect(within(container.querySelector('.mirror-weather__chart-labels') as HTMLElement).getByText('40%')).toBeInTheDocument() }) describe('temperature chart', () => { @@ -136,6 +138,85 @@ describe('weather widget', () => { expect(labelLefts).toHaveLength(9) pointXs.forEach((x, i) => expect(labelLefts[i]).toBeCloseTo((x / 640) * 100, 3)) }) + + it('draws all chart text as HTML: no SVG text, one value label per point at the point x', async () => { + stubObserver(640) + const data = weatherData() + setup({ configured: true, stale: false, data }) + const { container } = renderWithProviders('/') + await screen.findByText('17°') + const svg = container.querySelector('svg.mirror-weather__chart') as SVGSVGElement + await waitFor(() => expect(svg.getAttribute('viewBox')).toBe('0 0 640 265')) + expect(svg.querySelectorAll('text')).toHaveLength(0) + const overlay = container.querySelector('.mirror-weather__chart-labels') as HTMLElement + expect(overlay.tagName).toBe('DIV') + const values = [...overlay.querySelectorAll('.mirror-weather__chart-value')] + expect(values.map((el) => el.textContent)).toEqual(data.hourly.map((h) => `${h.temperatureC}°`)) + const pointXs = [...svg.querySelectorAll(':scope > g:not(.mirror-weather__rain-bars) > circle')].map((c) => Number(c.getAttribute('cx'))) + values.forEach((el, i) => expect(parseFloat(el.style.left)).toBeCloseTo((pointXs[i] / 640) * 100, 3)) + }) + + it('shows the three scale labels and the rain percentage as HTML in the overlay', async () => { + setup({ configured: true, stale: false, data: weatherData() }) + const { container } = renderWithProviders('/') + await screen.findByText('17°') + const overlay = container.querySelector('.mirror-weather__chart-labels') as HTMLElement + const scale = [...overlay.querySelectorAll('.mirror-weather__chart-scale')].map((el) => el.textContent) + expect(scale).toHaveLength(3) + scale.forEach((text) => expect(text).toMatch(/^-?\d+°$/)) + expect([...overlay.querySelectorAll('.mirror-weather__chart-rain')].map((el) => el.textContent)).toEqual(['40%']) + }) + + it('right-aligns the scale labels in the left gutter, ending 12 px before the first point', async () => { + stubObserver(640) + setup({ configured: true, stale: false, data: weatherData() }) + const { container } = renderWithProviders('/') + await screen.findByText('17°') + const svg = container.querySelector('svg.mirror-weather__chart') as SVGSVGElement + await waitFor(() => expect(svg.getAttribute('viewBox')).toBe('0 0 640 265')) + const firstX = Number(svg.querySelector(':scope > g:not(.mirror-weather__rain-bars) > circle')?.getAttribute('cx')) + const labels = [...container.querySelectorAll('.mirror-weather__chart-scale')] + expect(labels).toHaveLength(3) + // The CSS rule translates by -100%, so left is the right edge of the label. + labels.forEach((el) => expect(parseFloat(el.style.left)).toBeCloseTo(((firstX - 12) / 640) * 100, 3)) + // Vertical anchor: top is the grid line's y, and the CSS lifts the label so its bottom edge sits 4 px above it. + const lineYs = [...svg.querySelectorAll(':scope > line:not(.mirror-weather__chart-now)')].map((l) => Number(l.getAttribute('y1'))) + expect(lineYs).toHaveLength(3) + expect(labels.map((el) => parseFloat(el.style.top)).sort((a, b) => a - b)).toEqual([...lineYs].sort((a, b) => a - b)) + const css = readFileSync(resolve(process.cwd(), 'src/features/modules/weather/weather.css'), 'utf8') + const rule = /\.mirror-weather__chart-scale\s*\{[^}]*\}/.exec(css)?.[0] ?? '' + expect(rule).toContain('transform: translate(-100%, calc(-100% - 4px))') + }) + + it('draws a gradient area that closes on the bottom plot line, below the line, in both clipped halves', async () => { + setup({ configured: true, stale: false, data: weatherData() }) + const { container } = renderWithProviders('/') + await screen.findByText('17°') + const areas = [...container.querySelectorAll('path.mirror-weather__chart-area')] + expect(areas).toHaveLength(2) + const bottom = container.querySelector('svg.mirror-weather__chart > line')?.getAttribute('y1') + for (const area of areas) { + const d = area.getAttribute('d') as string + expect(d).toMatch(new RegExp(`L [\\d.]+,${bottom} L [\\d.]+,${bottom} Z$`)) + const id = /^url\(#(.+)\)$/.exec(area.getAttribute('fill') ?? '')?.[1] + expect(id).toBeTruthy() + expect(container.querySelector(`linearGradient[id="${id}"]`)).not.toBeNull() + expect(area.nextElementSibling?.classList.contains('mirror-weather__chart-temp')).toBe(true) + } + }) + + it('gives the points a black outline so the line passes behind them cleanly', async () => { + setup({ configured: true, stale: false, data: weatherData() }) + const { container } = renderWithProviders('/') + await screen.findByText('17°') + const points = container.querySelectorAll('circle.mirror-weather__chart-point') + expect(points).toHaveLength(9) + expect(points[0].getAttribute('r')).toBe('4.5') + points.forEach((p) => { + expect(p.getAttribute('stroke')).toBe('#000') + expect(p.getAttribute('stroke-width')).toBe('2') + }) + }) }) it('shows the alert line', async () => { diff --git a/web/src/features/modules/weather/Widget.tsx b/web/src/features/modules/weather/Widget.tsx index 095bf35..c40b754 100644 --- a/web/src/features/modules/weather/Widget.tsx +++ b/web/src/features/modules/weather/Widget.tsx @@ -165,57 +165,99 @@ function WeatherChart({ entries, now, width }: { entries: Hourly[]; now: number; const lastTime = new Date(entries[entries.length - 1].time).getTime() const currentProgress = Math.max(0, Math.min(1, (now - firstTime) / (lastTime - firstTime || 1))) const currentX = left + plotWidth * currentProgress + const first = temperatures[0] + const last = temperatures[temperatures.length - 1] + // Closed shape below the curve down to the bottom plot line; the gradient fades it out towards that line. + const areaPath = `${path} L ${last.x},${yBottom} L ${first.x},${yBottom} Z` + const scaleLabels = [ + { value: high, y: yTop }, + { value: mid, y: 130 }, + { value: low, y: yBottom }, + ] + const pct = (x: number) => `${(x / width) * 100}%` + // Text is HTML on top of the SVG: Chromium draws SVG text without the hinting and weight of HTML text. return ( - - - - - - - - - - - - - {low}° - {mid}° - {high}° - +
+ + + + + + + + + + + + + + + + + + {entries.map((entry, index) => { + const height = Math.max(0, entry.precipitationProbability * 0.28) + return height > 0 ? ( + + + {entry.precipitationProbability}% Regenwahrscheinlichkeit + + + ) : null + })} + + {/* The same curve twice, clipped at "now": the past part is dimmed and there is no join to kink. */} + + + + + + + + + + + {temperatures.map((value, index) => ( + + + + ))} + + +
) } diff --git a/web/src/features/modules/weather/weather.css b/web/src/features/modules/weather/weather.css index 63bb310..d7ff61f 100644 --- a/web/src/features/modules/weather/weather.css +++ b/web/src/features/modules/weather/weather.css @@ -15,15 +15,19 @@ .mirror-weather__hourly { margin-top: 3.5rem; text-align: left; width: 100%; } .mirror-weather__forecast h2 { color: #fff; font-size: clamp(1.35rem,1.7vw,1.8rem); font-weight: 500; letter-spacing: .08rem; margin: 0 0 1.15rem; text-transform: uppercase; } -.mirror-weather__chart { display: block; height: 265px; margin-top: .9rem; overflow: visible; width: 100%; } +.mirror-weather__chart-box { margin-top: .9rem; position: relative; width: 100%; } +.mirror-weather__chart { display: block; height: 265px; overflow: visible; shape-rendering: geometricPrecision; width: 100%; } .mirror-weather__chart line { stroke: rgba(255,255,255,.15); stroke-dasharray: 3 6; stroke-width: 1; } .mirror-weather__chart-now { stroke: rgba(255,255,255,.8) !important; stroke-dasharray: 3 5 !important; stroke-width: 1.5 !important; } -.mirror-weather__chart-temp { fill: none; stroke: #fff; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.5; } +.mirror-weather__chart-temp { fill: none; shape-rendering: geometricPrecision; stroke: #fff; stroke-linecap: round; stroke-linejoin: round; stroke-width: 3; } +.mirror-weather__chart-area { stroke: none; } .mirror-weather__chart circle { fill: #fff; } -.mirror-weather__chart-scale { fill: var(--mirror-muted); font-size: 27px; text-anchor: start; } -.mirror-weather__chart-value { fill: #fff; font-size: 27px; text-anchor: middle; } +.mirror-weather__chart-labels { inset: 0; pointer-events: none; position: absolute; } +.mirror-weather__chart-labels > span { font-size: 27px; line-height: 1; position: absolute; white-space: nowrap; } +.mirror-weather__chart-labels .mirror-weather__chart-scale { color: var(--mirror-muted); font-weight: 500; transform: translate(-100%, calc(-100% - 4px)); } +.mirror-weather__chart-labels .mirror-weather__chart-value { color: #fff; font-weight: 600; transform: translate(-50%, -100%); } +.mirror-weather__chart-labels .mirror-weather__chart-rain { color: rgba(255,255,255,.8); font-size: 22px; font-weight: 500; transform: translate(-50%, -100%); } .mirror-weather__rain-bars rect { fill: rgba(255,255,255,.42); } -.mirror-weather__rain-bars text { fill: rgba(255,255,255,.8); font-size: 24px; text-anchor: middle; } .mirror-weather__chart-past { opacity: .86; } .mirror-weather__chart-now-marker { fill: #fff; } From b3b0b3b0a56f31fe632c5b1180a1568c7f769c8e Mon Sep 17 00:00:00 2001 From: Thazzr <22547926+Thazzr@users.noreply.github.com> Date: Sun, 15 Nov 2026 09:38:08 +0000 Subject: [PATCH 2/2] docs(changelog): update Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BbBgi6nWM5aU7VDrf62V1r --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c28fd60..c4c4291 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ automatisch mit [git-cliff](https://git-cliff.org) aus den Commit-Messages gener - **icons**: Hochgeladene SVG-Symbole nehmen die Textfarbe an - **calendar**: Schichtzeiten immer mit Minuten +- **weather**: Temperaturdiagramm so scharf wie der übrige Text ## [0.9.1] - 2026-11-14