mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 13:01:00 +00:00
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.
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
/**
|
||
* 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);
|
||
}
|