(region)
| 188 | } |
| 189 | |
| 190 | function metricTable(region) { |
| 191 | const host = el('section', 'metrics-block'); |
| 192 | const own = region.metrics.length ? region.metrics : region.context_metrics; |
| 193 | if (!own.length) return host; |
| 194 | host.append(el('h3', '', region.metrics.length ? 'Region measurements' : 'Enclosing function measurements')); |
| 195 | const table = el('table'); |
| 196 | const head = el('thead'), row = el('tr'); |
| 197 | for (const name of viewSnapshot ? ['Metric card', 'Snapshot value'] : ['Metric card', 'Before', 'After', 'Change']) { const cell = el('th', '', name); cell.scope = 'col'; row.append(cell); } |
| 198 | head.append(row); table.append(head); |
| 199 | let body = el('tbody'); |
| 200 | const nodes = own.map(id => byId.get(id)).filter(Boolean).sort((left, right) => |
| 201 | left.properties.observation.subject.localeCompare(right.properties.observation.subject) || metricId(left).localeCompare(metricId(right))); |
| 202 | const subjects = new Set(nodes.map(node => node.properties.observation.subject)); |
| 203 | let previousSubject = null; |
| 204 | for (const node of nodes) { |
| 205 | if (subjects.size > 1 && node.properties.observation.subject !== previousSubject) { |
| 206 | if (body.childElementCount) table.append(body); |
| 207 | body = el('tbody'); |
| 208 | const group = el('tr'), heading = el('th', '', node.properties.observation.subject); |
| 209 | heading.colSpan = viewSnapshot ? 2 : 4; heading.scope = 'rowgroup'; group.append(heading); body.append(group); |
| 210 | previousSubject = node.properties.observation.subject; |
| 211 | } |
| 212 | const metric = metricId(node), observation = node.properties.observation; |
| 213 | const row = el('tr'), label = el('td'); |
| 214 | label.append(cardCallout(metric, metricCards.get(metric)?.title || metric)); |
| 215 | row.append(label); |
| 216 | for (const side of viewSnapshot ? ['after'] : ['before', 'after']) { |
| 217 | const sample = observation[side], cell = el('td', 'metric-value'); |
| 218 | cell.append(el('span', '', describeValue(sample))); |
| 219 | if (sample.reason) cell.append(detail('Reason', el('p', 'unknown-text', sample.reason))); |
| 220 | row.append(cell); |
| 221 | } |
| 222 | if (!viewSnapshot) row.append(el('td', '', changeText(node))); |
| 223 | body.append(row); |
| 224 | } |
| 225 | table.append(body); host.append(table); |
| 226 | return host; |
| 227 | } |
| 228 | |
| 229 | function counterpart(region, side) { |
| 230 | if (side === region.side) return { start: region.start_line, end: region.end_line, note: region.start_line ? 'Selected recorded region' : 'File-level context; no source range was reported' }; |
no test coverage detected