Scale unit label font size to fit left panel for multi-character strings
This commit is contained in:
+11
-1
@@ -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' <text style="font-size:18.7981px;font-family:\'ГОСТ тип А\',monospace;fill:#1a1a1a"'
|
||||
f' <text style="font-size:{_unit_font_size(unit):.4f}px;font-family:\'ГОСТ тип А\',monospace;fill:#1a1a1a"'
|
||||
f' x="41.455711" y="109.03796"'
|
||||
f' transform="scale(0.96486402,1.0364155)">{escape(unit)}</text>',
|
||||
|
||||
|
||||
Reference in New Issue
Block a user