Skip to content

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(charts): parse complete displayed numeric tokens (#333)

Rudy Mizrahi Celekli76e7e26a8bee
diff --git a/scripts/test-verify-sankey.py b/scripts/test-verify-sankey.py
index aa91d9c..a0e1405 100644
--- a/scripts/test-verify-sankey.py
+++ b/scripts/test-verify-sankey.py
@@ -1034,6 +1034,51 @@ def main() -> int:
else:
print("OK: --all refuses to run with a shipped variant missing")
+ with tempfile.TemporaryDirectory() as raw:
+ directory = Path(raw)
+ # Printed quantities may use scientific notation without changing the geometry.
+ fractional = re.sub(r'>([0-9][0-9,]*) min</text>',
+ lambda m: f'>{int(m.group(1).replace(",", "")) / 100000:g} min</text>', source)
+ fractional = re.sub(r'>0(\.[0-9]+) min</text>', r'>\1 min</text>', fractional)
+ quantity_pattern = r'>([0-9][0-9,]*) min</text>'
+ tiny, count = re.subn(quantity_pattern, '>1e-310 min</text>', source)
+ if count != 8:
+ failures.append(f"tiny-quantity fixture expected eight labels, found {count}")
+ tiny_finite = re.sub(
+ quantity_pattern,
+ lambda m: f'>{int(m.group(1).replace(",", "")) * 1e-305:g} min</text>',
+ source,
+ )
+ large_finite = re.sub(
+ quantity_pattern,
+ lambda m: f'>{int(m.group(1).replace(",", "")) * 1e300:g} min</text>',
+ source,
+ )
+ relative_overflow = large_finite.replace('>1.2e+304 min</text>', '>1e-305 min</text>', 1)
+ if relative_overflow == large_finite:
+ failures.append("could not build the relative-scale overflow fixture")
+ numeric_cases = (
+ ("equivalent scientific", source.replace('>12,000 min</text>', '>1.2e4 min</text>'), True, ""),
+ ("explicit plus and uppercase exponent", source.replace('>12,000 min</text>', '>+1.2E4 min</text>'), True, ""),
+ ("leading decimal with exponent", source.replace('>12,000 min</text>', '>.12e5 min</text>'), True, ""),
+ ("fractional quantity scale", fractional, True, ""),
+ ("wrong exponent", source.replace('>12,000 min</text>', '>1.2e3 min</text>'), False, "off the scale"),
+ ("negative quantity", source.replace('>12,000 min</text>', '>−1.2e4 min</text>'), False, "must be finite and positive"),
+ ("overflowing quantity", source.replace('>12,000 min</text>', '>1e400 min</text>'), False, "must be finite and positive"),
+ ("incomplete exponent", source.replace('>12,000 min</text>', '>1.2e min</text>'), False, "no readable value"),
+ ("eight tiny quantities cannot bypass scale fidelity", tiny, False, "scale must be finite and positive"),
+ ("tiny quantities with a finite shared scale", tiny_finite, True, ""),
+ ("finite scales with an overflowing relative comparison", relative_overflow, False, "non-finite relative scale"),
+ )
+ for index, (name, changed, expected_pass, finding) in enumerate(numeric_cases):
+ path = directory / f'numeric-{index}.html'
+ path.write_text(changed, encoding="utf-8")
+ code, output = run(path)
+ if (code == 0) != expected_pass or (not expected_pass and finding not in output) or "Traceback" in output:
+ failures.append(f"numeric case {name} unexpected result: {output.strip()}")
+ else:
+ print(f"OK: numeric case {name}")
+
for failure in failures:
print(f"FAIL: {failure}")
if failures:
diff --git a/scripts/test-verify-treemap.py b/scripts/test-verify-treemap.py
index d0aca2f..e3f0e02 100644
--- a/scripts/test-verify-treemap.py
+++ b/scripts/test-verify-treemap.py
@@ -560,6 +560,36 @@ def main() -> int:
else:
print("OK: every hosted percentage claim must agree")
+ # Punctuation glued to a word must not hide a contradictory claim.
+ for separator in ("-", "_", "."):
+ changed = source.replace("4.78B · 59% of world", f"4.78B{separator}99% of world", 1)
+ code, output = run(write(directory, f"glued-percentage-{ord(separator)}.html", changed))
+ if code == 0:
+ failures.append(f"word-glued {separator!r} percentage was silently ignored")
+ elif "percentage" not in output:
+ failures.append(f"word-glued {separator!r} lacked a percentage diagnostic")
+ else:
+ print(f"OK: word-glued {separator!r} percentage cannot hide a claim")
+
+ # Commas separating a magnitude from a percentage are punctuation,
+ # while grouped digits remain one complete number.
+ for label, claim, expected_pass, expected_finding in (
+ ("comma-matching", "4.78B,59% of world", True, ""),
+ ("comma-scientific-matching", "4.78B,5.9e1% of world", True, ""),
+ ("comma-conflicting", "4.78B,99% of world", False, "is labelled 99%"),
+ ("comma-second-conflicting", "4.78B · 59%,99% of world", False, "conflicting percentage claims"),
+ ("comma-grouped-number", "4.78B,1,059% of world", False, "is labelled 1059%"),
+ ("comma-negative-number", "4.78B,-59% of world", False, "is labelled -59%"),
+ ):
+ changed = source.replace("4.78B · 59% of world", claim, 1)
+ code, output = run(write(directory, f"{label}.html", changed))
+ if (code == 0) != expected_pass or (
+ not expected_pass and expected_finding not in output
+ ):
+ failures.append(f"{label}: unexpected percentage result: {output.strip()}")
+ else:
+ print(f"OK: {label} keeps complete percentage claims")
+
# 15. Explicit metadata outranks both sides of the decorative-rect
# heuristic. A declared cell cannot disappear merely because a bad
# edit makes it implausibly wide or tall.
@@ -640,6 +670,27 @@ def main() -> int:
else:
print("OK: XML-encoded cx/cy/r retain marker containment checks")
+ with tempfile.TemporaryDirectory() as directory:
+ d = Path(directory)
+ for label, claim, expect_pass, finding in (
+ ("negative", "-59%", False, "labelled -59%"),
+ ("unicode-minus", "\u221259%", False, "labelled -59%"),
+ ("scientific", "5.9e1%", True, ""),
+ ("positive-sign", "+59%", True, ""),
+ ("leading-decimal", ".590e2%", True, ""),
+ ("wrong-exponent", "5.9e2%", False, "labelled 590%"),
+ ("signed-conflict", "59% and -59%", False, "conflicting percentage claims"),
+ ("non-finite-claim", "1e400%", False, "must be finite numeric"),
+ ):
+ changed = source.replace("59% of world", claim + " of world")
+ code, output = run(write(d, "percentage-" + label + ".html", changed))
+ if changed == source or (code == 0) != expect_pass:
+ failures.append(f"{label} percentage behaved incorrectly: {output.strip()}")
+ elif finding and finding not in output:
+ failures.append(f"{label} percentage lacked its finding: {output.strip()}")
+ else:
+ print(f"OK: {label} percentage is read as one complete numeric claim")
+
for failure in failures:
print(f"FAIL: {failure}")
if failures:
diff --git a/scripts/verify-sankey.py b/scripts/verify-sankey.py
index ce7b279..e1cf093 100644
--- a/scripts/verify-sankey.py
+++ b/scripts/verify-sankey.py
@@ -109,6 +109,7 @@ from __future__ import annotations
import argparse
import html
+import math
import re
import sys
from pathlib import Path
@@ -266,7 +267,10 @@ TAG_RE = re.compile(r"<[^>]+>")
# leading number ONLY - requiring a unit word right after it silently stops
# matching the moment the format changes to something like "9,400 - 78%", and a
# value check that attaches to nothing passes everything.
-VALUE_RE = re.compile(r"^(?P<num>\d[\d,]*(?:\.\d+)?)(?![\d,.])")
+VALUE_RE = re.compile(
+ r"^(?P<num>[-+\u2212]?(?:\d[\d,]*(?:\.\d*)?|\.\d+)"
+ r"(?:[eE][-+]?\d+)?)(?![\d,.eE])"
+)
# A node bar is a thin vertical rect inside the plot band. The legend keys are
# 16x8 and the two background rects are the full viewBox, so both fall out on
@@ -707,7 +711,14 @@ def attach_values(source: str, bars: list[Bar], findings: list[str], name: str)
# the first and moving on lets a second, contradictory number sit in the
# same block: the checker validates the one it read, and the reader is
# shown the one it ignored.
- host.values.append((float(hit.group("num").replace(",", "")), body))
+ value = float(hit.group("num").replace(",", "").replace("\u2212", "-"))
+ if not math.isfinite(value) or value <= 0:
+ findings.append(
+ f"{name}:{line_of(source, m.start())}: the node quantity {body!r} "
+ "must be finite and positive for its drawn height"
+ )
+ continue
+ host.values.append((value, body))
if host.value is None:
host.value = host.values[0][0]
host.label = body
@@ -1178,11 +1189,31 @@ def check(path: Path) -> list[str]:
f"height is then compared against nothing, and the fidelity check "
f"below silently shrinks to the bars that do parse"
)
- scaled = [(bar, bar.h / bar.value) for bar in bars if bar.value]
+ scaled = []
+ for bar in bars:
+ if not bar.value:
+ continue
+ scale = bar.h / bar.value
+ if not math.isfinite(scale) or scale <= 0:
+ findings.append(
+ f"{name}:{line_of(source, bar.offset)}: node {bar.label!r} draws "
+ f"{bar.h:.2f}px for {bar.value:g}, which produces a non-finite "
+ f"or non-positive scale — the quantity scale must be finite and "
+ f"positive before value fidelity can be checked"
+ )
+ continue
+ scaled.append((bar, scale))
if len(scaled) >= 3:
reference = sorted(s for _, s in scaled)[len(scaled) // 2] # median
for bar, scale in scaled:
relative = (scale - reference) / reference * 100
+ if not math.isfinite(relative):
+ findings.append(
+ f"{name}:{line_of(source, bar.offset)}: node {bar.label!r} "
+ f"produces a non-finite relative scale — the quantity range "
+ f"cannot be compared on the figure's shared scale"
+ )
+ continue
if abs(relative) > SCALE_TOL:
findings.append(
f"{name}:{line_of(source, bar.offset)}: node {bar.label!r} draws "
diff --git a/scripts/verify-treemap.py b/scripts/verify-treemap.py
index 6e10d0e..14876ff 100644
--- a/scripts/verify-treemap.py
+++ b/scripts/verify-treemap.py
@@ -58,7 +58,11 @@ TAG_RE = re.compile(r"<[^>]+>")
# a percentage ("59%", "0.6%") is already the claimed share. Reading "0.6%" as
# the number 0.6 against cells measured in billions produces nonsense, so the
# percentage pattern is tried first and anchored on the sign.
-PCT_RE = re.compile(r"(?P<num>\d[\d,]*(?:\.\d+)?)\s*%")
+PCT_RE = re.compile(
+ r"(?<![\w.+\-\u2212])(?<!\d,)"
+ r"(?P<num>[-+\u2212]?(?:\d[\d,]*(?:\.\d*)?|\.\d+)"
+ r"(?:[eE][-+]?\d+)?)\s*%"
+)
VALUE_RE = re.compile(r"(?P<num>\d[\d,]*(?:\.\d+)?)\s*(?P<unit>[BMK])\b")
MONO_ADVANCE = 0.62
@@ -277,7 +281,8 @@ def _number(match: re.Match[str] | None) -> float | None:
if match is None:
return None
try:
- return float(match.group("num").replace(",", ""))
+ value = float(match.group("num").replace(",", "").replace("\u2212", "-"))
+ return value if math.isfinite(value) else None
except ValueError:
return None
@@ -473,11 +478,23 @@ def check(path: Path) -> list[str]:
# percentage in the hosted labels: search() alone silently accepted a
# later contradictory claim when the first happened to be correct.
label_text = " ".join(labels[index])
- percentages = [
- value
- for match in PCT_RE.finditer(label_text)
- if (value := _number(match)) is not None
- ]
+ percentages = []
+ matches = list(PCT_RE.finditer(label_text))
+ consumed_signs = {match.end() - 1 for match in matches}
+ if any(char == "%" and index not in consumed_signs for index, char in enumerate(label_text)):
+ findings.append(
+ f"{path.name}:{line_of(source, cell.offset)}: percentage claim "
+ "is not a complete numeric token — every percent sign must be parsed"
+ )
+ for match in matches:
+ percentage = _number(match)
+ if percentage is None:
+ findings.append(
+ f"{path.name}:{line_of(source, cell.offset)}: percentage claim "
+ f"{match.group(0)!r} must be finite numeric"
+ )
+ else:
+ percentages.append(percentage)
distinct_percentages: list[float] = []
for percentage in percentages:
if not any(
diff --git a/skills/diagram-design/references/type-sankey.md b/skills/diagram-design/references/type-sankey.md
index 953e96c..b801f13 100644
--- a/skills/diagram-design/references/type-sankey.md
+++ b/skills/diagram-design/references/type-sankey.md
@@ -2,6 +2,9 @@
**Best for:** showing where a *quantity* goes as it splits and merges across a small number of stages — CI compute budgets, funnel-adjacent volume flows, cost or headcount allocation. This is the one type where band **thickness carries data**; if the reader doesn't need to compare magnitudes, use process or pyramid instead.
+Printed node quantities preserve their complete numeric token, including finite decimal or scientific notation before the unit suffix. A quantity must be positive for a visible node bar; signs and exponents must not be discarded while checking its scale.
+The resulting pixels-per-unit scale and relative comparisons must also be finite; a quantity outside that arithmetic range is rejected rather than certified.
+
## Layout conventions
- **Exactly 3 stage columns**, left → right. No more, no less — above 3 stages, split into two linked diagrams.
diff --git a/skills/diagram-design/references/type-treemap.md b/skills/diagram-design/references/type-treemap.md
index a947125..1ed6c5e 100644
--- a/skills/diagram-design/references/type-treemap.md
+++ b/skills/diagram-design/references/type-treemap.md
@@ -29,6 +29,8 @@ Parseable numeric label positions and font sizes must be finite, and font sizes
### Declaring the share
+Printed percentages are read as complete signed numbers, including leading decimals and scientific notation; `5.9e1%` means 59%, while `-59%` contradicts a positive share. Non-finite percentage claims are findings.
+
**Every cell carries `data-share` — including cells too small to label.** It is the cell's percentage of the whole, and it is what makes the area checkable:
```svg