Braille axis: the right scale was only an echo of the left

Marks now tick the left gutter alone and the right edge closes with a
bare border, handing its cells to the chart. Deep tallies compact to
k/M marks, and the gutter sizes to the widest mark actually printed -
a 1.5k peak reads 1k while a lower tick still lands three digits wide.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Fable 5 committed 2026-08-08 19:12:01 -04:00
1 parent 192179d79f
commit d00c6349eb
4 files changed
+91 -39

No files matched your search

+55 -22
View File
@@ -33,10 +33,12 @@ Beyond timelines, the module owns the app's two other braille conventions:
``width``-cell meter resolves ``2 × width`` levels.
* :func:`axis_caption` — the ``oldest → now`` line under a timeline, which
fills in intermediate marks whenever the chart is wide enough to fit them.
* :func:`axis_chart` — frames :func:`timeline_rows` output in a mirrored
numeric y-axis (the dashboard's activity chart, the Time Machine's per-day
and rhythm charts), so a chart quotes its scale on the gutters instead of
just naming the peak in its heading.
* :func:`axis_chart` — frames :func:`timeline_rows` output in a numeric y-axis
(the dashboard's activity chart, the Time Machine's per-day and rhythm
charts): marks on the left gutter only — the right edge closes with a bare
border, its mirror dropped as redundant (JP, 2026-08-08) — each mark
compacted through :func:`compact_label` so the gutter never outgrows three
cells however deep the tallies run.
"""
from __future__ import annotations
@@ -423,6 +425,34 @@ def axis_caption(
return Text(label.ljust(chars), style=style), [0]
def compact_label(value: float) -> str:
"""A y-axis mark that stays gutter-sized however deep the tally: ``999``, ``12k``, ``2M``.
Counts above 999 compact to a rounded ``k``/``M`` (JP, 2026-08-08) so a gutter mark
always fits three cells for any tally a mesh realistically produces, instead of a
five-digit day widening every chart's gutter. A signed value keeps its minus (the SNR
band's depths). Rounding suits the gutter's job — a tick quotes roughly what a bar
peaking at its dot means, not an exact ledger; the headings still carry exact counts.
"""
if abs(value) < 1000:
return str(round(value))
thousands = round(value / 1000)
if abs(thousands) < 1000:
return f"{thousands}k"
return f"{round(value / 1_000_000)}M"
def axis_label_w(peak: float, rows: int, *, lo: float = 0.0) -> int:
"""The gutter width a chart of this scale actually needs: its widest printed mark.
Sizing from the compacted *peak* alone under-measures: a ``1.5k`` peak prints as the
two-cell ``1k`` while a lower tick can still land at ``563`` — three cells. Callers
sharing one gutter across stacked charts take the max of this over each chart's
scale (and the default :func:`axis_chart` gutter is computed the same way).
"""
return max([1, *(len(mark) for mark in y_axis_labels(peak, rows, lo=lo))])
def y_axis_labels(peak: float, rows: int, *, lo: float = 0.0) -> list[str]:
"""Each chart row's ticked-dot value, top row first, dupes and zeros blanked.
@@ -430,17 +460,19 @@ def y_axis_labels(peak: float, rows: int, *, lo: float = 0.0) -> list[str]:
row's bottom, so each mark quotes the value of a bar peaking *at that dot* —
the reading the tick visibly points at, not the row's top edge — using the
same zero-folded scaling :func:`timeline_rows` draws bars with (baseline row
and all). A mark that would repeat the one above (a low peak makes
neighbouring dots round to the same value) or read zero is left blank, so the
scale never shows the same number twice. A signed chart passes its floor as
``lo`` (``< 0``): marks above the grey zero line quote rise heights, marks
below it hang depths, so the gutter shows both signs of a zero-crossing
series (an SNR band's ``+5 … −10 dB``) instead of only the positive peak.
and all), compacted through :func:`compact_label` so it never outgrows the
gutter. A mark that would repeat the one above (a low peak makes
neighbouring dots round to the same value — or to the same ``1k``) or read
zero is left blank, so the scale never shows the same number twice. A signed
chart passes its floor as ``lo`` (``< 0``): marks above the grey zero line
quote rise heights, marks below it hang depths, so the gutter shows both
signs of a zero-crossing series (an SNR band's ``+5 … −10 dB``) instead of
only the positive peak.
"""
total = rows * 4
base = _baseline_row(lo, peak, total)
labels: list[str] = []
seen: set[int] = set()
seen: set[str] = set()
for i in range(rows):
dot = (rows - 1 - i) * 4 + 2 # the dot row this row's ┤ tick crosses
if dot > base:
@@ -449,9 +481,10 @@ def y_axis_labels(peak: float, rows: int, *, lo: float = 0.0) -> list[str]:
value = round(lo * (base - dot + 1) / (base + 1))
else:
value = 0 # the tick sits on the zero baseline itself
if peak != lo and value and value not in seen:
labels.append(str(value))
seen.add(value)
mark = compact_label(value)
if peak != lo and value and mark not in seen:
labels.append(mark)
seen.add(mark)
else:
labels.append("")
return labels
@@ -519,11 +552,13 @@ def axis_chart(
floor: float = 0.0,
ticks: Optional[Sequence[tuple[int, str]]] = None,
) -> list[Text]:
"""Frame :func:`timeline_rows` output with a mirrored y-axis and x-axis caption.
"""Frame :func:`timeline_rows` output with a left y-axis and an x-axis caption.
Each row's top-edge value is mirrored on both gutters (blank where it would
repeat the mark above or read zero), closed with a boxed bottom border, and
followed by an x-axis caption indented to clear the gutter.
Each row's ticked-dot value marks the left gutter (blank where it would repeat
the mark above or read zero), compacted through :func:`compact_label`; the right
edge closes with a bare border — the mirrored gutter it used to carry was
redundant, and its cells go to the chart (JP, 2026-08-08). A boxed bottom border
and an x-axis caption indented to clear the gutter close the frame.
The caption comes one of two ways. A *continuous* chart passes ``label_at`` and
the ends-plus-quarters marks of :func:`axis_caption` fill in whatever fits. A
@@ -556,15 +591,13 @@ def axis_chart(
``len(chart_rows) + 2`` :class:`Text` lines: the decorated rows, the
bottom border, and the caption.
"""
label_w = label_w or max(1, len(str(round(peak))), len(str(round(floor))))
marks = y_axis_labels(peak, len(chart_rows), lo=floor)
label_w = label_w or max([1, *(len(mark) for mark in marks)])
out: list[Text] = []
for mark, row in zip(marks, chart_rows):
line = Text(f"{mark:>{label_w}} " + ("┤" if mark else "│"), style=style)
line.append_text(row)
line.append("├" if mark else "│", style=style)
if mark:
line.append(f" {mark}", style=style)
line.append("│", style=style)
out.append(line)
if ticks is not None:
border, caption_text = _tick_axis(chars, label_w, ticks, style)
+8 -8
View File
@@ -43,7 +43,7 @@ from rich.text import Text
from ..core.events import MeshEvent
from ..core.models import NODE_TYPE_REPEATER, Observation, utcnow
from ..persistence.repository import OBSERVATION_WINDOW
from .braillechart import axis_chart, meter, timeline_rows
from .braillechart import axis_chart, axis_label_w, meter, timeline_rows
from .packet_viewer import (
DEFAULT_ICON,
KIND_ICONS,
@@ -279,16 +279,16 @@ class DashboardScreen(Screen):
"""The all-packet chart — newest minute at the right — plus the pulse line.
One dot column per minute, two per character cell, stretched across every
cell the terminal offers between the two scale gutters; a wider terminal
simply shows more history. Time runs oldest→now left to right (every
MeshTerm timeline's direction), and the scale is mirrored on both edges so
the counts are readable from either end of a wide chart.
cell the terminal offers past the left scale gutter (the right edge closes
with a bare border — see :func:`~meshterm.ui.braillechart.axis_chart`); a
wider terminal simply shows more history. Time runs oldest→now left to
right, every MeshTerm timeline's direction.
"""
histogram = list(self._activity()) # newest first, one count per minute
# Size the label lane from the whole histogram's peak (not just the visible
# slice) so the gutters never shift as a burst scrolls out of view.
label_w = max(1, len(str(max(histogram, default=0))))
chars = max(10, width - 2 * (label_w + 2))
# slice) so the gutter never shifts as a burst scrolls out of view.
label_w = axis_label_w(max(histogram, default=0), _CHART_ROWS)
chars = max(10, width - (label_w + 3))
minutes = chars * 2
shown = (histogram + [0] * minutes)[:minutes]
peak = max(shown)
+23 -4
View File
@@ -257,16 +257,35 @@ def test_y_axis_labels_blanks_a_repeated_mark() -> None:
assert y_axis_labels(1, 3) == ["1", "", ""]
def test_axis_chart_mirrors_marks_on_both_gutters() -> None:
"""Each row's mark is framed by tick glyphs and repeated on both edges."""
def test_axis_chart_marks_the_left_gutter_only() -> None:
"""Marks tick the left gutter; the right edge closes with a bare border (no mirror)."""
rows = timeline_rows([9] * 8, rows=2)
out = axis_chart(rows, 9, 4, lambda f: "now" if f >= 1.0 else "old")
assert len(out) == 4 # 2 chart rows + bottom border + caption
assert out[0].plain == "8 ┤⣿⣿⣿⣿├ 8" # ticked-dot values (peak 9 sizes the gutter)
assert out[1].plain == "3 ┤⣿⣿⣿⣿├ 3"
assert out[0].plain == "8 ┤⣿⣿⣿⣿│" # ticked-dot value (the widest mark sizes the gutter)
assert out[1].plain == "3 ┤⣿⣿⣿⣿│"
assert out[2].plain.startswith(" └") and out[2].plain.endswith("┘")
def test_axis_chart_compacts_deep_tallies_into_the_gutter() -> None:
"""Counts above 999 read as k/M marks, and the gutter sizes to the widest printed mark.
A 1.5k peak prints ``1k`` while a lower tick still lands three digits wide (``563``),
so the gutter takes three cells — sized from the marks, never from the bare peak.
"""
from meshterm.ui.braillechart import axis_label_w, compact_label
assert compact_label(999) == "999" and compact_label(1500) == "2k"
assert compact_label(12_345) == "12k" and compact_label(2_000_000) == "2M"
assert compact_label(-1200) == "-1k"
rows = timeline_rows([1500] * 8, rows=2)
out = axis_chart(rows, 1500, 4, lambda f: "x")
assert axis_label_w(1500, 2) == 3
assert out[0].plain == " 1k ┤⣿⣿⣿⣿│" # round(1500 · 7/8) → 1312 → 1k
assert out[1].plain == "562 ┤⣿⣿⣿⣿│" # round(1500 · 3/8) → the three-digit tick
def test_y_axis_labels_signed_span_quotes_both_extremes() -> None:
"""A signed chart's marks quote rise heights above zero and hang depths below."""
# rows=3 over +8..-4 (baseline on dot 4): the top tick reads a 7-dot rise (7),
+5 -5
View File
@@ -85,8 +85,8 @@ def test_dashboard_renders_all_three_sections() -> None:
assert "advert" in body and "Alice" in body # traffic class + the busiest node
def test_dashboard_activity_chart_reads_newest_right_with_mirrored_scale() -> None:
"""'now' anchors the right edge and the scale marks mirror on both gutters.
def test_dashboard_activity_chart_reads_newest_right_with_left_scale() -> None:
"""'now' anchors the right edge; the scale marks the left gutter, the right closes bare.
Peak 9 over 3 rows (12 dots): the top gutter's ┤ tick crosses its row's third
dot (an 11-dot bar → 9·11/12 ≈ 8), so the mark reads 8, not the peak itself.
@@ -95,14 +95,14 @@ def test_dashboard_activity_chart_reads_newest_right_with_mirrored_scale() -> No
lines = _stripped(screen.render_body(80))
top = next(line for line in lines if "┤" in line)
assert top.strip().startswith("8 ┤")
assert top.rstrip().endswith("├ 8")
assert top.rstrip().endswith("│") # no mirrored mark — the cells went to the chart
caption = next(line for line in lines if "now" in line)
assert caption.index("−") < caption.index("now") # oldest left, newest right
# The lone newest-minute burst draws against the chart's right gutter, and the
# The lone newest-minute burst draws against the chart's right border, and the
# left half of the chart is bare flatline.
chart = [line for line in lines if "┤" in line or "│" in line]
bottom = chart[-1]
left_half = bottom[3 : 3 + (len(bottom) - 6) // 2]
left_half = bottom[3 : 3 + (len(bottom) - 4) // 2]
assert all(ch in (chr(0x2800), chr(0x2800 | 0x40 | 0x80), " ") for ch in left_half)
assert any(0x2800 <= ord(ch) <= 0x28FF and ord(ch) & 0x3F for ch in chart[0])