fix(rack): draw shelves after rails (match spec placement)

This commit is contained in:
sjat 2026-06-24 17:49:49 +02:00
parent aab58e3692
commit e08862b81d

View file

@ -384,6 +384,25 @@ def render_svg(rack: str, items: list[dict]) -> str:
if face in ("rear", "both"): if face in ("rear", "both"):
draw_device(fm, rear_x) draw_device(fm, rear_x)
def draw_rail(fm: dict, x: int) -> None:
color = KIND_COLORS.get(fm.get("kind", ""), DEFAULT_COLOR)
name = fm.get("hostname", "?")
cx = x + RAIL_W // 2
cy = top + body_h // 2
p.append(
f'<rect x="{x}" y="{top}" width="{RAIL_W}" height="{body_h}" '
f'fill="{color}" stroke="#333"/>'
)
p.append(
f'<text x="{cx}" y="{cy}" text-anchor="middle" fill="#ffffff" '
f'transform="rotate(-90 {cx} {cy})">{_esc(name)}</text>'
)
for idx, fm in enumerate(left_items):
draw_rail(fm, PAD + idx * RAIL_W)
for idx, fm in enumerate(right_items):
draw_rail(fm, rear_x + COL_W + idx * RAIL_W)
SHELF_STRIP_H = 6 SHELF_STRIP_H = 6
shelves = [i for i in items if i.get("kind") == "shelf"] shelves = [i for i in items if i.get("kind") == "shelf"]
mounted = [i for i in items if "mounted_on" in i] mounted = [i for i in items if "mounted_on" in i]
@ -431,25 +450,6 @@ def render_svg(rack: str, items: list[dict]) -> str:
for fm in sorted(shelves, key=lambda s: s.get("hostname", "")): for fm in sorted(shelves, key=lambda s: s.get("hostname", "")):
draw_shelf(fm) draw_shelf(fm)
def draw_rail(fm: dict, x: int) -> None:
color = KIND_COLORS.get(fm.get("kind", ""), DEFAULT_COLOR)
name = fm.get("hostname", "?")
cx = x + RAIL_W // 2
cy = top + body_h // 2
p.append(
f'<rect x="{x}" y="{top}" width="{RAIL_W}" height="{body_h}" '
f'fill="{color}" stroke="#333"/>'
)
p.append(
f'<text x="{cx}" y="{cy}" text-anchor="middle" fill="#ffffff" '
f'transform="rotate(-90 {cx} {cy})">{_esc(name)}</text>'
)
for idx, fm in enumerate(left_items):
draw_rail(fm, PAD + idx * RAIL_W)
for idx, fm in enumerate(right_items):
draw_rail(fm, rear_x + COL_W + idx * RAIL_W)
p.append("</svg>") p.append("</svg>")
return "\n".join(p) + "\n" return "\n".join(p) + "\n"