diff --git a/web/app.py b/web/app.py index 6b719b8..45af05a 100644 --- a/web/app.py +++ b/web/app.py @@ -26,6 +26,16 @@ BIG_H = 5.0895 # major tick height SMALL_H = 2.6683 # minor tick height +_UNIT_AREA_WIDTH = 18.445 # canvas mm available for the unit label +_UNIT_SCALE_X = 0.96486402 +_UNIT_CHAR_EM = 0.65 # approximate advance-width ratio for GOST typ A + + +def _unit_font_size(unit: str) -> float: + n = max(1, len(unit)) + return min(18.7981, _UNIT_AREA_WIDTH / (n * _UNIT_SCALE_X * _UNIT_CHAR_EM)) + + def _fmt(v: float) -> str: if v == int(v): return str(int(v)) @@ -54,7 +64,7 @@ def generate_svg(unit, min_val, max_val, range_label, big_ticks, small_ticks, la ' M 58.443978,107.54692 H 183.64409 v 6.19963 H 58.443978 Z" />', # Unit label (large letter in left panel) - f' {escape(unit)}',