Skip to content

Commit d13cc58

Browse files
mvanhornpablodeymo
andauthored
feat(forkchoice): add color legend to fork choice viz (#338)
# Pull Request Template ## 🗒️ Description / Motivation Adds a four-swatch color legend to the right side of the `info-bar` on the fork choice visualization (`crates/net/rpc/static/fork_choice.html`). Issue #335 lists the four colors the viz uses and asks for an in-page legend so users do not have to guess which color means what. The mapping lives in the `COLORS` object inside the page script (lines 178-181) and is never surfaced in the rendered UI today, so anyone looking at the viz either has to know the convention from project docs or open dev tools and read the JS source. A small swatch-and-label list in the existing top bar fixes that without changing any of the actual viz logic. ## What Changed `crates/net/rpc/static/fork_choice.html`: - Adds `#legend`, `.legend-item`, and `.legend-swatch` CSS rules in the existing `<style>` block. The legend uses `margin-left: auto` so it pins to the right edge of the `#info-bar`, and `flex-wrap: wrap` so it relaxes onto a second line on narrow viewports without breaking the existing Head/Justified/Finalized/Validators value cards. - Adds a `<div id="legend" aria-label="Block color legend">` element after the `Validators` item inside `#info-bar`. Four `.legend-item` rows, one per role: Finalized (`#4caf50`), Justified (`#2196f3`), Safe target (`#ffeb3b`), Head (`#ff9800`). Hex values are copied from the `COLORS` object in the existing JS so the swatches cannot drift from the actual rendered colors. Label text uses the same casing convention (uppercase, 11px, `#888`) the existing info-bar labels use. No JavaScript changes. The `COLORS` object stays the single source of truth for what each role renders as; the legend is hand-keyed to match. ## Correctness / Behavior Guarantees - No JS logic touched. The viz still renders nodes through `nodeColor(node, data)` (line 209) using the same `COLORS` object that drives the new legend swatches. - No new network calls or polling. The legend is static markup. - The existing `#info-bar` flex container is preserved. The legend is appended after the `Validators` item; the existing four value cards keep their original order and alignment. - `aria-label="Block color legend"` is set on the legend container so screen readers announce the section. - `flex-wrap: wrap` on `#info-bar` was already present in the existing styles, so the legend wrapping onto a second line on narrow viewports does not change layout behavior elsewhere. ## Tests Added / Run `fork_choice.html` is a static asset served directly by the RPC layer (`GET /lean/v0/fork_choice/ui`). There is no compile or asset build step to run, so the existing test suite does not cover it. I did not bring up a node + browser locally to confirm the legend renders (no devnet available in this environment). The swatch hex values are byte-equal to the `.value-*` CSS rules and the JS `COLORS` object that already exist in the file, so the displayed swatches cannot drift from the actual node colors. After the change: ``` $ grep -F "background: #" crates/net/rpc/static/fork_choice.html <div class="legend-item"><span class="legend-swatch" style="background: #4caf50;"></span>Finalized</div> <div class="legend-item"><span class="legend-swatch" style="background: #2196f3;"></span>Justified</div> <div class="legend-item"><span class="legend-swatch" style="background: #ffeb3b;"></span>Safe target</div> <div class="legend-item"><span class="legend-swatch" style="background: #ff9800;"></span>Head</div> ``` matches the four entries in the existing `COLORS = { finalized, justified, safeTarget, head }` declaration. ## Related Issues / PRs - Closes #335 Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-authored-by: Pablo Deymonnaz <pdeymon@fi.uba.ar>
1 parent c1ff5de commit d13cc58

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

crates/net/rpc/static/fork_choice.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,31 @@
7878
.value-finalized { color: #4caf50; }
7979
.value-validators { color: #e0e0e0; }
8080

81+
#legend {
82+
display: flex;
83+
gap: 12px;
84+
margin-left: auto;
85+
flex-wrap: wrap;
86+
align-items: center;
87+
}
88+
89+
.legend-item {
90+
display: flex;
91+
align-items: center;
92+
gap: 6px;
93+
font-size: 11px;
94+
color: #888;
95+
text-transform: uppercase;
96+
letter-spacing: 1px;
97+
}
98+
99+
.legend-swatch {
100+
width: 10px;
101+
height: 10px;
102+
border-radius: 50%;
103+
flex-shrink: 0;
104+
}
105+
81106
#chart-container {
82107
flex: 1;
83108
overflow: auto;
@@ -185,6 +210,12 @@
185210
<span class="label">Validators</span>
186211
<span class="value value-validators" id="validator-count">--</span>
187212
</div>
213+
<div id="legend" aria-label="Block color legend">
214+
<div class="legend-item"><span class="legend-swatch" style="background: #4caf50;"></span>Finalized</div>
215+
<div class="legend-item"><span class="legend-swatch" style="background: #2196f3;"></span>Justified</div>
216+
<div class="legend-item"><span class="legend-swatch" style="background: #ffeb3b;"></span>Safe target</div>
217+
<div class="legend-item"><span class="legend-swatch" style="background: #ff9800;"></span>Head</div>
218+
</div>
188219
<button id="follow-head-toggle" type="button" aria-pressed="true">Following Head</button>
189220
</div>
190221

0 commit comments

Comments
 (0)