Skip to content

Units: the popup and the timeseries follow a layer's unit switch - #675

Draft
BhattaraiSijan wants to merge 3 commits into
feat/666-unit-switch-legendfrom
feat/668-unit-popup-timeseries
Draft

BhattaraiSijan wants to merge 3 commits into
feat/666-unit-switch-legendfrom
feat/668-unit-popup-timeseries

Conversation

@BhattaraiSijan

@BhattaraiSijan BhattaraiSijan commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #668, #669. Part of #672. Third PR of the units epic, stacked on #674; review that first, this diff is against its branch. Base moves to feat/unit-conversion once it merges.

Size

Files Added Removed
Code 7 132 44
Tests 5 145 11

What

#674 let a viewer show a layer in another unit, and relabelled the legend. This PR makes the two other surfaces that print a layer's values follow: the feature popup and the timeseries card, both while already open and for anything opened later. One layer now reads in one unit everywhere. Switching back restores the original numbers exactly.

  • One shared helper. _shared/units/applyUnit.ts applies the map core hands out with a unit (shown = source × scale + offset) and takes it back, rounding to twelve significant digits. It imports nothing from core; plugins never resolve a unit, they ask layers:getUnit and do the arithmetic. The LayerManager's rescale write-back now uses it too.
  • The popup follows (Feature Popup shows the measured value in the layer's active unit #668). The measured property prints through the layer's active unit with that unit's label; every other row is untouched. While a card is open the plugin keeps what it showed, and on layer:unitChange for that layer it updates its cached unit and shows the card again at the same anchor. The popup service replaces an open card in place, and the replaced card's request answers "closed", which presses nothing. Later clicks use the new unit with no re-read of the layer configs. A switch on another layer, or with no card open, does nothing.
  • The timeseries follows (Timeseries shows its values in the layer's active unit #669). The fetcher converts every value into the active unit when it builds the chart payload and labels each series with it; the mismatch warning now compares the response's unit against the data's. The tool keeps the last merged response for the current selection, so on layer:unitChange it re-emits seriesReady from that response with no fetch and no loading state. The kept response is dropped with the selection. The chart stays unit-ignorant: it prints the string it is handed, and the downloaded CSV's value column now names it, PM2.5 (mg/m³).

Reading order

  1. src/essence/Tools/_shared/units/applyUnit.ts: applyUnit and unapplyUnit, the only arithmetic a plugin does.
  2. src/essence/Tools/LayerManager/adapters/handlers.ts: setRescale now goes through unapplyUnit.
  3. src/essence/Tools/FeaturePopup/FeaturePopupTool.js: formatValue, _showCard split out of the click handler, _onUnitChange, and the layer:unitChange subscription.
  4. src/essence/Tools/FetchTimeseries/lib/timeseries.ts: buildPayload takes layerUnit and converts points[].y; FetchTimeseriesTool.tsx: _lastResponse, _payloadFor, _onUnitChange.
  5. src/essence/Tools/SeriesChart/lib/chartData.ts: the CSV header names the unit.

Notes

  • The popup converts only the measured property (property from layers:getUnit); a layer with no property prints every row as before, unit switch or not.
  • A switch that arrives while a timeseries fetch is in flight is applied when the response is built, because the payload reads the selection's unit at build time; nothing is re-fetched.
  • Rounding to twelve significant digits restores the original values exactly for the factors in use (powers of ten); a factor such as 1/3 would round-trip to twelve digits, not bit for bit.
  • The area-of-interest statistics card reads a different response and does not convert; that is a follow-up.
  • Raster clicks have no popup until A click on a raster answers with its value, like a click on a vector #571 merges.

Testing

  • npx vitest run: 226 files, 3874 tests pass; npx tsc --noEmit clean
  • Air4US with the v313 units config, AQS PM₂.₅ switched to mg/m³: a monitor click reads 0.0097 mg/m³ where it read 9.7 μg/m³, and the other rows are unchanged
  • With a card and its timeseries open, switch the unit: the card and the chart redraw in mg/m³, the tooltip and footer name mg/m³, and the network tab shows no new fetch
  • Download the CSV: the value column is headed with the unit and holds converted values
  • Switch back to μg/m³: the original values, not rounded copies
  • NAQFC PM₂.₅ (no popup) and a layer with no options: nothing changes

🤖 Generated with Claude Code

@BhattaraiSijan
BhattaraiSijan force-pushed the feat/668-unit-popup-timeseries branch from 3f9e1a0 to 6ac8621 Compare November 23, 2026 16:02
@BhattaraiSijan
BhattaraiSijan force-pushed the feat/666-unit-switch-legend branch from 19893f1 to b0e6c2f Compare November 23, 2026 16:02
@BhattaraiSijan
BhattaraiSijan force-pushed the feat/668-unit-popup-timeseries branch from 6ac8621 to e551a1b Compare November 23, 2026 16:29
@BhattaraiSijan
BhattaraiSijan force-pushed the feat/666-unit-switch-legend branch from b0e6c2f to e037e57 Compare November 23, 2026 16:29

This branch has not been deployed

No deployments
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.

1 participant