fix(units): keep converted values on the rounding helpers

The narrative, the workout distance and the elevation chart converted
through the unrounded escape hatch, and the trend caption scaled its
noise floor off the raw factor. They now take the rounded helpers, so a
narrated pound or mmol/L figure reads at the grain every screen shows
it, and the caption's floors are declared canonically (the distance
floor in metres). The trends row joins the chart-feeding surfaces that
may hand a raw scale to a chart.

Refs #1067
This commit is contained in:
Marc-André Bombeck committed 2026-10-01 09:17:44 +02:00
1 parent 0039bd1d1f
commit 9a282ed698
7 files changed
+33 -24

No files matched your search

@@ -13,7 +13,7 @@ import {
import { useTranslations } from "@/lib/i18n/context";
import { useUnitDisplay } from "@/hooks/use-unit-display";
import {
applyDisplayTransformUnrounded,
applyDisplayTransform,
getQuantityTransform,
} from "@/lib/measurements/display-transform";
@@ -41,8 +41,8 @@ export function WorkoutElevationChart({
const distance = getQuantityTransform("distance", preference);
const elevation = getQuantityTransform("elevation", preference);
const data = points.map((p) => ({
dist: applyDisplayTransformUnrounded(p.distanceM, distance),
alt: applyDisplayTransformUnrounded(p.altitude, elevation),
dist: applyDisplayTransform(p.distanceM, distance),
alt: applyDisplayTransform(p.altitude, elevation),
}));
return (
+8 -6
View File
@@ -265,7 +265,7 @@ export function TrendDescriptorCaption({
}) {
const { t } = useTranslations();
const { isAuthenticated } = useAuth();
const { toDisplay, transformFor, unitFor } = useUnitDisplay();
const { toDisplay, toDisplayDelta, unitFor } = useUnitDisplay();
const isMood = kind === "mood";
const primaryType = types[0] ?? "";
@@ -334,19 +334,21 @@ export function TrendDescriptorCaption({
const descriptor = useMemo(() => {
const meta = TREND_SLOT_DESCRIPTOR_META[metric];
// A slot that converts its series converts its noise floor with it (a
// floor is a difference: factor only).
// A slot that converts its series converts its noise floor with it: the
// floor is declared canonically and is a difference (factor only).
const config = isMood
? MOOD_DESCRIPTOR_CONFIG
: meta?.unitType
? {
...meta.config,
absoluteFloor:
meta.config.absoluteFloor * transformFor(meta.unitType).factor,
absoluteFloor: toDisplayDelta(
meta.unitType,
meta.config.absoluteFloor,
),
}
: meta?.config;
return computeTrendDescriptor(points, config);
}, [points, isMood, metric, transformFor]);
}, [points, isMood, metric, toDisplayDelta]);
// Tier 4 — genuinely too few points (also covers the in-flight window
// before the small series lands). Surface the real empty hint so the
@@ -1,7 +1,6 @@
import { getNumberFormat, getDateTimeFormat } from "@/lib/intl/formatter-cache";
import {
applyDisplayTransform,
applyDisplayTransformUnrounded,
getQuantityTransform,
paceSecondsPerDistanceUnit,
type UnitPreference,
@@ -46,7 +45,7 @@ export function formatDistance(
preference: UnitPreference,
): string {
const transform = getQuantityTransform("distance", preference);
const value = applyDisplayTransformUnrounded(meters, transform);
const value = applyDisplayTransform(meters, transform);
const formatted = getNumberFormat(locale, {
maximumFractionDigits: 2,
minimumFractionDigits: value < 10 ? 2 : 1,