|
139 | 139 | chartReadout(rows.find(row => row.id === state.report)); |
140 | 140 | } |
141 | 141 |
|
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) { |
143 | 153 | const focused = document.activeElement?.closest("[data-report]")?.dataset.report; |
144 | 154 | const scrollLeft = $("chart-scroll")?.scrollLeft || 0; |
145 | 155 | const baselines = unique(groupRows.map(row => row.baseline)); |
|
245 | 255 | $("chart").append(unavailable); |
246 | 256 | } |
247 | 257 | scroll.scrollLeft = scrollLeft; |
| 258 | + if (reveal) revealSelection(); |
248 | 259 | updateChartSelection(); |
249 | 260 | if (focused) Array.from(stage.querySelectorAll("[data-report]")).find(point => point.dataset.report === focused)?.focus({preventScroll: true}); |
250 | 261 | } |
|
253 | 264 | $("matrix").hidden = !embedded; |
254 | 265 | $("chart").hidden = embedded; |
255 | 266 | if (embedded) renderMatrix(); |
256 | | - else renderChart(); |
| 267 | + else renderChart(true); |
257 | 268 | $("matrix-notes").textContent = unique(rows.flatMap(row => [...row.notes, ...row.warnings])).join(" "); |
258 | 269 | } |
259 | 270 |
|
|
309 | 320 | function render() { |
310 | 321 | renderFilters(); |
311 | 322 | // 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]; |
313 | 326 | state.version = null; |
314 | 327 | state.report = selected.id; |
315 | 328 | renderOverview(); |
|
0 commit comments