Skip to content

Add a live solar conditions PNG badge and builder - #1274

Merged
accius merged 1 commit into
Stagingfrom
cursor/solar-badge-png-c5ce
Nov 21, 2026
Merged

accius merged 1 commit into
Stagingfrom
cursor/solar-badge-png-c5ce

Conversation

@accius

@accius accius commented Nov 21, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

Adds a public PNG badge of live solar and HF conditions so a QRZ biography (or any page that allows an image but not a script or iframe) can show OpenHamClock data instead of a third-party HamQSL banner.

GET /api/badge/solar.png draws SFI, sunspot number, Kp, A index, X-ray class, a UTC timestamp, and an HF day/night band row. Numbers are color-coded with the usual ham thresholds (SFI poor/fair/good/excellent, Kp quiet/unsettled/storm plus the NOAA G-scale, X-ray A/B, C, M, X). Band chips come from the in-process N0NBH cache and are labeled N0NBH. Sparklines use the SFI and Kp history already on the solar-indices payload. The image is rasterized with @resvg/resvg-wasm (no native addon, so Alpine, Pi, and the pkg binaries still work) and IBM Plex Sans, which is bundled because the production image has no system fonts.

The badge reads getSolarIndices() in-process — the same NOAA cache as /api/solar-indices — and does not call this server over HTTP. Renders are cached about five minutes per theme + fields + variant, concurrent misses share one render, and a missing upstream still returns a valid PNG that says "Data unavailable".

?theme= accepts every OpenHamClock app theme (read from src/styles/themes.css, so the colors stay in sync) plus red, blue, green, yellow, orange, purple, neutral, and neutral light. The default is dark, the app default. theme=red is the near-black / #e10600 brand lockup. Unknown themes, fields, and sizes fall back to the defaults. Status greens, yellows, and reds stay semantic; the theme only changes the background and the accent. GET /api/badge/themes lists them.

/badges (also /badge-builder) is a builder in the existing app: pick fields, size, and theme, watch the PNG update, and copy QRZ HTML, generic HTML, Markdown, or BBCode. It is linked from Settings → Community and the Help footer.

<a href="https://openhamclock.com"><img src="https://openhamclock.com/api/badge/solar.png" alt="OpenHamClock live solar conditions"></a>

QRZ: Edit page → Biography tab → switch the editor to HTML / source view → paste → Save.

Type of change

  • New feature
  • Documentation

How to test

  1. npx vitest run server/badge/status.test.js server/routes/badge.test.js src/components/BadgeBuilder.test.jsx
  2. Open /badges. Confirm the preview is a PNG, then change the theme, uncheck a field, and switch to Compact. The image and the QRZ/HTML/Markdown/BBCode snippets should follow.
  3. curl -sI localhost:3001/api/badge/solar.png should show Content-Type: image/png and Cache-Control: public, max-age=300.

Checklist

  • App loads without console errors
  • Tested in Dark, Light, and Retro themes (badge samples below; the builder page follows the selected OpenHamClock theme)
  • Responsive at different screen sizes (desktop + mobile)
  • If touching server.js: caches have TTLs and size caps (we serve 2,000+ concurrent users)
  • If adding an API route: includes caching and error handling
  • If adding a panel: wired into Modern, Classic, and Dockable layouts
  • No hardcoded colors — uses CSS variables (var(--accent-cyan), etc.)
  • No .bak, .old, console.log debug lines, or test scripts included

The builder page uses the app theme variables. The PNG itself has to bake colors in, including the semantic status colors, because it is a static image.

Screenshots (if visual change)

Builder (live NOAA data on this branch):

Badge builder

Theme switched to red; the snippet URL gains theme=red:

Builder with the red theme

Builder on a phone width

Badge samples (same conditions, different themes). Status colors stay put; the frame follows the theme.

Dark theme, the default

Red brand theme

Light theme

Retro theme

Matrix theme

Spring theme

Red theme with storm-level Kp (G2), poor SFI, and an M-class X-ray

Compact variant

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

Serve GET /api/badge/solar.png from the in-process NOAA cache, with themed frames, ham status meters, HF band chips, and a five-minute render cache. The /badges page previews the image and copies QRZ, HTML, Markdown, and BBCode snippets.

Co-authored-by: accius <accius@users.noreply.github.com>
@accius
accius changed the base branch from main to Staging November 21, 2026 23:48
@accius
accius merged commit 8c8625e into Staging Nov 21, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants