reqdiagram.py¶
clew/wiki/reqdiagram.py
A requirement's evidence as a diagram: implementers → tests → result (round 5, P5.4).
_summary_svg
str clew.wiki.reqdiagram._summary_svg(Any row, list[str] impls, list[tuple[str, str]] tests)
The summary form: each implementer to result buckets with counts.
Source · 49 lines
def _summary_svg(row: Any, impls: list[str], tests: list[tuple[str, str]]) -> str:
"""SAYS IT IS A SUMMARY and where the whole list is, so a reader is never shown a cut-down
picture as if it were complete. An implementer → bucket edge means at least one test with
that result reaches it, from the same `extent` the full form draws.
@brief Summarised evidence.
@return SVG.
"""
reached = {test: set(names) for test, names in (row.extent or ())}
uncovered = set(row.implementers_uncovered or ())
counts: dict[str, int] = {}
for _test, status in tests:
counts[status] = counts.get(status, 0) + 1
buckets = [f"{n} {s}" for s, n in sorted(counts.items(), key=lambda kv: (-kv[1], kv[0]))]
statuses = sorted(counts, key=lambda s: (-counts[s], s))
widths = [_width(impls), _width(buckets)]
xs = [0.0, widths[0] + 2 * _GAP]
rows = max(len(impls), len(buckets), 1)
height = _PITCH * rows + 2 * _PITCH
parts = [
f'<text class="head" x="0" y="12">implemented by</text>'
f'<text class="head" x="{xs[1]:.0f}" y="12">results ({len(tests)} tests)</text>'
]
for i, name in enumerate(impls):
cls = "impl uncovered" if name in uncovered else "impl"
parts.append(_label(xs[0], _PITCH * (i + 1), name, cls))
for j, (label, status) in enumerate(zip(buckets, statuses, strict=True)):
parts.append(_label(xs[1], _PITCH * (j + 1), label, f"result r-{status}"))
for i, name in enumerate(impls):
if any(s == status and name in reached.get(t, ()) for t, s in tests):
parts.append(
f'<line class="edge" data-edge="{escape(name)}→{escape(status)}" '
f'x1="{widths[0] - _PAD + 6:.0f}" y1="{_PITCH * (i + 1)}" '
f'x2="{xs[1] - 6:.0f}" y2="{_PITCH * (j + 1)}"/>'
)
note = f"{len(tests)} tests, a summary by result: every test is in the tests table below"
head = f"results ({len(tests)} tests)"
parts.append(f'<text class="note" x="0" y="{height - 6}">{escape(note)}</text>')
## W-9 (owner review 2026-11-22): the width counts the header and the note too — both clipped.
total = max(xs[1] + max(widths[1], _width([head])) + _PAD, _width([note]) + _PAD, 420)
summary = f"{len(impls)} implementers, {len(tests)} tests: " + ", ".join(buckets)
return (
f'<svg class="req-evidence summary" role="img" aria-label="{escape(summary)}" '
f'viewBox="0 0 {total:.0f} {height}" width="{total:.0f}" height="{height}">'
+ "".join(parts)
+ "</svg>"
)
Activity · 26 steps
Requirements
evidence_svg
str clew.wiki.reqdiagram.evidence_svg(Any row)
The SVG for one requirement's evidence, or "" when it has neither implementer nor test.
Source · 38 lines
def evidence_svg(row: Any) -> str:
"""@brief Draw implementers, tests and results with the measured edges between them.
@return SVG, or "".
"""
impls = list(row.implementers)
tests = list(row.tests)
if not impls and not tests:
return ""
if len(tests) > SUMMARY_TESTS:
return _summary_svg(row, impls, tests)
reached = {test: set(names) for test, names in (row.extent or ())}
uncovered = set(row.implementers_uncovered or ())
widths = [_width(impls), _width([t for t, _s in tests]), _width([s for _t, s in tests])]
xs = [0.0, widths[0] + _GAP, widths[0] + widths[1] + 2 * _GAP]
height = _PITCH * max(len(impls), len(tests), 1) + _PITCH
parts = [_heads(xs)]
at = {name: _PITCH * (i + 1) for i, name in enumerate(impls)}
for name, y in at.items():
cls = "impl uncovered" if name in uncovered else "impl"
parts.append(_label(xs[0], y, name, cls))
for i, (test, status) in enumerate(tests):
y = _PITCH * (i + 1)
parts += [_label(xs[1], y, test, "test"), _label(xs[2], y, status, f"result r-{status}")]
parts += [
_edge(test, name, xs, widths, y, at[name])
for name in impls
if name in reached.get(test, ())
]
total = xs[2] + widths[2] + _PAD
summary = f"{len(impls)} implementers, {len(tests)} tests, {sum(1 for _t, s in tests if s == 'passed')} passed"
return (
f'<svg class="req-evidence" role="img" aria-label="{escape(summary)}" '
f'viewBox="0 0 {total:.0f} {height}" width="{total:.0f}" height="{height}">'
+ "".join(parts)
+ "</svg>"
)