Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion kaievolve/viewer/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,11 @@ def compare_page():
"delta": f"{delta:.4f}" if abs(delta) > 1e-9 else "best",
"delta_cls": dcls,
"level": svg.hbar(
a.best_mean - lo + 1e-9, (hi - lo) + 1e-9, width=150, height=14
a.best_mean - lo + 1e-9,
(hi - lo) + 1e-9,
width=150,
height=14,
show_label=False, # gap is already shown in the 'vs best' column
),
"spark": (
svg.sparkline(curves[a.label], lo=clo, hi=chi)
Expand Down
22 changes: 16 additions & 6 deletions kaievolve/viewer/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,31 @@ def effect_bar(delta: float, scale: float, width: int = 200, height: int = 20) -
# ─── horizontal bar (model usage etc.) ───────────────────────────────────────


def hbar(value: float, max_value: float, width: int = 180, height: int = 16) -> str:
"""A plain left-anchored bar with the count at its end. For 'AI models used'
and similar small categorical breakdowns."""
def hbar(
value: float, max_value: float, width: int = 180, height: int = 16, show_label: bool = True
) -> str:
"""A plain left-anchored bar. With ``show_label`` (the default) the integer
``value`` is printed at the bar's end - for count breakdowns like 'AI models
used'. Set ``show_label=False`` when the bar encodes a continuous magnitude
(e.g. a score gap) whose exact value already lives in an adjacent column;
an ``int()`` count label would otherwise read as a meaningless '0'."""
if max_value <= 0:
return _empty(width, height)
frac = max(0.0, min(1.0, value / max_value))
w = frac * (width - 34)
pad = 34 if show_label else 4
w = frac * (width - pad)
y = height * 0.5
label = (
f'<text x="{_f(w + 5)}" y="{_f(y + 3.5)}" font-size="10" fill="{MUTED}">{int(value)}</text>'
if show_label
else ""
)
return (
f'<svg width="{width}" height="{height}" viewBox="0 0 {width} {height}" '
f'font-family="ui-sans-serif,system-ui,sans-serif">'
f'<rect x="0" y="{_f(y - 4)}" width="{_f(w)}" height="8" '
f'fill="{ACCENT}" rx="1"/>'
f'<text x="{_f(w + 5)}" y="{_f(y + 3.5)}" font-size="10" '
f'fill="{MUTED}">{int(value)}</text>'
f"{label}"
f"</svg>"
)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def test_charts_well_formed(self):
self._well_formed(svg.effect_bar(0.0, 0.0)) # zero delta + zero scale
self._well_formed(svg.hbar(12, 40))
self._well_formed(svg.hbar(0, 0)) # empty
self._well_formed(svg.hbar(0.07, 0.2, show_label=False)) # magnitude bar, no label

def test_hbar_label_toggle(self):
# count bars print the integer value; magnitude bars omit it so a
# fractional gap doesn't render as a meaningless int() '0'
self.assertIn("<text", svg.hbar(12, 40))
self.assertNotIn("<text", svg.hbar(0.07, 0.2, show_label=False))

def test_effect_bar_sign_color(self):
self.assertIn(svg.POS, svg.effect_bar(0.05, 0.1))
Expand Down
Loading