Skip to content

Commit e710d5e

Browse files
committed
Scroll the chart to the selected version
1 parent 8cbb032 commit e710d5e

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ use. It does not accept input reports inside its output.
260260
Select **Embed table** to copy an iframe for the current filters or download the
261261
group's complete Markdown/SVG table. Query parameters retain project, target,
262262
scope, profile, baseline, selected report, declaration status, kind, and search.
263-
A `version` parameter selects a version when no report is selected.
263+
A `version` parameter selects a version when no report is selected. Without
264+
either parameter, the newest version is selected. The chart scrolls to show the
265+
selected bar.
264266
The embedding page uses the same catalog and counts as the full report.
265267

266268
The `site` command does not collect releases, build candidates, schedule runs, or

‎Sources/InterfaceCoverage/SiteAssets/site.js‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,17 @@
139139
chartReadout(rows.find(row => row.id === state.report));
140140
}
141141

142-
function renderChart() {
142+
// Shows the selected bar when it is outside the visible part of the chart.
143+
function revealSelection() {
144+
const scroll = $("chart-scroll");
145+
const bar = scroll && Array.from(scroll.querySelectorAll("[data-report]")).find(item => item.dataset.report === state.report);
146+
if (!bar) return;
147+
const left = bar.offsetLeft, right = left + bar.offsetWidth;
148+
if (left >= scroll.scrollLeft && right <= scroll.scrollLeft + scroll.clientWidth) return;
149+
scroll.scrollLeft = Math.max(0, left + bar.offsetWidth / 2 - scroll.clientWidth / 2);
150+
}
151+
152+
function renderChart(reveal = false) {
143153
const focused = document.activeElement?.closest("[data-report]")?.dataset.report;
144154
const scrollLeft = $("chart-scroll")?.scrollLeft || 0;
145155
const baselines = unique(groupRows.map(row => row.baseline));
@@ -245,6 +255,7 @@
245255
$("chart").append(unavailable);
246256
}
247257
scroll.scrollLeft = scrollLeft;
258+
if (reveal) revealSelection();
248259
updateChartSelection();
249260
if (focused) Array.from(stage.querySelectorAll("[data-report]")).find(point => point.dataset.report === focused)?.focus({preventScroll: true});
250261
}
@@ -253,7 +264,7 @@
253264
$("matrix").hidden = !embedded;
254265
$("chart").hidden = embedded;
255266
if (embedded) renderMatrix();
256-
else renderChart();
267+
else renderChart(true);
257268
$("matrix-notes").textContent = unique(rows.flatMap(row => [...row.notes, ...row.warnings])).join(" ");
258269
}
259270

@@ -309,7 +320,9 @@
309320
function render() {
310321
renderFilters();
311322
// Summary links name a version, because report IDs change when reports are generated again.
312-
const selected = rows.find(row => row.id === state.report) || rows.find(row => row.version === state.version) || rows[0];
323+
// Without a report or version, select the newest version.
324+
const version = state.version || versionOrder(unique(rows.map(row => row.version))).at(-1);
325+
const selected = rows.find(row => row.id === state.report) || rows.find(row => row.version === version) || rows[0];
313326
state.version = null;
314327
state.report = selected.id;
315328
renderOverview();

0 commit comments

Comments
 (0)