31 lines
1.5 KiB
Python
31 lines
1.5 KiB
Python
"""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'<line x1="{x(v):.1f}" y1="{top-6}" x2="{x(v):.1f}" y2="{bot}" stroke="{LINE}" stroke-width="0.8"/>')
|
||
|
|
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'<line x1="{x(LIMIT):.1f}" y1="{top-14}" x2="{x(LIMIT):.1f}" y2="{bot}" stroke="{RED}" stroke-width="1.4" stroke-dasharray="5 3"/>')
|
||
|
|
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'<rect x="{L}" y="{cy-8.5:.1f}" width="{x(v)-L:.1f}" height="17" rx="2" fill="{c}"/>')
|
||
|
|
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("</svg>")
|
||
|
|
return "".join(o)
|
||
|
|
|
||
|
|
|
||
|
|
FIGS = {"bars": bars}
|