Skip to content

Commit 1115a8e

Browse files
stevedekorteclaude
andcommitted
bench: hovering a legend key dims the other series
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent e574439 commit 1115a8e

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

‎bench/index.html‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
.chart-box svg{ display:block; }
4343
.legend{ display:flex; gap:6px 18px; flex-wrap:wrap; margin-top:12px; font-size:12.5px; color:#555; }
4444
.legend .swatch{ display:inline-block; width:18px; height:3px; border-radius:2px; vertical-align:middle; margin-right:6px; }
45+
.legend [data-metric]{ cursor:default; }
46+
.chart-box svg [data-metric]{ transition:opacity .15s ease; }
4547

4648
.status{ font-size:13px; color:#888; }
4749
.status.error{ border:1px solid #e3b3ae; background:#fbeae8; color:#8a2a22;
@@ -194,10 +196,10 @@
194196
const color = COLORS[mi % COLORS.length];
195197
if (pts.length > 1) {
196198
const path = pts.map((p, i) => (i ? "L" : "M") + p.x.toFixed(1) + " " + p.y.toFixed(1)).join(" ");
197-
svg += `<path d="${path}" fill="none" stroke="${color}" stroke-width="2" stroke-dasharray="${dashFor(hi)}"/>`;
199+
svg += `<path d="${path}" data-metric="${metric}" fill="none" stroke="${color}" stroke-width="2" stroke-dasharray="${dashFor(hi)}"/>`;
198200
}
199201
for (const p of pts) {
200-
svg += `<circle cx="${p.x.toFixed(1)}" cy="${p.y.toFixed(1)}" r="3.5" fill="${color}">` +
202+
svg += `<circle cx="${p.x.toFixed(1)}" cy="${p.y.toFixed(1)}" r="3.5" data-metric="${metric}" fill="${color}">` +
201203
`<title>${metric}: ${p.e.metrics[metric]} ${unit}\n${p.e.date} · ${p.e.commit} · ${p.e.machine}</title></circle>`;
202204
}
203205
});
@@ -206,12 +208,24 @@
206208
document.getElementById(containerId).innerHTML = svg;
207209

208210
const legend = metrics.map((m, i) =>
209-
`<span><span class="swatch" style="background:${COLORS[i % COLORS.length]}"></span>${m}</span>`);
211+
`<span data-metric="${m}"><span class="swatch" style="background:${COLORS[i % COLORS.length]}"></span>${m}</span>`);
210212
if (shownMachines.length > 1) {
211213
legend.push(...shownMachines.map((m, i) =>
212214
`<span><span class="swatch" style="background:#999;${i ? "background:repeating-linear-gradient(90deg,#999 0 4px,transparent 4px 8px)" : ""}"></span>${m}</span>`));
213215
}
214-
document.getElementById(legendId).innerHTML = legend.join("");
216+
const legendEl = document.getElementById(legendId);
217+
legendEl.innerHTML = legend.join("");
218+
219+
// hovering a legend key dims every other series in this chart
220+
const setFocus = metric => {
221+
document.querySelectorAll(`#${containerId} [data-metric]`).forEach(el => {
222+
el.style.opacity = metric && el.getAttribute("data-metric") !== metric ? 0.08 : 1;
223+
});
224+
};
225+
legendEl.querySelectorAll("[data-metric]").forEach(item => {
226+
item.addEventListener("mouseenter", () => setFocus(item.getAttribute("data-metric")));
227+
item.addEventListener("mouseleave", () => setFocus(null));
228+
});
215229
}
216230

217231
function render() {

0 commit comments

Comments
 (0)