Editorial diagram design for Claude Code, Codex, GitHub Copilot, Cursor, Factory Droid, Qoder, and Pi. 45 diagram types. Self-contained HTML + SVG. No shadows. No Mermaid slop.
fix(geometry): compare translated label masks in canvas space (#327)
Rudy Mizrahi Celekli8295d8ee2cc9
diff --git a/README.md b/README.mdindex f712633..fb97db4 100644--- a/README.md+++ b/README.md@@ -546,6 +546,8 @@ If you touch the Excalidraw import path, `python3 scripts/verify-excalidraw-impopass — it covers scene parsing, bound labels, groups and frames, adversarial labels,trust-boundary behavior, resource caps, named failures, and reference/command wiring.+Label masks and nodes are compared in canvas coordinates after supported enclosing or element `translate()` transforms, so separate snapshot panels do not overlap merely because they reuse local coordinates.+Label placement is gated geometrically: `python3 scripts/verify-geometry.py --all` fails CI when a label mask overlaps a node declared later in the document, because the node fill would clip the text at render time. The same script fails diagonal connectors, connectors that run along a node's border or attach at its corner, ports crowded closer than 12px, and arrows stacked on one trunk. `python3 scripts/test-verify-geometry.py` keeps that checker honest in both directions.Diagrams using the traceable block decomposition pattern get a structural gate on top of that: `python3 scripts/verify-block-registry.py --all` fails CI on a duplicate `data-block-id`, a `data-block-parent` that doesn't resolve to another block in the same file, a cycle in the parent chain, a blank `data-block-id`, or a missing or blank `data-block-name` — the same defects that would make `--registry`'s exported JSON (see [`export-registry.md`](skills/diagram-design/references/export-registry.md)) misrepresent the tree it claims to describe. `python3 scripts/test-verify-block-registry.py` keeps that checker honest in both directions.Treemaps get a second geometric gate, because their whole claim is that area *is* the encoding: `python3 scripts/verify-treemap.py --all` fails CI when a cell's share of the drawn area doesn't match the value printed inside it, or when a label overruns the cell it names. It measures area error as a *relative* figure — an absolute one passes exactly the small cells most likely to be wrong. `python3 scripts/test-verify-treemap.py` keeps it honest in both directions.diff --git a/scripts/test-verify-geometry.py b/scripts/test-verify-geometry.pyindex 36ff97c..0801021 100644--- a/scripts/test-verify-geometry.py+++ b/scripts/test-verify-geometry.py@@ -114,6 +114,27 @@ def main() -> int:0,)+ # Snapshot panels use their own local coordinates, but masking happens in+ # the shared canvas after enclosing and per-element translations.+ mask = '<rect x="50" y="80" width="80" height="12" fill="#fff"/>'+ panel_node = '<rect x="100" y="70" width="100" height="60" fill="#eee"/>'+ check("translated panels keep clear masks separate", document(+ mask + '<g transform="translate(300 0)">' + panel_node + '</g>'), 0)+ translated_mask = '<rect x="350" y="80" width="80" height="12" fill="#fff"/>'+ check("translated mask is clipped in canvas space", document(+ '<g transform="translate(-200 0)">' + translated_mask + '</g>' + panel_node), 1)+ check("nested translations accumulate", document(+ '<g transform="translate(-100 0)"><g transform="translate(-100 0)">'+ + translated_mask + '</g></g>' + panel_node), 1)+ check("element translation joins group translation", document(+ '<g transform="translate(-100 0)">'+ + translated_mask.replace('<rect ', '<rect transform="translate(-100 0)" ')+ + '</g>' + panel_node), 1)+ check("translated earlier node remains legal", document(+ panel_node + '<g transform="translate(-200 0)">' + translated_mask + '</g>'), 0)+ check("translated contained badge remains legal", document(+ '<g transform="translate(300 0)">' + badge + node + '</g>'), 0)+# A long mono plate (128px, as shipped in example-sequence-oauth.html) or a# wide CJK label plate must be recognized as a mask and checked like any other.check(diff --git a/scripts/verify-geometry.py b/scripts/verify-geometry.pyindex b6d7f2b..2bcab5e 100644--- a/scripts/verify-geometry.py+++ b/scripts/verify-geometry.py@@ -64,15 +64,6 @@ from pathlib import PathROOT = Path(__file__).resolve().parent.parentASSET_DIR = ROOT / "skills/diagram-design/assets"-RECT_RE = re.compile(- r"<rect\b[^>]*?"- r'\bx="(?P<x>-?[\d.]+)"\s+'- r'y="(?P<y>-?[\d.]+)"\s+'- r'width="(?P<w>[\d.]+)"\s+'- r'height="(?P<h>[\d.]+)"',- re.IGNORECASE,-)-NODE_MIN_W = 60.0NODE_MIN_H = 40.0MASK_MIN_W = 20.0@@ -102,18 +93,16 @@ class Rect:def parse_rects(source: str) -> list[Rect]:+ """Mask and node bounds in the same translated canvas as connectors."""rects: list[Rect] = []- for match in RECT_RE.finditer(source):- rects.append(- Rect(- float(match.group("x")),- float(match.group("y")),- float(match.group("w")),- float(match.group("h")),- source.count("\n", 0, match.start()) + 1,- match.start(),- )- )+ for tag, attrs, start, frame in shapes(source):+ if tag != "rect" or frame is None:+ continue+ x, y, w, h = (number(attrs, key) for key in ("x", "y", "width", "height"))+ if None in (x, y, w, h):+ continue+ rects.append(Rect(x + frame[0], y + frame[1], w, h,+ source.count("\n", 0, start) + 1, start))return rectsdiff --git a/skills/diagram-design/references/primitives-core.md b/skills/diagram-design/references/primitives-core.mdindex 5f0cb47..e6e16a1 100644--- a/skills/diagram-design/references/primitives-core.md+++ b/skills/diagram-design/references/primitives-core.md@@ -73,7 +73,7 @@ These six rules are **non-negotiable**. Run the pre-output checklist (SKILL.mdWhen in doubt, reroute. The exception exists for the narrow case where rerouting is geometrically impossible, not as a shortcut to avoid layout work.-6. **A label mask must not overlap a node drawn after it.** Rule 2 keeps the label off its own connector; this one keeps it off the boxes. Because nodes are painted after labels, a mask that lands partly inside a node is covered by the node fill and the text renders as a fragment sitting on the node border. Place the label on a segment of the connector that runs through open canvas — for a connector leaving a node's right edge, that means clearing the node's `x + width` before the mask starts. A mask fully *inside* a node is a badge chip and is fine; a mask overlapping a zone container is fine too, since zones are painted first. From a repository checkout, verify with `python3 <repo-root>/scripts/verify-geometry.py <file>`.+6. **A label mask must not overlap a node drawn after it.** Compare their bounds after supported group and element `translate()` offsets, in the shared canvas rather than separate panel-local coordinates. Rule 2 keeps the label off its own connector; this one keeps it off the boxes. Because nodes are painted after labels, a mask that lands partly inside a node is covered by the node fill and the text renders as a fragment sitting on the node border. Place the label on a segment of the connector that runs through open canvas — for a connector leaving a node's right edge, that means clearing the node's `x + width` before the mask starts. A mask fully *inside* a node is a badge chip and is fine; a mask overlapping a zone container is fine too, since zones are painted first. From a repository checkout, verify with `python3 <repo-root>/scripts/verify-geometry.py <file>`.## Node box — full pattern