mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
Range bars and the lab list, detail rows, chart tooltip and reference ranges printed numbers with a plain `String()`, so a German reader saw "1.8 mIU/L" and "61.3 kg" under a German interface. The same was true of the mean, GMI, eA1C and the advanced indices on the glucose panel. `RangeBar` now prints value, bounds and delta through the locale number formatter and takes an optional `formatValue` for surfaces with their own precision. Lab values keep their trim rule (whole numbers bare, at most two decimals) in `formatLabValue`, which now hands the digits to a caller-supplied locale formatter; `useLabNumber` wires it to the reader's locale for every lab surface. Inputs are unchanged.
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
"use client";
|
||
|
||
import { RangeBar } from "@/components/targets/range-bar";
|
||
|
||
import { useLabNumber } from "./use-lab-format";
|
||
|
||
/**
|
||
* v1.37.34 — compact reference-range visualization for saved lab readings.
|
||
*
|
||
* The adapter keeps lab-specific data rules out of the shared target bar:
|
||
* qualitative readings are omitted, one-sided limits get a bounded visual
|
||
* scale, and invalid ranges remain text-only.
|
||
*/
|
||
export function LabReferenceRangeBar({
|
||
value,
|
||
referenceLow,
|
||
referenceHigh,
|
||
unit,
|
||
}: {
|
||
value: number | null;
|
||
referenceLow: number | null;
|
||
referenceHigh: number | null;
|
||
unit: string;
|
||
}) {
|
||
const labNumber = useLabNumber();
|
||
const hasLow = referenceLow !== null && Number.isFinite(referenceLow);
|
||
const hasHigh = referenceHigh !== null && Number.isFinite(referenceHigh);
|
||
if (
|
||
value === null ||
|
||
!Number.isFinite(value) ||
|
||
(!hasLow && !hasHigh) ||
|
||
(hasLow && hasHigh && referenceLow! >= referenceHigh!)
|
||
) {
|
||
return null;
|
||
}
|
||
|
||
// A missing endpoint gets a synthetic opposite edge only for positioning;
|
||
// the visible label still shows the original one-sided limit.
|
||
const scale = Math.max(Math.abs(referenceLow ?? referenceHigh!), 1);
|
||
const min = referenceLow ?? referenceHigh! - scale;
|
||
const max = referenceHigh ?? referenceLow! + scale;
|
||
const rangeLabel = !hasLow
|
||
? `≤${labNumber(referenceHigh!)} ${unit}`
|
||
: !hasHigh
|
||
? `≥${labNumber(referenceLow!)} ${unit}`
|
||
: `${labNumber(referenceLow!)}–${labNumber(referenceHigh!)} ${unit}`;
|
||
|
||
return (
|
||
<div
|
||
data-slot="lab-reference-range-bar"
|
||
className="w-full max-w-48 shrink-0"
|
||
aria-label={rangeLabel}
|
||
>
|
||
<RangeBar
|
||
value={value}
|
||
min={min}
|
||
max={max}
|
||
unit={unit}
|
||
compact
|
||
tone="lab"
|
||
formatValue={labNumber}
|
||
minLabel={referenceLow === null ? null : undefined}
|
||
maxLabel={referenceHigh === null ? null : undefined}
|
||
/>
|
||
</div>
|
||
);
|
||
}
|