Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): keep the usage bars tooltip inside short viewports
Dash4972bc6ceb8a
diff --git a/apps/desktop/src/renderer/components/settings/usage/UsageBarsTooltip.tsx b/apps/desktop/src/renderer/components/settings/usage/UsageBarsTooltip.tsxindex ed420abbde..2b3a10a71d 100644--- a/apps/desktop/src/renderer/components/settings/usage/UsageBarsTooltip.tsx+++ b/apps/desktop/src/renderer/components/settings/usage/UsageBarsTooltip.tsx@@ -101,8 +101,17 @@ export function UsageBarsTooltip({Math.max(centerX - width / 2, VIEWPORT_MARGIN_PX),viewportWidth - width - VIEWPORT_MARGIN_PX,);+ // 优先放在绘图区上方,放不下翻到下方;两边都放不下(如 3× 缩放的矮窗口)就夹在视口内,+ // 超出视口高度的部分由 max-height 截掉,头部的日期与总量始终可见。+ const bottomLimit = document.documentElement.clientHeight - VIEWPORT_MARGIN_PX;const above = plot.top - GAP_PX - height;- const top = above >= VIEWPORT_MARGIN_PX ? above : plot.bottom + GAP_PX;+ const below = plot.bottom + GAP_PX;+ const top =+ above >= VIEWPORT_MARGIN_PX+ ? above+ : below + height <= bottomLimit+ ? below+ : Math.max(VIEWPORT_MARGIN_PX, bottomLimit - height);setPosition((prev) =>prev && prev.left === left && prev.top === top ? prev : { left, top, glide: prev !== null },);@@ -125,7 +134,7 @@ export function UsageBarsTooltip({aria-hidden="true"data-testid="usage-bars-tooltip"data-glide={position?.glide ? 'true' : undefined}- className="usage-bars-tooltip animate-fade-in pointer-events-none fixed left-0 top-0 z-[10011] w-max min-w-[220px] max-w-[320px] select-none rounded-xl bg-[var(--tooltip-bg)] px-3 py-2.5 text-[var(--tooltip-text)]"+ className="usage-bars-tooltip animate-fade-in pointer-events-none fixed left-0 top-0 z-[10011] w-max min-w-[220px] max-w-[320px] max-h-[calc(100vh-16px)] overflow-hidden select-none rounded-xl bg-[var(--tooltip-bg)] px-3 py-2.5 text-[var(--tooltip-text)]"style={{transform: position ? `translate3d(${position.left}px, ${position.top}px, 0)` : undefined,visibility: position ? 'visible' : 'hidden',diff --git a/apps/desktop/src/renderer/components/settings/usage/__tests__/usageBarsTooltip.test.tsx b/apps/desktop/src/renderer/components/settings/usage/__tests__/usageBarsTooltip.test.tsxindex 480455dc8f..aaadcac29b 100644--- a/apps/desktop/src/renderer/components/settings/usage/__tests__/usageBarsTooltip.test.tsx+++ b/apps/desktop/src/renderer/components/settings/usage/__tests__/usageBarsTooltip.test.tsx@@ -66,6 +66,10 @@ beforeEach(() => {configurable: true,value: 1000,});+ Object.defineProperty(document.documentElement, 'clientHeight', {+ configurable: true,+ value: 800,+ });});afterEach(() => {cleanup();@@ -157,6 +161,26 @@ describe('usage bars tooltip', () => {expect(tooltipTransform()).toBe('translate3d(752px, 204px, 0)');});+ it('stays inside a short viewport when neither side of the plot has room (3× zoom)', () => {+ Object.defineProperty(document.documentElement, 'clientHeight', {+ configurable: true,+ value: 200,+ });+ rects.set('plot', { left: 100, top: 60, width: 800, height: 96 });+ const view = renderBars();+ rects.set('2026-09-26', { left: 500, top: 130, width: 10, height: 26 });++ fireEvent.pointerOver(bar(view));+ // above: 60 - 8 - 150 < 8; below: 164 + 150 > 192 → clamp to 192 - 150+ expect(tooltipTransform()).toBe('translate3d(385px, 42px, 0)');++ rects.set('tooltip', { width: 240, height: 300 });+ fireEvent.scroll(window);+ // taller than the viewport: pinned to the top margin, max-height clips the rest+ expect(tooltipTransform()).toBe('translate3d(385px, 8px, 0)');+ expect(screen.getByTestId('usage-bars-tooltip').className).toContain('max-h-');+ });+it('caps the share bar at six model segments plus one merged remainder', () => {const models = Array.from({ length: 10 }, (_, i) => row(`m${i}`, (i + 1) * 10));const view = render(diff --git a/docs/design-rules/usage-history-charts.md b/docs/design-rules/usage-history-charts.mdindex 69baf76fcd..1845558313 100644--- a/docs/design-rules/usage-history-charts.md+++ b/docs/design-rules/usage-history-charts.md@@ -25,7 +25,7 @@| 头部 | 日期(含星期,11px,60% 不透明度);当日总量 16px / 500 等宽数字,单位 11px 弱化 || 占比条 | 4px 高、2px 圆角的横向分段,颜色与柱段相同,按 token 降序,段间 1px 间隔;与明细同口径只画前 6 个模型,其余合成一段 40% 不透明度的中性段,不会因模型多而被裁掉 || 明细 | 8×8px、2px 圆角色块 · 模型名(截断)· token(500,等宽右对齐)· 占比(50% 不透明度);按 token 降序,最多 6 行,其余折叠为「另有 N 个模型」 |-| 位置与动效 | portal + fixed,优先置于绘图区上方,空间不足翻到下方,水平以柱子为中心并夹在视口内;入场 `animate-fade-in`,在柱子之间以 `--motion-fast` 平滑跟随,首次定位与减少动态效果时不过渡 |+| 位置与动效 | portal + fixed,优先置于绘图区上方,空间不足翻到下方,上下都放不下(如 3× 缩放的矮窗口)时夹在视口内、超出视口高度的部分截掉(头部日期与总量始终可见),水平以柱子为中心并夹在视口内;入场 `animate-fade-in`,在柱子之间以 `--motion-fast` 平滑跟随,首次定位与减少动态效果时不过渡 |浮层 `aria-hidden`:柱子按钮的 `aria-label` 给出日期与总量,逐模型明细经 `aria-describedby` 指向同组件内的 `sr-only` 文本,承接原生 title 的信息。色块与占比条沿用 `usage-token-bar` 的 2px 数据图元角,不是新的形状登记。