fix(panel): eliminate virtual-scroll column jitter in step table

- Lock measured thead column widths with table-layout: fixed once virtualized rows mount, preserving horizontal scroll min-width on narrow viewports and unlocking automatically on layout, sort, locale, font-scale, or sizer changes
- Fix buildColumnSizerSpec tokPerSec scoring bug and improve proportional width estimation across badges, models, timing, pending pricing, and bold first-column rows
- Enable tabular-nums on .data-table cells to prevent sub-pixel width drift between digits
This commit is contained in:
fish
2026-11-24 02:12:28 +09:00
parent f7ed2e0aa8
commit b76a5889ca
5 changed files with 336 additions and 70 deletions
+149 -34
View File
@@ -21642,24 +21642,48 @@ const SIZER_ROW_KEY = '__vsizer__';
const SPACER_TOP_KEY = '__vspacer_top__'; const SPACER_TOP_KEY = '__vspacer_top__';
const SPACER_BOTTOM_KEY = '__vspacer_bottom__'; const SPACER_BOTTOM_KEY = '__vspacer_bottom__';
function estTokenChars(val) { function estProportionalTextWidth(text) {
const n = Math.max(0, Number(val || 0)); const s = String(text || '');
if (n >= 1_000_000) return n >= 10_000_000 ? 6 : 5; let w = 0;
if (n >= 100_000) return 6; for (let i = 0; i < s.length; i++) {
if (n >= 10_000) return 5; const code = s.charCodeAt(i);
if (n >= 1_000) return 4; if (code > 0x2e7f) {
if (n >= 100) return 3; w += 1.8;
if (n >= 10) return 2; } else if (
return 1; code === 105 || code === 108 || code === 73 || code === 116 || code === 102 ||
code === 114 || code === 46 || code === 44 || code === 58 || code === 59 ||
code === 45 || code === 47 || code === 32
) {
w += 0.55;
} else if (
code === 109 || code === 119 || code === 77 || code === 87 || code === 71 ||
code === 79 || code === 81 || code === 67
) {
w += 1.32;
} else {
w += 1.0;
}
}
return w;
} }
function estCostChars(val) { function estTokenChars(val) {
const n = Number(val); const n = Math.max(0, Number(val || 0));
if (!Number.isFinite(n) || n <= 0) return 1; if (n >= 1_000_000) return n >= 10_000_000 ? 6.4 : 5.6;
if (n >= 100) return 7; if (n >= 100_000) return 6.0;
if (n >= 10) return 6; if (n >= 10_000) return 5.0;
if (n >= 0.01) return 5; if (n >= 1_000) return 4.1;
return 7; if (n >= 100) return 3.0;
if (n >= 10) return 2.0;
return 1.0;
}
function estCostWidth(st) {
const c = st?.costUsd;
if (c == null || !Number.isFinite(Number(c))) {
return st?.isPricingPending ? estProportionalTextWidth(t('fmt.pricingPending')) : 1;
}
return estProportionalTextWidth(formatUsd(Number(c)));
} }
function estSegmentChars(seg, st) { function estSegmentChars(seg, st) {
@@ -21755,19 +21779,27 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
let bestCostObj = firstStep; let bestCostObj = firstStep;
let bestBadgeText = ''; let bestBadgeText = '';
let bestBadgeWidth = -1;
let bestBadgeClass = ''; let bestBadgeClass = '';
let hasBoldFirstCol = false;
const badgeCandidates = cellCtx?.showAgentBadge ? new Set() : null; const badgeCandidates = cellCtx?.showAgentBadge ? new Set() : null;
for (let i = 0; i < tableSteps.length; i++) { for (let i = 0; i < tableSteps.length; i++) {
const st = tableSteps[i]; const st = tableSteps[i];
if (!st || typeof st !== 'object') continue; if (!st || typeof st !== 'object') continue;
if (!hasBoldFirstCol && (isCompactionStepItem(st) || Number(st?.anomaly?.count) > 0)) {
hasBoldFirstCol = true;
}
if (badgeCandidates) { if (badgeCandidates) {
const bKey = `${st.agentKind || ''}|${st.isSubagent ? 1 : 0}|${st.isSideQuestion ? 1 : 0}|${st.agentOrdinal || 0}|${st.sideIndex || 0}|${st.agentIndex || 0}|${st.agentBadge || ''}`; const bKey = `${st.agentKind || ''}|${st.isSubagent ? 1 : 0}|${st.isSideQuestion ? 1 : 0}|${st.agentOrdinal || 0}|${st.sideIndex || 0}|${st.agentIndex || 0}|${st.agentBadge || ''}`;
if (!badgeCandidates.has(bKey)) { if (!badgeCandidates.has(bKey)) {
badgeCandidates.add(bKey); badgeCandidates.add(bKey);
const text = resolveBadgeTextForStep(st); const text = resolveBadgeTextForStep(st);
if (text.length > bestBadgeText.length) { const bw = estProportionalTextWidth(text);
if (bw > bestBadgeWidth) {
bestBadgeWidth = bw;
bestBadgeText = text; bestBadgeText = text;
bestBadgeClass = getAgentBadgeClass(st.agentIndex || 0, !st.isSubagent); bestBadgeClass = getAgentBadgeClass(st.agentIndex || 0, !st.isSubagent);
} }
@@ -21811,17 +21843,23 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
if (needTtft) { if (needTtft) {
const v = Number(st.ttftSec); const v = Number(st.ttftSec);
if (Number.isFinite(v) && v > maxTtftVal) { if (Number.isFinite(v) && v >= 0) {
maxTtftVal = v; const score = estProportionalTextWidth(formatMetric(v, 's')) * 1e6 + v;
bestTtftObj = st; if (score > maxTtftVal) {
maxTtftVal = score;
bestTtftObj = st;
}
} }
} }
if (needDuration) { if (needDuration) {
const v = Number(st.totalDurationSec ?? st.streamDurationSec); const v = Number(st.totalDurationSec ?? st.streamDurationSec);
if (Number.isFinite(v) && v > maxDurVal) { if (Number.isFinite(v) && v >= 0) {
maxDurVal = v; const score = estProportionalTextWidth(formatMetric(v, 's')) * 1e6 + v;
bestDurObj = st; if (score > maxDurVal) {
maxDurVal = score;
bestDurObj = st;
}
} }
} }
@@ -21907,7 +21945,7 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
if (needCost) { if (needCost) {
const c = Number(st.costUsd); const c = Number(st.costUsd);
const score = estCostChars(c) * 1e6 + (Number.isFinite(c) && c > 0 ? c : 0); const score = estCostWidth(st) * 1e6 + (Number.isFinite(c) && c > 0 ? c : 0);
if (score > bestCostScore) { if (score > bestCostScore) {
bestCostScore = score; bestCostScore = score;
bestCostObj = st; bestCostObj = st;
@@ -21918,13 +21956,13 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
if (needStep) colSteps.step = bestStepObj; if (needStep) colSteps.step = bestStepObj;
if (needTime) colSteps.time = bestTimeObj || firstStep; if (needTime) colSteps.time = bestTimeObj || firstStep;
if (needModel && modelCandidates) { if (needModel && modelCandidates) {
let bestModelLen = -1; let bestModelWidth = -1;
let bestModelObj = firstStep; let bestModelObj = firstStep;
for (const cand of modelCandidates.values()) { for (const cand of modelCandidates.values()) {
const disp = resolveModelDisplayInfo(cand, cellCtx?.displaySettings, { fallback: '—' }); const disp = resolveModelDisplayInfo(cand, cellCtx?.displaySettings, { fallback: '—' });
const len = disp.baseText?.length || 0; const w = estProportionalTextWidth(disp.baseText || '');
if (len > bestModelLen) { if (w > bestModelWidth) {
bestModelLen = len; bestModelWidth = w;
bestModelObj = cand; bestModelObj = cand;
} }
} }
@@ -21932,19 +21970,20 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
} }
if (needTps) { if (needTps) {
let longestReasonKey = null; let longestReasonKey = null;
let longestReasonLen = 0; let longestReasonWidth = 0;
if (reasonCandidates) { if (reasonCandidates) {
for (const rk of reasonCandidates) { for (const rk of reasonCandidates) {
const txt = speedReasonText(rk); const txt = speedReasonText(rk);
if (txt && txt.length > longestReasonLen) { const w = txt ? estProportionalTextWidth(txt) : 0;
longestReasonLen = txt.length; if (w > longestReasonWidth) {
longestReasonWidth = w;
longestReasonKey = rk; longestReasonKey = rk;
} }
} }
} }
colSteps.tps = { colSteps.tps = {
...(maxTpsObj || firstStep), ...(maxTpsObj || firstStep),
tokPerSec: maxTpsVal > 0 ? maxTpsVal : firstStep.tokPerSec, tokPerSec: maxTpsObj ? maxTpsObj.tokPerSec : firstStep.tokPerSec,
selectedSpeedReason: longestReasonKey, selectedSpeedReason: longestReasonKey,
}; };
} }
@@ -21967,7 +22006,8 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
colSteps, colSteps,
badgeText: bestBadgeText, badgeText: bestBadgeText,
badgeClass: bestBadgeClass, badgeClass: bestBadgeClass,
sig: `sizer:${bestBadgeText}:${sigParts.join('|')}`, hasBoldFirstCol,
sig: `sizer:${bestBadgeText}:${hasBoldFirstCol ? 1 : 0}:${sigParts.join('|')}`,
}; };
} }
@@ -22235,8 +22275,66 @@ const StepTableWidget = defineComponent({
let lastFontScale = 1; let lastFontScale = 1;
let calibratedSingleRowH = 0; let calibratedSingleRowH = 0;
let calibratedReasonRowH = 0; let calibratedReasonRowH = 0;
let lockedColKey = '';
let lockedPaneWidth = 0;
const rowPool = []; const rowPool = [];
function computeColLockKey(ds) {
if (!ds?.isVirtualized) return '';
return `${ds.locale}:${ds.colOrderSig}:${lastFontScale}:${ds.showAgentBadge ? 1 : 0}:${ds.railActive ? 1 : 0}:${ds.sortKey || ''}:${ds.sortDir || ''}:${ds.sizerSpec?.sig || ''}`;
}
function unlockColumnWidths() {
lockedColKey = '';
lockedPaneWidth = 0;
patchClasses(stepsTableEl, { 'is-cols-locked': false });
if (stepsTableEl.style) {
stepsTableEl.style.minWidth = '';
}
const ths = stepsTheadRow.children || [];
for (let i = 0; i < ths.length; i++) {
if (ths[i]?.style) ths[i].style.width = '';
}
}
function lockColumnWidthsIfNeeded() {
if (!activeDataset?.isVirtualized) return;
const paneW = Number(stepsTablePane.clientWidth || 0);
if (paneW <= 0) return;
const nextKey = computeColLockKey(activeDataset);
if (lockedColKey === nextKey && Math.abs(paneW - lockedPaneWidth) < 1) return;
const ths = stepsTheadRow.children || [];
const colCount = activeDataset.colKeys.length;
if (ths.length !== colCount) return;
// Release fixed layout momentarily if stale so browser resolves natural widths from sizer + header
if (stepsTableEl.classList?.contains('is-cols-locked')) {
unlockColumnWidths();
}
const widths = [];
for (let i = 0; i < colCount; i++) {
const w = Number(ths[i]?.getBoundingClientRect?.()?.width || 0);
if (!Number.isFinite(w) || w <= 0) return;
widths.push(w);
}
const tableW = Number(stepsTableEl.getBoundingClientRect?.()?.width || 0);
if (!Number.isFinite(tableW) || tableW <= 0) return;
for (let i = 0; i < colCount; i++) {
if (ths[i]?.style) {
ths[i].style.width = `${widths[i].toFixed(2)}px`;
}
}
if (stepsTableEl.style) {
stepsTableEl.style.minWidth = tableW > paneW + 0.5 ? `${tableW.toFixed(2)}px` : '';
}
patchClasses(stepsTableEl, { 'is-cols-locked': true });
lockedColKey = nextKey;
lockedPaneWidth = paneW;
}
function readUiFontScale() { function readUiFontScale() {
try { try {
if (typeof getComputedStyle === 'function') { if (typeof getComputedStyle === 'function') {
@@ -22299,6 +22397,7 @@ const StepTableWidget = defineComponent({
lastFontScale = nextScale; lastFontScale = nextScale;
calibratedSingleRowH = 0; calibratedSingleRowH = 0;
calibratedReasonRowH = 0; calibratedReasonRowH = 0;
unlockColumnWidths();
if (activeDataset?.isVirtualized) { if (activeDataset?.isVirtualized) {
const rebuilt = buildRowTops(activeDataset.tableSteps.length, activeDataset.hasReasonFlags); const rebuilt = buildRowTops(activeDataset.tableSteps.length, activeDataset.hasReasonFlags);
activeDataset.rowTops = rebuilt.rowTops; activeDataset.rowTops = rebuilt.rowTops;
@@ -22447,6 +22546,7 @@ const StepTableWidget = defineComponent({
calibrateRafId = 0; calibrateRafId = 0;
if (!activeDataset?.isVirtualized) return; if (!activeDataset?.isVirtualized) return;
if (Number(stepsTablePane.clientHeight || 0) <= 0) return; if (Number(stepsTablePane.clientHeight || 0) <= 0) return;
lockColumnWidthsIfNeeded();
const needSingle = calibratedSingleRowH <= 0; const needSingle = calibratedSingleRowH <= 0;
const needReason = calibratedReasonRowH <= 0 && activeDataset.hasAnyReason; const needReason = calibratedReasonRowH <= 0 && activeDataset.hasAnyReason;
if (!needSingle && !needReason) return; if (!needSingle && !needReason) return;
@@ -22539,7 +22639,12 @@ const StepTableWidget = defineComponent({
if (!activeDataset?.isVirtualized) return; if (!activeDataset?.isVirtualized) return;
const needSingle = calibratedSingleRowH <= 0; const needSingle = calibratedSingleRowH <= 0;
const needReason = calibratedReasonRowH <= 0 && activeDataset.hasAnyReason; const needReason = calibratedReasonRowH <= 0 && activeDataset.hasAnyReason;
if (!needSingle && !needReason) return; const paneW = Number(stepsTablePane.clientWidth || 0);
const needColLock =
!lockedColKey ||
lockedColKey !== computeColLockKey(activeDataset) ||
(paneW > 0 && Math.abs(paneW - lockedPaneWidth) >= 1);
if (!needSingle && !needReason && !needColLock) return;
if (calibrateRafId) return; if (calibrateRafId) return;
if (typeof requestAnimationFrame === 'function') { if (typeof requestAnimationFrame === 'function') {
calibrateRafId = requestAnimationFrame(calibrateRowHeights); calibrateRafId = requestAnimationFrame(calibrateRowHeights);
@@ -22772,6 +22877,7 @@ const StepTableWidget = defineComponent({
updateRow: (refs, item, _idx, tr) => { updateRow: (refs, item, _idx, tr) => {
if (item.isSizer) { if (item.isSizer) {
const spec = item.sizerSpec; const spec = item.sizerSpec;
patchClasses(tr, { 'has-bold-first': Boolean(spec.hasBoldFirstCol) });
if (refs.colOrderSig !== colOrderSig) { if (refs.colOrderSig !== colOrderSig) {
for (const [oldColKey, entry] of refs.cellMap) { for (const [oldColKey, entry] of refs.cellMap) {
if (!wantedSet.has(oldColKey)) { if (!wantedSet.has(oldColKey)) {
@@ -23104,6 +23210,10 @@ const StepTableWidget = defineComponent({
function refreshViewport() { function refreshViewport() {
if (!activeDataset?.isVirtualized) return; if (!activeDataset?.isVirtualized) return;
const scaleChanged = syncFontScaleIfChanged(); const scaleChanged = syncFontScaleIfChanged();
const paneW = Number(stepsTablePane.clientWidth || 0);
if (lockedColKey && paneW > 0 && Math.abs(paneW - lockedPaneWidth) >= 1) {
unlockColumnWidths();
}
renderCurrentWindow({ force: scaleChanged, enteringRowKeys: null }); renderCurrentWindow({ force: scaleChanged, enteringRowKeys: null });
scheduleCalibrateRowHeights(); scheduleCalibrateRowHeights();
} }
@@ -23327,8 +23437,13 @@ const StepTableWidget = defineComponent({
totalBodyH, totalBodyH,
sizerSpec, sizerSpec,
effectiveScopes, effectiveScopes,
sortKey: normSortKey,
sortDir: normSortDir,
formattedPrompts: new Map(), formattedPrompts: new Map(),
}; };
if (!isVirtualized || computeColLockKey(activeDataset) !== lockedColKey) {
unlockColumnWidths();
}
renderedSliceStart = -1; renderedSliceStart = -1;
renderedSliceEnd = -1; renderedSliceEnd = -1;
renderedTopSpacerH = -1; renderedTopSpacerH = -1;
+2 -2
View File
@@ -4,11 +4,11 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>用量监控</title> <title>用量监控</title>
<link rel="stylesheet" href="/styles.css?v=1795452753215"> <link rel="stylesheet" href="/styles.css?v=1795453915976">
<script src="/preload.js"></script> <script src="/preload.js"></script>
</head> </head>
<body> <body>
<div id="app-root"></div> <div id="app-root"></div>
<script src="/app.js?v=1795452753215"></script> <script src="/app.js?v=1795453915976"></script>
</body> </body>
</html> </html>
@@ -17,6 +17,8 @@ import {
buildStepAnomalyDiagnostic, buildStepAnomalyDiagnostic,
buildStepCompactionDiagnostic, buildStepCompactionDiagnostic,
buildStepTimingDiagnostic, buildStepTimingDiagnostic,
formatMetric,
formatUsd,
hasStepTimingData, hasStepTimingData,
resolveModelDisplayInfo, resolveModelDisplayInfo,
speedReasonText, speedReasonText,
@@ -55,24 +57,48 @@ const SIZER_ROW_KEY = '__vsizer__';
const SPACER_TOP_KEY = '__vspacer_top__'; const SPACER_TOP_KEY = '__vspacer_top__';
const SPACER_BOTTOM_KEY = '__vspacer_bottom__'; const SPACER_BOTTOM_KEY = '__vspacer_bottom__';
function estTokenChars(val) { function estProportionalTextWidth(text) {
const n = Math.max(0, Number(val || 0)); const s = String(text || '');
if (n >= 1_000_000) return n >= 10_000_000 ? 6 : 5; let w = 0;
if (n >= 100_000) return 6; for (let i = 0; i < s.length; i++) {
if (n >= 10_000) return 5; const code = s.charCodeAt(i);
if (n >= 1_000) return 4; if (code > 0x2e7f) {
if (n >= 100) return 3; w += 1.8;
if (n >= 10) return 2; } else if (
return 1; code === 105 || code === 108 || code === 73 || code === 116 || code === 102 ||
code === 114 || code === 46 || code === 44 || code === 58 || code === 59 ||
code === 45 || code === 47 || code === 32
) {
w += 0.55;
} else if (
code === 109 || code === 119 || code === 77 || code === 87 || code === 71 ||
code === 79 || code === 81 || code === 67
) {
w += 1.32;
} else {
w += 1.0;
}
}
return w;
} }
function estCostChars(val) { function estTokenChars(val) {
const n = Number(val); const n = Math.max(0, Number(val || 0));
if (!Number.isFinite(n) || n <= 0) return 1; if (n >= 1_000_000) return n >= 10_000_000 ? 6.4 : 5.6;
if (n >= 100) return 7; if (n >= 100_000) return 6.0;
if (n >= 10) return 6; if (n >= 10_000) return 5.0;
if (n >= 0.01) return 5; if (n >= 1_000) return 4.1;
return 7; if (n >= 100) return 3.0;
if (n >= 10) return 2.0;
return 1.0;
}
function estCostWidth(st) {
const c = st?.costUsd;
if (c == null || !Number.isFinite(Number(c))) {
return st?.isPricingPending ? estProportionalTextWidth(t('fmt.pricingPending')) : 1;
}
return estProportionalTextWidth(formatUsd(Number(c)));
} }
function estSegmentChars(seg, st) { function estSegmentChars(seg, st) {
@@ -168,19 +194,27 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
let bestCostObj = firstStep; let bestCostObj = firstStep;
let bestBadgeText = ''; let bestBadgeText = '';
let bestBadgeWidth = -1;
let bestBadgeClass = ''; let bestBadgeClass = '';
let hasBoldFirstCol = false;
const badgeCandidates = cellCtx?.showAgentBadge ? new Set() : null; const badgeCandidates = cellCtx?.showAgentBadge ? new Set() : null;
for (let i = 0; i < tableSteps.length; i++) { for (let i = 0; i < tableSteps.length; i++) {
const st = tableSteps[i]; const st = tableSteps[i];
if (!st || typeof st !== 'object') continue; if (!st || typeof st !== 'object') continue;
if (!hasBoldFirstCol && (isCompactionStepItem(st) || Number(st?.anomaly?.count) > 0)) {
hasBoldFirstCol = true;
}
if (badgeCandidates) { if (badgeCandidates) {
const bKey = `${st.agentKind || ''}|${st.isSubagent ? 1 : 0}|${st.isSideQuestion ? 1 : 0}|${st.agentOrdinal || 0}|${st.sideIndex || 0}|${st.agentIndex || 0}|${st.agentBadge || ''}`; const bKey = `${st.agentKind || ''}|${st.isSubagent ? 1 : 0}|${st.isSideQuestion ? 1 : 0}|${st.agentOrdinal || 0}|${st.sideIndex || 0}|${st.agentIndex || 0}|${st.agentBadge || ''}`;
if (!badgeCandidates.has(bKey)) { if (!badgeCandidates.has(bKey)) {
badgeCandidates.add(bKey); badgeCandidates.add(bKey);
const text = resolveBadgeTextForStep(st); const text = resolveBadgeTextForStep(st);
if (text.length > bestBadgeText.length) { const bw = estProportionalTextWidth(text);
if (bw > bestBadgeWidth) {
bestBadgeWidth = bw;
bestBadgeText = text; bestBadgeText = text;
bestBadgeClass = getAgentBadgeClass(st.agentIndex || 0, !st.isSubagent); bestBadgeClass = getAgentBadgeClass(st.agentIndex || 0, !st.isSubagent);
} }
@@ -224,17 +258,23 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
if (needTtft) { if (needTtft) {
const v = Number(st.ttftSec); const v = Number(st.ttftSec);
if (Number.isFinite(v) && v > maxTtftVal) { if (Number.isFinite(v) && v >= 0) {
maxTtftVal = v; const score = estProportionalTextWidth(formatMetric(v, 's')) * 1e6 + v;
bestTtftObj = st; if (score > maxTtftVal) {
maxTtftVal = score;
bestTtftObj = st;
}
} }
} }
if (needDuration) { if (needDuration) {
const v = Number(st.totalDurationSec ?? st.streamDurationSec); const v = Number(st.totalDurationSec ?? st.streamDurationSec);
if (Number.isFinite(v) && v > maxDurVal) { if (Number.isFinite(v) && v >= 0) {
maxDurVal = v; const score = estProportionalTextWidth(formatMetric(v, 's')) * 1e6 + v;
bestDurObj = st; if (score > maxDurVal) {
maxDurVal = score;
bestDurObj = st;
}
} }
} }
@@ -320,7 +360,7 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
if (needCost) { if (needCost) {
const c = Number(st.costUsd); const c = Number(st.costUsd);
const score = estCostChars(c) * 1e6 + (Number.isFinite(c) && c > 0 ? c : 0); const score = estCostWidth(st) * 1e6 + (Number.isFinite(c) && c > 0 ? c : 0);
if (score > bestCostScore) { if (score > bestCostScore) {
bestCostScore = score; bestCostScore = score;
bestCostObj = st; bestCostObj = st;
@@ -331,13 +371,13 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
if (needStep) colSteps.step = bestStepObj; if (needStep) colSteps.step = bestStepObj;
if (needTime) colSteps.time = bestTimeObj || firstStep; if (needTime) colSteps.time = bestTimeObj || firstStep;
if (needModel && modelCandidates) { if (needModel && modelCandidates) {
let bestModelLen = -1; let bestModelWidth = -1;
let bestModelObj = firstStep; let bestModelObj = firstStep;
for (const cand of modelCandidates.values()) { for (const cand of modelCandidates.values()) {
const disp = resolveModelDisplayInfo(cand, cellCtx?.displaySettings, { fallback: '—' }); const disp = resolveModelDisplayInfo(cand, cellCtx?.displaySettings, { fallback: '—' });
const len = disp.baseText?.length || 0; const w = estProportionalTextWidth(disp.baseText || '');
if (len > bestModelLen) { if (w > bestModelWidth) {
bestModelLen = len; bestModelWidth = w;
bestModelObj = cand; bestModelObj = cand;
} }
} }
@@ -345,19 +385,20 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
} }
if (needTps) { if (needTps) {
let longestReasonKey = null; let longestReasonKey = null;
let longestReasonLen = 0; let longestReasonWidth = 0;
if (reasonCandidates) { if (reasonCandidates) {
for (const rk of reasonCandidates) { for (const rk of reasonCandidates) {
const txt = speedReasonText(rk); const txt = speedReasonText(rk);
if (txt && txt.length > longestReasonLen) { const w = txt ? estProportionalTextWidth(txt) : 0;
longestReasonLen = txt.length; if (w > longestReasonWidth) {
longestReasonWidth = w;
longestReasonKey = rk; longestReasonKey = rk;
} }
} }
} }
colSteps.tps = { colSteps.tps = {
...(maxTpsObj || firstStep), ...(maxTpsObj || firstStep),
tokPerSec: maxTpsVal > 0 ? maxTpsVal : firstStep.tokPerSec, tokPerSec: maxTpsObj ? maxTpsObj.tokPerSec : firstStep.tokPerSec,
selectedSpeedReason: longestReasonKey, selectedSpeedReason: longestReasonKey,
}; };
} }
@@ -380,7 +421,8 @@ function buildColumnSizerSpec(tableSteps, colKeys, wantedSet, cellCtx) {
colSteps, colSteps,
badgeText: bestBadgeText, badgeText: bestBadgeText,
badgeClass: bestBadgeClass, badgeClass: bestBadgeClass,
sig: `sizer:${bestBadgeText}:${sigParts.join('|')}`, hasBoldFirstCol,
sig: `sizer:${bestBadgeText}:${hasBoldFirstCol ? 1 : 0}:${sigParts.join('|')}`,
}; };
} }
@@ -648,8 +690,66 @@ export const StepTableWidget = defineComponent({
let lastFontScale = 1; let lastFontScale = 1;
let calibratedSingleRowH = 0; let calibratedSingleRowH = 0;
let calibratedReasonRowH = 0; let calibratedReasonRowH = 0;
let lockedColKey = '';
let lockedPaneWidth = 0;
const rowPool = []; const rowPool = [];
function computeColLockKey(ds) {
if (!ds?.isVirtualized) return '';
return `${ds.locale}:${ds.colOrderSig}:${lastFontScale}:${ds.showAgentBadge ? 1 : 0}:${ds.railActive ? 1 : 0}:${ds.sortKey || ''}:${ds.sortDir || ''}:${ds.sizerSpec?.sig || ''}`;
}
function unlockColumnWidths() {
lockedColKey = '';
lockedPaneWidth = 0;
patchClasses(stepsTableEl, { 'is-cols-locked': false });
if (stepsTableEl.style) {
stepsTableEl.style.minWidth = '';
}
const ths = stepsTheadRow.children || [];
for (let i = 0; i < ths.length; i++) {
if (ths[i]?.style) ths[i].style.width = '';
}
}
function lockColumnWidthsIfNeeded() {
if (!activeDataset?.isVirtualized) return;
const paneW = Number(stepsTablePane.clientWidth || 0);
if (paneW <= 0) return;
const nextKey = computeColLockKey(activeDataset);
if (lockedColKey === nextKey && Math.abs(paneW - lockedPaneWidth) < 1) return;
const ths = stepsTheadRow.children || [];
const colCount = activeDataset.colKeys.length;
if (ths.length !== colCount) return;
// Release fixed layout momentarily if stale so browser resolves natural widths from sizer + header
if (stepsTableEl.classList?.contains('is-cols-locked')) {
unlockColumnWidths();
}
const widths = [];
for (let i = 0; i < colCount; i++) {
const w = Number(ths[i]?.getBoundingClientRect?.()?.width || 0);
if (!Number.isFinite(w) || w <= 0) return;
widths.push(w);
}
const tableW = Number(stepsTableEl.getBoundingClientRect?.()?.width || 0);
if (!Number.isFinite(tableW) || tableW <= 0) return;
for (let i = 0; i < colCount; i++) {
if (ths[i]?.style) {
ths[i].style.width = `${widths[i].toFixed(2)}px`;
}
}
if (stepsTableEl.style) {
stepsTableEl.style.minWidth = tableW > paneW + 0.5 ? `${tableW.toFixed(2)}px` : '';
}
patchClasses(stepsTableEl, { 'is-cols-locked': true });
lockedColKey = nextKey;
lockedPaneWidth = paneW;
}
function readUiFontScale() { function readUiFontScale() {
try { try {
if (typeof getComputedStyle === 'function') { if (typeof getComputedStyle === 'function') {
@@ -712,6 +812,7 @@ export const StepTableWidget = defineComponent({
lastFontScale = nextScale; lastFontScale = nextScale;
calibratedSingleRowH = 0; calibratedSingleRowH = 0;
calibratedReasonRowH = 0; calibratedReasonRowH = 0;
unlockColumnWidths();
if (activeDataset?.isVirtualized) { if (activeDataset?.isVirtualized) {
const rebuilt = buildRowTops(activeDataset.tableSteps.length, activeDataset.hasReasonFlags); const rebuilt = buildRowTops(activeDataset.tableSteps.length, activeDataset.hasReasonFlags);
activeDataset.rowTops = rebuilt.rowTops; activeDataset.rowTops = rebuilt.rowTops;
@@ -860,6 +961,7 @@ export const StepTableWidget = defineComponent({
calibrateRafId = 0; calibrateRafId = 0;
if (!activeDataset?.isVirtualized) return; if (!activeDataset?.isVirtualized) return;
if (Number(stepsTablePane.clientHeight || 0) <= 0) return; if (Number(stepsTablePane.clientHeight || 0) <= 0) return;
lockColumnWidthsIfNeeded();
const needSingle = calibratedSingleRowH <= 0; const needSingle = calibratedSingleRowH <= 0;
const needReason = calibratedReasonRowH <= 0 && activeDataset.hasAnyReason; const needReason = calibratedReasonRowH <= 0 && activeDataset.hasAnyReason;
if (!needSingle && !needReason) return; if (!needSingle && !needReason) return;
@@ -952,7 +1054,12 @@ export const StepTableWidget = defineComponent({
if (!activeDataset?.isVirtualized) return; if (!activeDataset?.isVirtualized) return;
const needSingle = calibratedSingleRowH <= 0; const needSingle = calibratedSingleRowH <= 0;
const needReason = calibratedReasonRowH <= 0 && activeDataset.hasAnyReason; const needReason = calibratedReasonRowH <= 0 && activeDataset.hasAnyReason;
if (!needSingle && !needReason) return; const paneW = Number(stepsTablePane.clientWidth || 0);
const needColLock =
!lockedColKey ||
lockedColKey !== computeColLockKey(activeDataset) ||
(paneW > 0 && Math.abs(paneW - lockedPaneWidth) >= 1);
if (!needSingle && !needReason && !needColLock) return;
if (calibrateRafId) return; if (calibrateRafId) return;
if (typeof requestAnimationFrame === 'function') { if (typeof requestAnimationFrame === 'function') {
calibrateRafId = requestAnimationFrame(calibrateRowHeights); calibrateRafId = requestAnimationFrame(calibrateRowHeights);
@@ -1185,6 +1292,7 @@ export const StepTableWidget = defineComponent({
updateRow: (refs, item, _idx, tr) => { updateRow: (refs, item, _idx, tr) => {
if (item.isSizer) { if (item.isSizer) {
const spec = item.sizerSpec; const spec = item.sizerSpec;
patchClasses(tr, { 'has-bold-first': Boolean(spec.hasBoldFirstCol) });
if (refs.colOrderSig !== colOrderSig) { if (refs.colOrderSig !== colOrderSig) {
for (const [oldColKey, entry] of refs.cellMap) { for (const [oldColKey, entry] of refs.cellMap) {
if (!wantedSet.has(oldColKey)) { if (!wantedSet.has(oldColKey)) {
@@ -1517,6 +1625,10 @@ export const StepTableWidget = defineComponent({
function refreshViewport() { function refreshViewport() {
if (!activeDataset?.isVirtualized) return; if (!activeDataset?.isVirtualized) return;
const scaleChanged = syncFontScaleIfChanged(); const scaleChanged = syncFontScaleIfChanged();
const paneW = Number(stepsTablePane.clientWidth || 0);
if (lockedColKey && paneW > 0 && Math.abs(paneW - lockedPaneWidth) >= 1) {
unlockColumnWidths();
}
renderCurrentWindow({ force: scaleChanged, enteringRowKeys: null }); renderCurrentWindow({ force: scaleChanged, enteringRowKeys: null });
scheduleCalibrateRowHeights(); scheduleCalibrateRowHeights();
} }
@@ -1740,8 +1852,13 @@ export const StepTableWidget = defineComponent({
totalBodyH, totalBodyH,
sizerSpec, sizerSpec,
effectiveScopes, effectiveScopes,
sortKey: normSortKey,
sortDir: normSortDir,
formattedPrompts: new Map(), formattedPrompts: new Map(),
}; };
if (!isVirtualized || computeColLockKey(activeDataset) !== lockedColKey) {
unlockColumnWidths();
}
renderedSliceStart = -1; renderedSliceStart = -1;
renderedSliceEnd = -1; renderedSliceEnd = -1;
renderedTopSpacerH = -1; renderedTopSpacerH = -1;
@@ -56,6 +56,19 @@
white-space: nowrap; white-space: nowrap;
} }
.data-table td {
font-variant-numeric: tabular-nums;
}
.data-table.is-cols-locked {
table-layout: fixed;
}
.data-table.is-cols-locked td:not(:first-child) {
overflow: hidden;
text-overflow: ellipsis;
}
.data-table th.is-right, .data-table th.is-right,
.data-table td.is-right { .data-table td.is-right {
text-align: right; text-align: right;
@@ -140,6 +153,10 @@
height: 0; height: 0;
} }
.data-table tbody tr.step-vsizer.has-bold-first td:first-child {
font-weight: 600;
}
.step-vsizer-inner { .step-vsizer-inner {
display: block; display: block;
height: 0; height: 0;
+17
View File
@@ -4189,6 +4189,19 @@ html[data-standalone="true"] .app-shell {
white-space: nowrap; white-space: nowrap;
} }
.data-table td {
font-variant-numeric: tabular-nums;
}
.data-table.is-cols-locked {
table-layout: fixed;
}
.data-table.is-cols-locked td:not(:first-child) {
overflow: hidden;
text-overflow: ellipsis;
}
.data-table th.is-right, .data-table th.is-right,
.data-table td.is-right { .data-table td.is-right {
text-align: right; text-align: right;
@@ -4273,6 +4286,10 @@ html[data-standalone="true"] .app-shell {
height: 0; height: 0;
} }
.data-table tbody tr.step-vsizer.has-bold-first td:first-child {
font-weight: 600;
}
.step-vsizer-inner { .step-vsizer-inner {
display: block; display: block;
height: 0; height: 0;