fix(panel): eliminate hover flicker in monthly chart and breakdown rows

- Replace the 3px .monthly-grid column gap with zero-gap column padding and hand off hover across adjacent active months without hiding or restarting the popover fade-in
- Wrap the progress bar and model-name footer inside a single .cons-source-hover-zone across client sources, project ranking, and session ranking so crossing the vertical gap keeps the popover and highlight steady
This commit is contained in:
fish
2026-11-24 02:59:32 +09:00
parent 2e1126a88f
commit 49e346c0ca
7 changed files with 373 additions and 213 deletions
+131 -85
View File
@@ -29873,6 +29873,7 @@ const ConsumptionView = defineComponent({
});
let activeHoverTargetEl = null;
let activeHoverPayload = null;
let cachedBreakdownRootRect = null;
let cachedBreakdownAnchorRect = null;
@@ -29889,6 +29890,7 @@ const ConsumptionView = defineComponent({
function hideBreakdownPopover() {
cachedBreakdownRootRect = null;
cachedBreakdownAnchorRect = null;
activeHoverPayload = null;
if (activeHoverTargetEl) {
patchClasses(activeHoverTargetEl, { 'is-hovered': false });
activeHoverTargetEl = null;
@@ -29964,6 +29966,9 @@ const ConsumptionView = defineComponent({
hideBreakdownPopover();
return;
}
const wasHidden = breakdownPopoverEl.hasAttribute('hidden');
const sameTargetAndPayload =
!wasHidden && activeHoverTargetEl === anchorEl && activeHoverPayload === payload;
if (activeHoverTargetEl && activeHoverTargetEl !== anchorEl) {
patchClasses(activeHoverTargetEl, { 'is-hovered': false });
cachedBreakdownAnchorRect = null;
@@ -29972,8 +29977,10 @@ const ConsumptionView = defineComponent({
cachedBreakdownAnchorRect = null;
}
activeHoverTargetEl = anchorEl;
activeHoverPayload = payload;
patchClasses(anchorEl, { 'is-hovered': true });
if (!sameTargetAndPayload) {
popoverContent.update({
title: payload.title || '—',
calls: payload.calls || 0,
@@ -29986,8 +29993,8 @@ const ConsumptionView = defineComponent({
outputTokens: payload.outputTokens,
segments: Array.isArray(payload.segments) ? payload.segments : [],
});
}
const wasHidden = breakdownPopoverEl.hasAttribute('hidden');
patchAttr(breakdownPopoverEl, 'hidden', false);
positionBreakdownPopover(anchorEl, pointerClientX, pointerClientY);
if (wasHidden) {
@@ -30010,6 +30017,19 @@ const ConsumptionView = defineComponent({
return { el: segEl, refs: { segEl } };
}
let monthlyGridEl = null;
const monthlyColByEl = new Map();
function findMonthlyColForNode(node) {
let cur = node;
while (cur && cur !== monthlyGridEl) {
const hit = monthlyColByEl.get(cur);
if (hit) return hit;
cur = cur.parentNode || null;
}
return null;
}
const monthlyCols = Array.from({ length: 12 }, (_, idx) => {
const costText = h('span', { className: 'month-cost text-mono', text: '' });
const stackWrap = h('div', { className: 'month-stack' });
@@ -30036,6 +30056,9 @@ const ConsumptionView = defineComponent({
e?.clientY ?? null
);
} else {
if (activeHoverTargetEl && monthlyColByEl.has(activeHoverTargetEl)) {
hideBreakdownPopover();
}
e?.stopPropagation?.();
}
},
@@ -30044,8 +30067,16 @@ const ConsumptionView = defineComponent({
positionBreakdownPopover(colEl, e?.clientX ?? null, e?.clientY ?? null);
}
},
onMouseLeave: () => {
if (activeHoverTargetEl === colEl) hideBreakdownPopover();
onMouseLeave: (e) => {
if (activeHoverTargetEl !== colEl) return;
const nextEl = e?.relatedTarget || null;
if (nextEl) {
const nextCol = findMonthlyColForNode(nextEl);
if ((nextCol && nextCol.colState.hoverPayload) || nextEl === monthlyGridEl) {
return;
}
}
hideBreakdownPopover();
},
},
[
@@ -30055,7 +30086,7 @@ const ConsumptionView = defineComponent({
tokText,
]
);
return {
const colRec = {
el: colEl,
costText,
stackWrap,
@@ -30064,8 +30095,23 @@ const ConsumptionView = defineComponent({
tokText,
colState,
};
monthlyColByEl.set(colEl, colRec);
return colRec;
});
monthlyGridEl = h(
'div',
{
className: 'monthly-grid',
onMouseLeave: () => {
if (activeHoverTargetEl && monthlyColByEl.has(activeHoverTargetEl)) {
hideBreakdownPopover();
}
},
},
monthlyCols.map((c) => c.el)
);
const monthlyPanel = h('section', { className: 'panel' }, [
h('div', { className: 'panel-header' }, [
h('span', { className: 'panel-title' }, [
@@ -30074,11 +30120,7 @@ const ConsumptionView = defineComponent({
]),
monthlyHoverHint,
]),
h(
'div',
{ className: 'monthly-grid' },
monthlyCols.map((c) => c.el)
),
monthlyGridEl,
]);
const scrollInner = h(
@@ -30567,6 +30609,54 @@ const ConsumptionView = defineComponent({
/**
* 创建客户端来源单行 DOM 结构(保留长尾合并分段配色进度条、单行不换行的 Top 2-3 模型速览和右侧总调用数,悬停进度条或速览区弹出完整明细浮层)。
*/
function isNodeInside(root, node) {
if (!root || !node) return false;
if (typeof root.contains === 'function') return root.contains(node);
let cur = node;
while (cur) {
if (cur === root) return true;
cur = cur.parentNode || null;
}
return false;
}
function attachUnifiedHoverZone(zoneEl, compatTargets, rowState) {
zoneEl.addEventListener('mouseenter', (e) => {
if (rowState.hoverPayload) {
showBreakdownPopover(zoneEl, rowState.hoverPayload, e?.clientX ?? null, e?.clientY ?? null);
}
});
zoneEl.addEventListener('mousemove', (e) => {
if (rowState.hoverPayload && activeHoverTargetEl === zoneEl) {
positionBreakdownPopover(zoneEl, e?.clientX ?? null, e?.clientY ?? null);
}
});
zoneEl.addEventListener('mouseleave', () => {
if (activeHoverTargetEl === zoneEl) hideBreakdownPopover();
});
for (const childEl of compatTargets) {
if (!childEl) continue;
childEl.addEventListener('mouseenter', (e) => {
if (rowState.hoverPayload) {
showBreakdownPopover(zoneEl, rowState.hoverPayload, e?.clientX ?? null, e?.clientY ?? null);
}
});
childEl.addEventListener('mousemove', (e) => {
if (rowState.hoverPayload && activeHoverTargetEl === zoneEl) {
positionBreakdownPopover(zoneEl, e?.clientX ?? null, e?.clientY ?? null);
}
});
childEl.addEventListener('mouseleave', (e) => {
const nextEl = e?.relatedTarget || null;
if (isNodeInside(zoneEl, nextEl)) {
return;
}
if (activeHoverTargetEl === zoneEl) hideBreakdownPopover();
});
}
}
function createSourceBreakdownRow() {
const nameTextEl = h('span', { className: 'cons-row-title-text' });
const nameEl = h('strong', { className: 'cons-row-title' }, [nameTextEl]);
@@ -30575,26 +30665,7 @@ const ConsumptionView = defineComponent({
const costEl = h('strong', { className: 'cons-row-cost text-mono' });
const trackEl = h('div', { className: 'progress-track cons-seg-bar cons-source-model-bar' });
const rowState = { hoverPayload: null };
const bindPopoverHover = (targetEl) => ({
onMouseEnter: (e) => {
if (rowState.hoverPayload) {
showBreakdownPopover(
targetEl,
rowState.hoverPayload,
e?.clientX ?? null,
e?.clientY ?? null
);
}
},
onMouseMove: (e) => {
if (rowState.hoverPayload && activeHoverTargetEl === targetEl) {
positionBreakdownPopover(targetEl, e?.clientX ?? null, e?.clientY ?? null);
}
},
onMouseLeave: () => {
if (activeHoverTargetEl === targetEl) hideBreakdownPopover();
},
});
const barHitEl = h(
'div',
{
@@ -30602,20 +30673,23 @@ const ConsumptionView = defineComponent({
},
[trackEl]
);
const barHandlers = bindPopoverHover(barHitEl);
barHitEl.addEventListener('mouseenter', barHandlers.onMouseEnter);
barHitEl.addEventListener('mousemove', barHandlers.onMouseMove);
barHitEl.addEventListener('mouseleave', barHandlers.onMouseLeave);
const topModelsEl = h('div', { className: 'cons-source-top-models', hidden: true });
const topHandlers = bindPopoverHover(topModelsEl);
topModelsEl.addEventListener('mouseenter', topHandlers.onMouseEnter);
topModelsEl.addEventListener('mousemove', topHandlers.onMouseMove);
topModelsEl.addEventListener('mouseleave', topHandlers.onMouseLeave);
const callsLbl = h('span', { text: t('cons.footCalls') });
const callsVal = h('strong', { className: 'text-mono' });
const hoverZoneEl = h('div', { className: 'cons-source-hover-zone' }, [
barHitEl,
h('div', { className: 'cons-item-foot cons-source-foot' }, [
topModelsEl,
h('span', { className: 'legend-left cons-calls-stat' }, [
callsLbl,
callsVal,
]),
]),
]);
attachUnifiedHoverZone(hoverZoneEl, [barHitEl, topModelsEl], rowState);
const rowEl = h('div', { className: 'cons-item-row cons-source-row' }, [
h('div', { className: 'panel-header' }, [
nameEl,
@@ -30625,14 +30699,7 @@ const ConsumptionView = defineComponent({
costEl,
]),
]),
barHitEl,
h('div', { className: 'cons-item-foot cons-source-foot' }, [
topModelsEl,
h('span', { className: 'legend-left cons-calls-stat' }, [
callsLbl,
callsVal,
]),
]),
hoverZoneEl,
]);
return {
@@ -30643,6 +30710,7 @@ const ConsumptionView = defineComponent({
pctBadge,
totalTokEl,
costEl,
hoverZoneEl,
barHitEl,
trackEl,
topModelsEl,
@@ -30746,6 +30814,7 @@ const ConsumptionView = defineComponent({
segments: partitioned,
}
: null;
patchClasses(refs.hoverZoneEl, { 'is-interactive': Boolean(refs.rowState.hoverPayload) });
}
function createTopConversationRow() {
@@ -30761,43 +30830,26 @@ const ConsumptionView = defineComponent({
const trackEl = h('div', { className: 'progress-track cons-seg-bar cons-source-model-bar' });
const rowState = { cascadeId: '', canJump: false, hoverPayload: null };
const bindPopoverHover = (targetEl) => ({
onMouseEnter: (e) => {
if (rowState.hoverPayload) {
showBreakdownPopover(
targetEl,
rowState.hoverPayload,
e?.clientX ?? null,
e?.clientY ?? null
);
}
},
onMouseMove: (e) => {
if (rowState.hoverPayload && activeHoverTargetEl === targetEl) {
positionBreakdownPopover(targetEl, e?.clientX ?? null, e?.clientY ?? null);
}
},
onMouseLeave: () => {
if (activeHoverTargetEl === targetEl) hideBreakdownPopover();
},
});
const barHitEl = h('div', { className: 'cons-source-bar-hit' }, [trackEl]);
const barHandlers = bindPopoverHover(barHitEl);
barHitEl.addEventListener('mouseenter', barHandlers.onMouseEnter);
barHitEl.addEventListener('mousemove', barHandlers.onMouseMove);
barHitEl.addEventListener('mouseleave', barHandlers.onMouseLeave);
const topModelsEl = h('div', { className: 'cons-source-top-models', hidden: true });
const topHandlers = bindPopoverHover(topModelsEl);
topModelsEl.addEventListener('mouseenter', topHandlers.onMouseEnter);
topModelsEl.addEventListener('mousemove', topHandlers.onMouseMove);
topModelsEl.addEventListener('mouseleave', topHandlers.onMouseLeave);
const fallbackMetaEl = h('span', { className: 'cons-top-conv-meta', hidden: true });
const callsLbl = h('span', { text: t('cons.footCalls') });
const callsVal = h('strong', { className: 'text-mono' });
const hoverZoneEl = h('div', { className: 'cons-source-hover-zone' }, [
barHitEl,
h('div', { className: 'cons-item-foot cons-source-foot' }, [
topModelsEl,
fallbackMetaEl,
h('span', { className: 'legend-left cons-calls-stat' }, [
callsLbl,
callsVal,
]),
]),
]);
attachUnifiedHoverZone(hoverZoneEl, [barHitEl, topModelsEl], rowState);
const rowEl = h(
'div',
{
@@ -30825,15 +30877,7 @@ const ConsumptionView = defineComponent({
costEl,
]),
]),
barHitEl,
h('div', { className: 'cons-item-foot cons-source-foot' }, [
topModelsEl,
fallbackMetaEl,
h('span', { className: 'legend-left cons-calls-stat' }, [
callsLbl,
callsVal,
]),
]),
hoverZoneEl,
]
);
@@ -30847,6 +30891,7 @@ const ConsumptionView = defineComponent({
pctBadge,
totalTokEl,
costEl,
hoverZoneEl,
barHitEl,
trackEl,
topModelsEl,
@@ -31004,6 +31049,7 @@ const ConsumptionView = defineComponent({
segments: partitioned,
}
: null;
patchClasses(refs.hoverZoneEl, { 'is-interactive': Boolean(refs.rowState.hoverPayload) });
}
let latestSlice = null;
+2 -2
View File
@@ -4,11 +4,11 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>用量监控</title>
<link rel="stylesheet" href="/styles.css?v=1795453915976">
<link rel="stylesheet" href="/styles.css?v=1795456766440">
<script src="/preload.js"></script>
</head>
<body>
<div id="app-root"></div>
<script src="/app.js?v=1795453915976"></script>
<script src="/app.js?v=1795456766440"></script>
</body>
</html>
+2
View File
@@ -479,6 +479,8 @@ html[data-standalone="true"][data-modern-ui="true"] .app-shell {
border-top-color: color-mix(in srgb, var(--text-primary) 8%, transparent);
}
[data-modern-ui="true"] .cons-source-hover-zone.is-interactive:hover .cons-source-model-bar,
[data-modern-ui="true"] .cons-source-hover-zone.is-hovered .cons-source-model-bar,
[data-modern-ui="true"] .cons-source-bar-hit:hover .cons-source-model-bar,
[data-modern-ui="true"] .cons-source-bar-hit.is-hovered .cons-source-model-bar,
[data-modern-ui="true"] .month-col.is-interactive:hover .month-stack,
@@ -891,12 +891,27 @@
container-type: inline-size;
}
.cons-source-bar-hit {
padding: 5px 0;
margin: -5px 0;
.cons-source-hover-zone {
display: flex;
flex-direction: column;
gap: 5px;
padding: 4px 0 2px;
margin: -4px 0 -2px;
min-width: 0;
}
.cons-source-hover-zone.is-interactive {
cursor: pointer;
}
.cons-source-bar-hit {
padding: 0;
margin: 0;
cursor: inherit;
}
.cons-source-hover-zone.is-interactive:hover .cons-source-model-bar,
.cons-source-hover-zone.is-hovered .cons-source-model-bar,
.cons-source-bar-hit:hover .cons-source-model-bar,
.cons-source-bar-hit.is-hovered .cons-source-model-bar {
box-shadow: 0 0 0 1px var(--border-strong);
@@ -959,6 +974,8 @@
transition: color 120ms ease;
}
.cons-source-hover-zone.is-interactive:hover .cons-source-top-name,
.cons-source-hover-zone.is-hovered .cons-source-top-name,
.cons-source-top-models:hover .cons-source-top-name,
.cons-source-top-models.is-hovered .cons-source-top-name {
color: var(--text-primary);
@@ -1236,17 +1253,20 @@
/* --- 6. 12 个月垂直堆叠柱状图 (12-Month Stacked Bar Chart) --- */
.monthly-grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 3px;
align-items: end;
padding-top: var(--space-2);
grid-template-columns: repeat(12, minmax(0, 1fr));
gap: 0;
align-items: stretch;
margin: var(--space-2) -1.5px 0;
}
.month-col {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
gap: 3px;
padding: 0 1.5px;
box-sizing: border-box;
min-width: 0;
}
+131 -85
View File
@@ -538,6 +538,7 @@ export const ConsumptionView = defineComponent({
});
let activeHoverTargetEl = null;
let activeHoverPayload = null;
let cachedBreakdownRootRect = null;
let cachedBreakdownAnchorRect = null;
@@ -554,6 +555,7 @@ export const ConsumptionView = defineComponent({
function hideBreakdownPopover() {
cachedBreakdownRootRect = null;
cachedBreakdownAnchorRect = null;
activeHoverPayload = null;
if (activeHoverTargetEl) {
patchClasses(activeHoverTargetEl, { 'is-hovered': false });
activeHoverTargetEl = null;
@@ -629,6 +631,9 @@ export const ConsumptionView = defineComponent({
hideBreakdownPopover();
return;
}
const wasHidden = breakdownPopoverEl.hasAttribute('hidden');
const sameTargetAndPayload =
!wasHidden && activeHoverTargetEl === anchorEl && activeHoverPayload === payload;
if (activeHoverTargetEl && activeHoverTargetEl !== anchorEl) {
patchClasses(activeHoverTargetEl, { 'is-hovered': false });
cachedBreakdownAnchorRect = null;
@@ -637,8 +642,10 @@ export const ConsumptionView = defineComponent({
cachedBreakdownAnchorRect = null;
}
activeHoverTargetEl = anchorEl;
activeHoverPayload = payload;
patchClasses(anchorEl, { 'is-hovered': true });
if (!sameTargetAndPayload) {
popoverContent.update({
title: payload.title || '—',
calls: payload.calls || 0,
@@ -651,8 +658,8 @@ export const ConsumptionView = defineComponent({
outputTokens: payload.outputTokens,
segments: Array.isArray(payload.segments) ? payload.segments : [],
});
}
const wasHidden = breakdownPopoverEl.hasAttribute('hidden');
patchAttr(breakdownPopoverEl, 'hidden', false);
positionBreakdownPopover(anchorEl, pointerClientX, pointerClientY);
if (wasHidden) {
@@ -675,6 +682,19 @@ export const ConsumptionView = defineComponent({
return { el: segEl, refs: { segEl } };
}
let monthlyGridEl = null;
const monthlyColByEl = new Map();
function findMonthlyColForNode(node) {
let cur = node;
while (cur && cur !== monthlyGridEl) {
const hit = monthlyColByEl.get(cur);
if (hit) return hit;
cur = cur.parentNode || null;
}
return null;
}
const monthlyCols = Array.from({ length: 12 }, (_, idx) => {
const costText = h('span', { className: 'month-cost text-mono', text: '' });
const stackWrap = h('div', { className: 'month-stack' });
@@ -701,6 +721,9 @@ export const ConsumptionView = defineComponent({
e?.clientY ?? null
);
} else {
if (activeHoverTargetEl && monthlyColByEl.has(activeHoverTargetEl)) {
hideBreakdownPopover();
}
e?.stopPropagation?.();
}
},
@@ -709,8 +732,16 @@ export const ConsumptionView = defineComponent({
positionBreakdownPopover(colEl, e?.clientX ?? null, e?.clientY ?? null);
}
},
onMouseLeave: () => {
if (activeHoverTargetEl === colEl) hideBreakdownPopover();
onMouseLeave: (e) => {
if (activeHoverTargetEl !== colEl) return;
const nextEl = e?.relatedTarget || null;
if (nextEl) {
const nextCol = findMonthlyColForNode(nextEl);
if ((nextCol && nextCol.colState.hoverPayload) || nextEl === monthlyGridEl) {
return;
}
}
hideBreakdownPopover();
},
},
[
@@ -720,7 +751,7 @@ export const ConsumptionView = defineComponent({
tokText,
]
);
return {
const colRec = {
el: colEl,
costText,
stackWrap,
@@ -729,8 +760,23 @@ export const ConsumptionView = defineComponent({
tokText,
colState,
};
monthlyColByEl.set(colEl, colRec);
return colRec;
});
monthlyGridEl = h(
'div',
{
className: 'monthly-grid',
onMouseLeave: () => {
if (activeHoverTargetEl && monthlyColByEl.has(activeHoverTargetEl)) {
hideBreakdownPopover();
}
},
},
monthlyCols.map((c) => c.el)
);
const monthlyPanel = h('section', { className: 'panel' }, [
h('div', { className: 'panel-header' }, [
h('span', { className: 'panel-title' }, [
@@ -739,11 +785,7 @@ export const ConsumptionView = defineComponent({
]),
monthlyHoverHint,
]),
h(
'div',
{ className: 'monthly-grid' },
monthlyCols.map((c) => c.el)
),
monthlyGridEl,
]);
const scrollInner = h(
@@ -1232,6 +1274,54 @@ export const ConsumptionView = defineComponent({
/**
* 创建客户端来源单行 DOM 结构(保留长尾合并分段配色进度条、单行不换行的 Top 2-3 模型速览和右侧总调用数,悬停进度条或速览区弹出完整明细浮层)。
*/
function isNodeInside(root, node) {
if (!root || !node) return false;
if (typeof root.contains === 'function') return root.contains(node);
let cur = node;
while (cur) {
if (cur === root) return true;
cur = cur.parentNode || null;
}
return false;
}
function attachUnifiedHoverZone(zoneEl, compatTargets, rowState) {
zoneEl.addEventListener('mouseenter', (e) => {
if (rowState.hoverPayload) {
showBreakdownPopover(zoneEl, rowState.hoverPayload, e?.clientX ?? null, e?.clientY ?? null);
}
});
zoneEl.addEventListener('mousemove', (e) => {
if (rowState.hoverPayload && activeHoverTargetEl === zoneEl) {
positionBreakdownPopover(zoneEl, e?.clientX ?? null, e?.clientY ?? null);
}
});
zoneEl.addEventListener('mouseleave', () => {
if (activeHoverTargetEl === zoneEl) hideBreakdownPopover();
});
for (const childEl of compatTargets) {
if (!childEl) continue;
childEl.addEventListener('mouseenter', (e) => {
if (rowState.hoverPayload) {
showBreakdownPopover(zoneEl, rowState.hoverPayload, e?.clientX ?? null, e?.clientY ?? null);
}
});
childEl.addEventListener('mousemove', (e) => {
if (rowState.hoverPayload && activeHoverTargetEl === zoneEl) {
positionBreakdownPopover(zoneEl, e?.clientX ?? null, e?.clientY ?? null);
}
});
childEl.addEventListener('mouseleave', (e) => {
const nextEl = e?.relatedTarget || null;
if (isNodeInside(zoneEl, nextEl)) {
return;
}
if (activeHoverTargetEl === zoneEl) hideBreakdownPopover();
});
}
}
function createSourceBreakdownRow() {
const nameTextEl = h('span', { className: 'cons-row-title-text' });
const nameEl = h('strong', { className: 'cons-row-title' }, [nameTextEl]);
@@ -1240,26 +1330,7 @@ export const ConsumptionView = defineComponent({
const costEl = h('strong', { className: 'cons-row-cost text-mono' });
const trackEl = h('div', { className: 'progress-track cons-seg-bar cons-source-model-bar' });
const rowState = { hoverPayload: null };
const bindPopoverHover = (targetEl) => ({
onMouseEnter: (e) => {
if (rowState.hoverPayload) {
showBreakdownPopover(
targetEl,
rowState.hoverPayload,
e?.clientX ?? null,
e?.clientY ?? null
);
}
},
onMouseMove: (e) => {
if (rowState.hoverPayload && activeHoverTargetEl === targetEl) {
positionBreakdownPopover(targetEl, e?.clientX ?? null, e?.clientY ?? null);
}
},
onMouseLeave: () => {
if (activeHoverTargetEl === targetEl) hideBreakdownPopover();
},
});
const barHitEl = h(
'div',
{
@@ -1267,20 +1338,23 @@ export const ConsumptionView = defineComponent({
},
[trackEl]
);
const barHandlers = bindPopoverHover(barHitEl);
barHitEl.addEventListener('mouseenter', barHandlers.onMouseEnter);
barHitEl.addEventListener('mousemove', barHandlers.onMouseMove);
barHitEl.addEventListener('mouseleave', barHandlers.onMouseLeave);
const topModelsEl = h('div', { className: 'cons-source-top-models', hidden: true });
const topHandlers = bindPopoverHover(topModelsEl);
topModelsEl.addEventListener('mouseenter', topHandlers.onMouseEnter);
topModelsEl.addEventListener('mousemove', topHandlers.onMouseMove);
topModelsEl.addEventListener('mouseleave', topHandlers.onMouseLeave);
const callsLbl = h('span', { text: t('cons.footCalls') });
const callsVal = h('strong', { className: 'text-mono' });
const hoverZoneEl = h('div', { className: 'cons-source-hover-zone' }, [
barHitEl,
h('div', { className: 'cons-item-foot cons-source-foot' }, [
topModelsEl,
h('span', { className: 'legend-left cons-calls-stat' }, [
callsLbl,
callsVal,
]),
]),
]);
attachUnifiedHoverZone(hoverZoneEl, [barHitEl, topModelsEl], rowState);
const rowEl = h('div', { className: 'cons-item-row cons-source-row' }, [
h('div', { className: 'panel-header' }, [
nameEl,
@@ -1290,14 +1364,7 @@ export const ConsumptionView = defineComponent({
costEl,
]),
]),
barHitEl,
h('div', { className: 'cons-item-foot cons-source-foot' }, [
topModelsEl,
h('span', { className: 'legend-left cons-calls-stat' }, [
callsLbl,
callsVal,
]),
]),
hoverZoneEl,
]);
return {
@@ -1308,6 +1375,7 @@ export const ConsumptionView = defineComponent({
pctBadge,
totalTokEl,
costEl,
hoverZoneEl,
barHitEl,
trackEl,
topModelsEl,
@@ -1411,6 +1479,7 @@ export const ConsumptionView = defineComponent({
segments: partitioned,
}
: null;
patchClasses(refs.hoverZoneEl, { 'is-interactive': Boolean(refs.rowState.hoverPayload) });
}
function createTopConversationRow() {
@@ -1426,43 +1495,26 @@ export const ConsumptionView = defineComponent({
const trackEl = h('div', { className: 'progress-track cons-seg-bar cons-source-model-bar' });
const rowState = { cascadeId: '', canJump: false, hoverPayload: null };
const bindPopoverHover = (targetEl) => ({
onMouseEnter: (e) => {
if (rowState.hoverPayload) {
showBreakdownPopover(
targetEl,
rowState.hoverPayload,
e?.clientX ?? null,
e?.clientY ?? null
);
}
},
onMouseMove: (e) => {
if (rowState.hoverPayload && activeHoverTargetEl === targetEl) {
positionBreakdownPopover(targetEl, e?.clientX ?? null, e?.clientY ?? null);
}
},
onMouseLeave: () => {
if (activeHoverTargetEl === targetEl) hideBreakdownPopover();
},
});
const barHitEl = h('div', { className: 'cons-source-bar-hit' }, [trackEl]);
const barHandlers = bindPopoverHover(barHitEl);
barHitEl.addEventListener('mouseenter', barHandlers.onMouseEnter);
barHitEl.addEventListener('mousemove', barHandlers.onMouseMove);
barHitEl.addEventListener('mouseleave', barHandlers.onMouseLeave);
const topModelsEl = h('div', { className: 'cons-source-top-models', hidden: true });
const topHandlers = bindPopoverHover(topModelsEl);
topModelsEl.addEventListener('mouseenter', topHandlers.onMouseEnter);
topModelsEl.addEventListener('mousemove', topHandlers.onMouseMove);
topModelsEl.addEventListener('mouseleave', topHandlers.onMouseLeave);
const fallbackMetaEl = h('span', { className: 'cons-top-conv-meta', hidden: true });
const callsLbl = h('span', { text: t('cons.footCalls') });
const callsVal = h('strong', { className: 'text-mono' });
const hoverZoneEl = h('div', { className: 'cons-source-hover-zone' }, [
barHitEl,
h('div', { className: 'cons-item-foot cons-source-foot' }, [
topModelsEl,
fallbackMetaEl,
h('span', { className: 'legend-left cons-calls-stat' }, [
callsLbl,
callsVal,
]),
]),
]);
attachUnifiedHoverZone(hoverZoneEl, [barHitEl, topModelsEl], rowState);
const rowEl = h(
'div',
{
@@ -1490,15 +1542,7 @@ export const ConsumptionView = defineComponent({
costEl,
]),
]),
barHitEl,
h('div', { className: 'cons-item-foot cons-source-foot' }, [
topModelsEl,
fallbackMetaEl,
h('span', { className: 'legend-left cons-calls-stat' }, [
callsLbl,
callsVal,
]),
]),
hoverZoneEl,
]
);
@@ -1512,6 +1556,7 @@ export const ConsumptionView = defineComponent({
pctBadge,
totalTokEl,
costEl,
hoverZoneEl,
barHitEl,
trackEl,
topModelsEl,
@@ -1669,6 +1714,7 @@ export const ConsumptionView = defineComponent({
segments: partitioned,
}
: null;
patchClasses(refs.hoverZoneEl, { 'is-interactive': Boolean(refs.rowState.hoverPayload) });
}
let latestSlice = null;
+29 -7
View File
@@ -3696,12 +3696,27 @@ html[data-standalone="true"] .app-shell {
container-type: inline-size;
}
.cons-source-bar-hit {
padding: 5px 0;
margin: -5px 0;
.cons-source-hover-zone {
display: flex;
flex-direction: column;
gap: 5px;
padding: 4px 0 2px;
margin: -4px 0 -2px;
min-width: 0;
}
.cons-source-hover-zone.is-interactive {
cursor: pointer;
}
.cons-source-bar-hit {
padding: 0;
margin: 0;
cursor: inherit;
}
.cons-source-hover-zone.is-interactive:hover .cons-source-model-bar,
.cons-source-hover-zone.is-hovered .cons-source-model-bar,
.cons-source-bar-hit:hover .cons-source-model-bar,
.cons-source-bar-hit.is-hovered .cons-source-model-bar {
box-shadow: 0 0 0 1px var(--border-strong);
@@ -3764,6 +3779,8 @@ html[data-standalone="true"] .app-shell {
transition: color 120ms ease;
}
.cons-source-hover-zone.is-interactive:hover .cons-source-top-name,
.cons-source-hover-zone.is-hovered .cons-source-top-name,
.cons-source-top-models:hover .cons-source-top-name,
.cons-source-top-models.is-hovered .cons-source-top-name {
color: var(--text-primary);
@@ -4041,17 +4058,20 @@ html[data-standalone="true"] .app-shell {
/* --- 6. 12 个月垂直堆叠柱状图 (12-Month Stacked Bar Chart) --- */
.monthly-grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 3px;
align-items: end;
padding-top: var(--space-2);
grid-template-columns: repeat(12, minmax(0, 1fr));
gap: 0;
align-items: stretch;
margin: var(--space-2) -1.5px 0;
}
.month-col {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
gap: 3px;
padding: 0 1.5px;
box-sizing: border-box;
min-width: 0;
}
@@ -8303,6 +8323,8 @@ html[data-standalone="true"][data-modern-ui="true"] .app-shell {
border-top-color: color-mix(in srgb, var(--text-primary) 8%, transparent);
}
[data-modern-ui="true"] .cons-source-hover-zone.is-interactive:hover .cons-source-model-bar,
[data-modern-ui="true"] .cons-source-hover-zone.is-hovered .cons-source-model-bar,
[data-modern-ui="true"] .cons-source-bar-hit:hover .cons-source-model-bar,
[data-modern-ui="true"] .cons-source-bar-hit.is-hovered .cons-source-model-bar,
[data-modern-ui="true"] .month-col.is-interactive:hover .month-stack,
+27 -3
View File
@@ -486,25 +486,39 @@ test('ConsumptionView: Top Models color dot + % bar, clutter-free Client Sources
['输入', '缓存', '思考', '输出']
);
const appHoverZone = sourceRows[0].querySelector('.cons-source-hover-zone');
const appTopModelsEl = sourceRows[0].querySelector('.cons-source-top-models');
assert.ok(appHoverZone, 'Client source row should wrap bar and top models in a unified hover zone');
// Moving seamlessly from progress bar into gap / top-models keeps popover visible without flicker
appBarHit.dispatchEvent({ type: 'mouseleave', relatedTarget: appHoverZone });
assert.equal(popover.hasAttribute('hidden'), false, 'Moving into unified hover zone gap must not hide popover');
appBarHit.dispatchEvent({ type: 'mouseleave', relatedTarget: appTopModelsEl });
assert.equal(popover.hasAttribute('hidden'), false, 'Moving from bar to model names must not hide popover');
appBarHit.dispatchEvent({ type: 'mouseleave' });
assert.equal(popover.hasAttribute('hidden'), true);
const appTopModelsEl = sourceRows[0].querySelector('.cons-source-top-models');
appTopModelsEl.dispatchEvent({ type: 'mouseenter', clientX: 90 });
assert.equal(popover.hasAttribute('hidden'), false);
assert.equal(popover.querySelector('.trend-tip-time')?.textContent, 'Antigravity App');
appTopModelsEl.dispatchEvent({ type: 'mouseleave' });
appTopModelsEl.dispatchEvent({ type: 'mouseleave', relatedTarget: appBarHit });
assert.equal(popover.hasAttribute('hidden'), false, 'Moving back from model names to bar must not hide popover');
appHoverZone.dispatchEvent({ type: 'mouseleave' });
assert.equal(popover.hasAttribute('hidden'), true);
// Verify single-line non-wrapping CSS rules exist for client source top models
// Verify single-line non-wrapping CSS rules and zero-gap hover layout rules
const { readFileSync } = await import('node:fs');
const consCss = readFileSync(new URL('../src/styles/views-consumption.css', import.meta.url), 'utf8');
assert.match(consCss, /\.cons-source-hover-zone\s*\{[\s\S]*flex-direction:\s*column/);
assert.match(consCss, /\.cons-source-foot\s*\{[\s\S]*flex-wrap:\s*nowrap/);
assert.match(consCss, /\.cons-source-top-models\s*\{[\s\S]*flex-wrap:\s*nowrap/);
assert.match(consCss, /@container\s*\(max-width:\s*340px\)\s*\{\s*\.cons-source-top-item:nth-child\(n\s*\+\s*3\)/);
assert.match(consCss, /\.monthly-grid\s*\{[\s\S]*gap:\s*0/);
// 3. Monthly Breakdown: old 4-channel legend removed; Nov column renders model-colored vertical segments & unified hover popover
assert.equal(view.el.querySelectorAll('.monthly-legend').length, 0);
const monthlyGrid = view.el.querySelector('.monthly-grid');
const monthCols = view.el.querySelectorAll('.month-col');
const novCol = monthCols[10];
const novSegs = novCol.querySelectorAll('.month-seg.cons-model-seg');
@@ -520,6 +534,16 @@ test('ConsumptionView: Top Models color dot + % bar, clutter-free Client Sources
assert.equal(popover.querySelectorAll('.cons-pop-model-row').length, 4);
assert.equal(popover.querySelector('.cons-pop-channels')?.hasAttribute('hidden'), false);
// Seam/sibling handoff inside monthly-grid keeps popover open; empty month or exiting grid hides it
novCol.dispatchEvent({ type: 'mouseleave', relatedTarget: monthlyGrid });
assert.equal(popover.hasAttribute('hidden'), false, 'Sub-pixel seam inside monthly-grid must not flicker popover');
monthCols[0].dispatchEvent({ type: 'mouseenter' });
assert.equal(popover.hasAttribute('hidden'), true, 'Hovering zero-data month must hide popover');
novCol.dispatchEvent({ type: 'mouseenter' });
assert.equal(popover.hasAttribute('hidden'), false);
monthlyGrid.dispatchEvent({ type: 'mouseleave' });
assert.equal(popover.hasAttribute('hidden'), true, 'Leaving monthly-grid must hide popover');
// 4. Usage Trend: taller 184px viewBox & hovering x-axis tick opens redesigned tooltip (hero TOKEN, 4-seg model bars, no subtitle/dot clutter, bottom 4 channels)
const trendSvg = view.el.querySelector('.trend-svg');
assert.match(trendSvg?.getAttribute('viewBox') || '', /\s184$/);