Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): keep the usage bars tooltip inside narrow viewports

Dash9890f75b4aa4
diff --git a/apps/desktop/src/renderer/components/settings/usage/UsageBarsTooltip.tsx b/apps/desktop/src/renderer/components/settings/usage/UsageBarsTooltip.tsx
index 2b3a10a71d..4ca8337a78 100644
--- a/apps/desktop/src/renderer/components/settings/usage/UsageBarsTooltip.tsx
+++ b/apps/desktop/src/renderer/components/settings/usage/UsageBarsTooltip.tsx
@@ -97,9 +97,11 @@ export function UsageBarsTooltip({
const { width, height } = el.getBoundingClientRect();
const viewportWidth = document.documentElement.clientWidth;
const centerX = anchor.left + anchor.width / 2;
- const left = Math.min(
- Math.max(centerX - width / 2, VIEWPORT_MARGIN_PX),
- viewportWidth - width - VIEWPORT_MARGIN_PX,
+ // 两个方向同一不变量:浮层整体留在视口内。宽度已由 CSS 限制在视口宽度内,
+ // 左侧边距优先(视口比浮层还窄时贴左边距,不被挤出左缘)。
+ const left = Math.max(
+ VIEWPORT_MARGIN_PX,
+ Math.min(centerX - width / 2, viewportWidth - width - VIEWPORT_MARGIN_PX),
);
// 优先放在绘图区上方,放不下翻到下方;两边都放不下(如 3× 缩放的矮窗口)就夹在视口内,
// 超出视口高度的部分由 max-height 截掉,头部的日期与总量始终可见。
@@ -134,7 +136,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] max-h-[calc(100vh-16px)] overflow-hidden 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-[min(220px,calc(100vw-16px))] max-w-[min(320px,calc(100vw-16px))] 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.tsx
index aaadcac29b..b597992611 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
@@ -181,6 +181,24 @@ describe('usage bars tooltip', () => {
expect(screen.getByTestId('usage-bars-tooltip').className).toContain('max-h-');
});
+ it('stays inside a narrow viewport instead of spilling past the left edge (3× zoom)', () => {
+ Object.defineProperty(document.documentElement, 'clientWidth', {
+ configurable: true,
+ value: 267,
+ });
+ rects.set('plot', { left: 10, top: 400, width: 250, height: 96 });
+ rects.set('tooltip', { width: 320, height: 150 });
+ const view = renderBars();
+ rects.set('2026-09-26', { left: 200, top: 470, width: 6, height: 26 });
+
+ fireEvent.pointerOver(bar(view));
+ // 267 - 320 - 8 < 8 → left margin wins; width itself is capped by CSS to the viewport
+ expect(tooltipTransform()).toBe('translate3d(8px, 242px, 0)');
+ expect(screen.getByTestId('usage-bars-tooltip').className).toContain(
+ 'max-w-[min(320px,calc(100vw-16px))]',
+ );
+ });
+
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.md
index 1845558313..8d97ed983e 100644
--- a/docs/design-rules/usage-history-charts.md
+++ b/docs/design-rules/usage-history-charts.md
@@ -21,7 +21,7 @@
| 层 | 规格 |
| --- | --- |
-| 容器 | `--tooltip-bg` / `--tooltip-text`(两模式同为深底白字,沿用共享 Tooltip),12px 圆角、`--shadow-menu` 投影加 10% `--tooltip-text` 发丝内描边(Dark 下与卡片底色区分),内边距 12×10px,宽 220–320px |
+| 容器 | `--tooltip-bg` / `--tooltip-text`(两模式同为深底白字,沿用共享 Tooltip),12px 圆角、`--shadow-menu` 投影加 10% `--tooltip-text` 发丝内描边(Dark 下与卡片底色区分),内边距 12×10px,宽 220–320px(不超过视口宽度减去两侧 8px 边距) |
| 头部 | 日期(含星期,11px,60% 不透明度);当日总量 16px / 500 等宽数字,单位 11px 弱化 |
| 占比条 | 4px 高、2px 圆角的横向分段,颜色与柱段相同,按 token 降序,段间 1px 间隔;与明细同口径只画前 6 个模型,其余合成一段 40% 不透明度的中性段,不会因模型多而被裁掉 |
| 明细 | 8×8px、2px 圆角色块 · 模型名(截断)· token(500,等宽右对齐)· 占比(50% 不透明度);按 token 降序,最多 6 行,其余折叠为「另有 N 个模型」 |