"""TEMPLATE figures for a TN. Keep the source numbers here; build.py imports them.
Each figure is a function returning an SVG string; register it in FIGS."""
from mpmdoc.figkit import T, svg_open, INK, KICK, MUTE, LINE, RED, GRY
# ---- source numbers (one place only) ----
MEASURED = 51.0
LIMIT = 63.8
def bars():
W, L, R, top, rowh = 700, 150, 640, 30, 30
rows = [("Measured", MEASURED, INK), ("Reference", 20.4, GRY)]
vmax = 70.0
x = lambda v: L + v * (R - L) / vmax
bot = top + rowh * len(rows)
o = [svg_open(W, bot + 30)]
for v in range(0, 71, 10):
o.append(f'')
o.append(T(x(v), bot + 14, v, size=7.4, w=500, fill=MUTE, anchor="middle", fam="JetBrains Mono", ls=0))
o.append(f'')
o.append(T(x(LIMIT), top - 18, f"LIMIT ยท {LIMIT:.1f} W", size=6.8, w=800, fill=RED, anchor="middle", ls=1.0))
for i, (name, v, c) in enumerate(rows):
cy = top + i * rowh + rowh / 2
o.append(T(L - 10, cy + 3, name, size=8.2, anchor="end"))
o.append(f'')
o.append(T(x(v) + 6, cy + 3.2, f"{v:.1f} W", size=8.6, w=700, fam="JetBrains Mono", ls=0, halo=True))
o.append("")
return "".join(o)
FIGS = {"bars": bars}