Files
HealthLog/src/lib/charts/axis-unit.ts
T
Marc-André Bombeck 4c06ecafe3 fix(dashboard): show the blood pressure axis in mmHg, not Hg
The dashboard's blood pressure chart passed `yAxisUnit="Hg"` beside
`unit="mmHg"`, a shortening carried since the first release, so every
tick read "154 Hg". The override is gone; "mmHg" is four characters and
fits the axis gutter like "bpm" and "mg/dL" do.

A unit with a space of its own ("/ 5") is now joined with no-break
spaces as well, so Recharts cannot wrap it either. A guard fails on any
`yAxisUnit` that is a cut-down form of the `unit` beside it.
2026-10-09 12:56:32 +02:00

34 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* The unit suffix a chart axis appends to each tick value ("62 bpm").
*
* Joined with a no-break space, never a plain one. Recharts word-wraps a
* tick label that is wider than the axis, and it measures the label in the
* page's body font rather than the tick's own 11 px, so "62 bpm" and
* "106 mg/dL" measured wider than their axis and broke onto two lines on
* every screen. The second line dropped onto the first x tick. A label with
* no breaking space is one word and stays on one line.
*/
export function axisUnitSuffix(
unit: string | null | undefined,
): string | undefined {
// A space inside the unit ("/ 5") would break the label the same way.
return unit ? ` ${unit.replace(/ /g, "\u00a0")}` : undefined;
}
/**
* The longest unit a tick label carries. A word-length unit ("Schritte",
* "Atemzüge/min", "mL/(kg·min)") made every tick wider than the fixed y-axis
* gutter, and the label was clipped at its left edge (".744 Schritte"). Such
* a unit stays off the ticks; the stat strip and the tile above the chart
* already name it.
*/
export const MAX_TICK_UNIT_LENGTH = 5;
/** The tick suffix for `unit`, or none when the unit is too long to fit. */
export function axisTickUnitSuffix(
unit: string | null | undefined,
): string | undefined {
if (!unit || unit.length > MAX_TICK_UNIT_LENGTH) return undefined;
return axisUnitSuffix(unit);
}