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。

feat(desktop): 用量历史每日柱图改用自绘悬停浮层

Dashbe3c9eb896b1
diff --git a/apps/desktop/src/renderer/components/settings/usage/UsageBarsTooltip.tsx b/apps/desktop/src/renderer/components/settings/usage/UsageBarsTooltip.tsx
new file mode 100644
index 0000000000..58796d15be
--- /dev/null
+++ b/apps/desktop/src/renderer/components/settings/usage/UsageBarsTooltip.tsx
@@ -0,0 +1,179 @@
+/**
+ * UsageBarsTooltip — 每日 token 柱图的悬停浮层 (设置 → 用量历史)。
+ *
+ * 取代原生 title: 原生提示由系统绘制, 无法对齐、无法配色, 模型一多就是一堵字墙。
+ * 整张图只挂**一个**浮层实例, 跟随当前悬停 / 聚焦的柱子移动 (而不是每根柱子一个
+ * Radix Tooltip —— 那是原来选原生 title 的理由)。
+ *
+ * 版式 (所有者 2026-09-26 要求「更好看、有设计感」):
+ * - 头部: 日期 (次要色) + 当日总量 (大号数字, 单位弱化)
+ * - 占比条: 与柱子同色、同顺序的横向分段, 一眼看出当天构成
+ * - 明细: 色块 · 模型名 · token · 占比, 按 token 降序, 数字等宽右对齐
+ * - 模型多于 MAX_ROWS 时折叠成「另有 N 个模型」一行, 浮层高度有上限
+ *
+ * 浮层走 portal + fixed 定位: 设置页滚动容器与卡片都不会裁掉它。优先放在柱图上方,
+ * 上方空间不够时翻到下方; 水平方向以柱子为中心并夹在视口内。只做信息展示,
+ * aria-hidden —— 柱子按钮自带完整的 aria-label。
+ */
+
+import React, { useLayoutEffect, useRef, useState } from 'react';
+import { createPortal } from 'react-dom';
+import { useTranslation } from 'react-i18next';
+
+import { formatCompactTokens } from '@/lib/usageFormat';
+
+const MAX_ROWS = 6;
+const GAP_PX = 8;
+const VIEWPORT_MARGIN_PX = 8;
+
+export interface UsageBarsTooltipSegment {
+ key: string | number;
+ label: string;
+ tokens: number;
+ color: string;
+}
+
+export interface UsageBarsTooltipData {
+ day: string;
+ tokens: number;
+ segments: UsageBarsTooltipSegment[];
+ /** 当前柱子的点击区域 (视口坐标), 决定水平位置。 */
+ anchor: DOMRect;
+ /** 整个绘图区 (视口坐标), 决定上下位置 —— 浮层不遮挡其它柱子。 */
+ plot: DOMRect;
+}
+
+/** 行按 token 降序; 超出 MAX_ROWS 的尾部合并计数。 */
+export function tooltipRows(segments: readonly UsageBarsTooltipSegment[]): {
+ rows: UsageBarsTooltipSegment[];
+ hiddenCount: number;
+ hiddenTokens: number;
+} {
+ const sorted = [...segments].sort((a, b) => b.tokens - a.tokens);
+ const rows = sorted.slice(0, MAX_ROWS);
+ const hidden = sorted.slice(MAX_ROWS);
+ return {
+ rows,
+ hiddenCount: hidden.length,
+ hiddenTokens: hidden.reduce((sum, s) => sum + s.tokens, 0),
+ };
+}
+
+function formatShare(tokens: number, total: number): string {
+ if (!(total > 0)) return '';
+ const share = (tokens / total) * 100;
+ if (share > 0 && share < 1) return '<1%';
+ return `${Math.round(share)}%`;
+}
+
+export function UsageBarsTooltip({
+ data,
+}: {
+ data: UsageBarsTooltipData | null;
+}): React.JSX.Element | null {
+ const { t, i18n } = useTranslation();
+ const ref = useRef<HTMLDivElement>(null);
+ const [position, setPosition] = useState<{
+ left: number;
+ top: number;
+ /** 首次定位不做过渡 (否则会从视口左上角滑入), 之后在柱子间平滑跟随。 */
+ glide: boolean;
+ } | null>(null);
+
+ useLayoutEffect(() => {
+ const el = ref.current;
+ if (!data || !el) {
+ setPosition(null);
+ return;
+ }
+ const { width, height } = el.getBoundingClientRect();
+ const viewportWidth = document.documentElement.clientWidth;
+ const centerX = data.anchor.left + data.anchor.width / 2;
+ const left = Math.min(
+ Math.max(centerX - width / 2, VIEWPORT_MARGIN_PX),
+ viewportWidth - width - VIEWPORT_MARGIN_PX,
+ );
+ const above = data.plot.top - GAP_PX - height;
+ const top = above >= VIEWPORT_MARGIN_PX ? above : data.plot.bottom + GAP_PX;
+ setPosition((prev) => ({ left, top, glide: prev !== null }));
+ }, [data]);
+
+ if (!data) return null;
+
+ const [year, month, day] = data.day.split('-').map(Number);
+ const dateLabel = new Intl.DateTimeFormat(i18n.language, {
+ year: 'numeric',
+ month: 'short',
+ day: 'numeric',
+ weekday: 'short',
+ }).format(new Date(year, (month ?? 1) - 1, day ?? 1));
+ const { rows, hiddenCount, hiddenTokens } = tooltipRows(data.segments);
+ const barSegments = [...data.segments].sort((a, b) => b.tokens - a.tokens);
+
+ return createPortal(
+ <div
+ ref={ref}
+ 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)]"
+ style={{
+ transform: position ? `translate3d(${position.left}px, ${position.top}px, 0)` : undefined,
+ visibility: position ? 'visible' : 'hidden',
+ }}
+ >
+ <div className="text-11 leading-none opacity-60">{dateLabel}</div>
+ <div className="mt-1.5 flex items-baseline gap-1 leading-none">
+ <span className="text-16 font-medium tabular-nums">
+ {data.tokens > 0 ? formatCompactTokens(data.tokens) : '0'}
+ </span>
+ <span className="text-11 opacity-60">{t('usageHistory.daily.tooltip.unit')}</span>
+ </div>
+
+ {data.tokens > 0 ? (
+ <>
+ <div className="mt-2.5 flex h-1 gap-px overflow-hidden rounded-[2px]">
+ {barSegments.map((s) => (
+ <span
+ key={s.key}
+ className="h-full min-w-[2px]"
+ style={{ flexGrow: s.tokens, flexBasis: 0, backgroundColor: s.color }}
+ />
+ ))}
+ </div>
+ <div className="mt-2.5 grid grid-cols-[auto_minmax(0,1fr)_auto_auto] items-center gap-x-2 gap-y-1.5 text-12 leading-none">
+ {rows.map((s) => (
+ <React.Fragment key={s.key}>
+ <span className="h-2 w-2 rounded-[2px]" style={{ backgroundColor: s.color }} />
+ <span className="truncate opacity-80">{s.label}</span>
+ <span className="text-right font-medium tabular-nums">
+ {formatCompactTokens(s.tokens)}
+ </span>
+ <span className="min-w-[3.5ch] text-right tabular-nums opacity-50">
+ {formatShare(s.tokens, data.tokens)}
+ </span>
+ </React.Fragment>
+ ))}
+ {hiddenCount > 0 ? (
+ <>
+ <span className="h-2 w-2 rounded-[2px] border border-current opacity-40" />
+ <span className="truncate opacity-60">
+ {t('usageHistory.daily.tooltip.more', { count: hiddenCount })}
+ </span>
+ <span className="text-right tabular-nums opacity-60">
+ {formatCompactTokens(hiddenTokens)}
+ </span>
+ <span className="min-w-[3.5ch] text-right tabular-nums opacity-50">
+ {formatShare(hiddenTokens, data.tokens)}
+ </span>
+ </>
+ ) : null}
+ </div>
+ </>
+ ) : (
+ <div className="mt-2 text-12 opacity-60">{t('usageHistory.heatmap.emptyCell')}</div>
+ )}
+ </div>,
+ document.body,
+ );
+}
diff --git a/apps/desktop/src/renderer/components/settings/usage/UsageTokenBars.tsx b/apps/desktop/src/renderer/components/settings/usage/UsageTokenBars.tsx
index c5f8118946..739fd21e98 100644
--- a/apps/desktop/src/renderer/components/settings/usage/UsageTokenBars.tsx
+++ b/apps/desktop/src/renderer/components/settings/usage/UsageTokenBars.tsx
@@ -11,10 +11,11 @@
* - 柱高 max(3, round(ratio × H)); 零值日固定 2px, 保留"那天有格子但没用量"的视觉
*
* 日期推算一律以 main 返回的 todayKey 为锚, renderer 不自己取系统日期。
- * 30 根柱子用原生 title 做 tooltip (Radix per-cell 实例太重, 同热力图取舍)。
+ * 悬停 / 聚焦时整张图共用一个 UsageBarsTooltip 浮层 (日期、总量、占比条、按模型明细),
+ * 不再用原生 title —— 原生提示无法排版配色, 也不给每根柱子各挂一个 Radix 实例。
*/
-import React, { useMemo } from 'react';
+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { formatCompactTokens } from '@/lib/usageFormat';
@@ -22,6 +23,7 @@ import type { UsageHistoryModelDay } from '@/hooks/useUsageHistory';
import { usageModelKey } from '@/components/new-chat/usagePalette';
import { usageHistoryModelColor } from './usageHistoryColors';
+import { UsageBarsTooltip, type UsageBarsTooltipData } from './UsageBarsTooltip';
const WINDOW_DAYS = 30;
const CHART_HEIGHT_PX = 96;
@@ -130,6 +132,42 @@ export function UsageTokenBars({
return { list, max: Math.max(...list.map((b) => b.tokens), 0) };
}, [modelDaily, colorOrder, todayKey, t]);
+ const plotRef = useRef<HTMLDivElement>(null);
+ // 只记住悬停的是哪一天和位置; 浮层内容每次渲染从当前 bars 取, 数据刷新时同步更新。
+ const [hover, setHover] = useState<{ day: string; anchor: DOMRect; plot: DOMRect } | null>(null);
+ const showTooltip = useCallback((day: string, target: HTMLElement) => {
+ const plot = plotRef.current;
+ if (!plot) return;
+ setHover({ day, anchor: target.getBoundingClientRect(), plot: plot.getBoundingClientRect() });
+ }, []);
+ const hideTooltip = useCallback(() => setHover(null), []);
+ // fixed 定位的浮层不随页面滚动: 滚动或窗口尺寸变化时直接收起, 不留在错位置。
+ useEffect(() => {
+ if (!hover) return;
+ window.addEventListener('scroll', hideTooltip, true);
+ window.addEventListener('resize', hideTooltip);
+ return () => {
+ window.removeEventListener('scroll', hideTooltip, true);
+ window.removeEventListener('resize', hideTooltip);
+ };
+ }, [hover, hideTooltip]);
+ const hoveredBar = hover ? bars.list.find((b) => b.day === hover.day) : undefined;
+ const tooltip: UsageBarsTooltipData | null =
+ hover && hoveredBar
+ ? {
+ day: hoveredBar.day,
+ tokens: hoveredBar.tokens,
+ segments: hoveredBar.segments.map((s) => ({
+ key: s.rank,
+ label: s.label,
+ tokens: s.tokens,
+ color: usageHistoryModelColor(s.rank, colorOrder.length),
+ })),
+ anchor: hover.anchor,
+ plot: hover.plot,
+ }
+ : null;
+
const ticks = niceTicks(bars.max);
const recentWeekStart = shiftDayKeyLocal(todayKey, -6);
@@ -159,7 +197,11 @@ export function UsageTokenBars({
/>
))}
<div className="absolute inset-0">
- <div className="usage-token-plot flex h-full items-end gap-[3px]">
+ <div
+ ref={plotRef}
+ className="usage-token-plot flex h-full items-end gap-[3px]"
+ onPointerLeave={hideTooltip}
+ >
{bars.list.map((b) => {
const ratio = bars.max > 0 ? b.tokens / bars.max : 0;
const visualHeight =
@@ -169,20 +211,14 @@ export function UsageTokenBars({
b.tokens > 0
? t('usageDashboard.tokensOnly', { tokens: formatCompactTokens(b.tokens) })
: t('usageHistory.heatmap.emptyCell');
- const titleLines = [
- `${b.day} · ${usageSummary}`,
- ...b.segments.map(
- (s) =>
- `${s.label}: ${t('usageDashboard.tokensOnly', {
- tokens: formatCompactTokens(s.tokens),
- })}`,
- ),
- ];
return (
<button
key={b.day}
type="button"
- title={titleLines.join('\n')}
+ data-day={b.day}
+ onPointerEnter={(event) => showTooltip(b.day, event.currentTarget)}
+ onFocus={(event) => showTooltip(b.day, event.currentTarget)}
+ onBlur={hideTooltip}
aria-label={`${dateFormatter.format(parseDayKeyLocal(b.day))} · ${usageSummary}`}
aria-pressed={selectedDay === b.day}
data-highlighted={
@@ -227,6 +263,7 @@ export function UsageTokenBars({
</div>
</div>
</div>
+ <UsageBarsTooltip data={tooltip} />
</div>
);
}
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
new file mode 100644
index 0000000000..68c9b2acca
--- /dev/null
+++ b/apps/desktop/src/renderer/components/settings/usage/__tests__/usageBarsTooltip.test.tsx
@@ -0,0 +1,86 @@
+// @vitest-environment jsdom
+import React from 'react';
+import { cleanup, fireEvent, render, screen } from '@testing-library/react';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { UsageTokenBars } from '../UsageTokenBars';
+import { tooltipRows } from '../UsageBarsTooltip';
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({
+ t: (key: string, opts?: { count?: number }) =>
+ opts?.count !== undefined ? `${key}:${opts.count}` : key,
+ i18n: { language: 'en' },
+ }),
+}));
+afterEach(cleanup);
+
+const money = {
+ amount: 0,
+ currency: 'USD' as const,
+ approximate: false,
+ kind: 'actual-cost' as const,
+};
+const row = (model: string, tokens: number) => ({
+ day: '2026-09-26',
+ agentKind: 'codex' as const,
+ model,
+ tokens,
+ money,
+ apiMoney: money,
+ subscriptionEstimateMoney: money,
+});
+
+describe('usage bars tooltip', () => {
+ it('orders rows by tokens and folds the tail beyond six models', () => {
+ const segments = [1, 9, 3, 7, 5, 2, 8, 4].map((tokens) => ({
+ key: tokens,
+ label: `m${tokens}`,
+ tokens,
+ color: 'red',
+ }));
+ const { rows, hiddenCount, hiddenTokens } = tooltipRows(segments);
+ expect(rows.map((r) => r.tokens)).toEqual([9, 8, 7, 5, 4, 3]);
+ expect(hiddenCount).toBe(2);
+ expect(hiddenTokens).toBe(3);
+ });
+
+ it('replaces the native title with one shared tooltip on hover and focus', () => {
+ const view = render(
+ <UsageTokenBars
+ modelDaily={[row('small', 100), row('big', 900)]}
+ colorOrder={['codex big', 'codex small']}
+ todayKey="2026-09-26"
+ onDayClick={vi.fn()}
+ />,
+ );
+ const bar = view.container.querySelector<HTMLButtonElement>('button[data-day="2026-09-26"]')!;
+ expect(bar.hasAttribute('title')).toBe(false);
+ expect(screen.queryByTestId('usage-bars-tooltip')).toBeNull();
+
+ fireEvent.pointerOver(bar);
+ const tooltip = screen.getByTestId('usage-bars-tooltip');
+ expect(tooltip.getAttribute('aria-hidden')).toBe('true');
+ const text = tooltip.textContent ?? '';
+ expect(text.indexOf('big')).toBeLessThan(text.indexOf('small'));
+ expect(text).toContain('90%');
+ expect(text).toContain('10%');
+
+ fireEvent.pointerOut(bar.parentElement!, { relatedTarget: document.body });
+ expect(screen.queryByTestId('usage-bars-tooltip')).toBeNull();
+
+ fireEvent.focus(bar);
+ expect(screen.getByTestId('usage-bars-tooltip')).toBeTruthy();
+ fireEvent.blur(bar);
+ expect(screen.queryByTestId('usage-bars-tooltip')).toBeNull();
+ });
+
+ it('shows the empty-day message for a day without usage', () => {
+ const view = render(
+ <UsageTokenBars modelDaily={[]} colorOrder={[]} todayKey="2026-09-26" onDayClick={vi.fn()} />,
+ );
+ fireEvent.pointerOver(view.container.querySelector('button[data-day="2026-09-20"]')!);
+ expect(screen.getByTestId('usage-bars-tooltip').textContent).toContain(
+ 'usageHistory.heatmap.emptyCell',
+ );
+ });
+});
diff --git a/apps/desktop/src/renderer/components/settings/usage/__tests__/usageHistoryColors.test.tsx b/apps/desktop/src/renderer/components/settings/usage/__tests__/usageHistoryColors.test.tsx
index 5a730083e7..5c043e120d 100644
--- a/apps/desktop/src/renderer/components/settings/usage/__tests__/usageHistoryColors.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/usage/__tests__/usageHistoryColors.test.tsx
@@ -94,7 +94,7 @@ describe('Usage History model colors', () => {
</>,
);
const mark = view.container.querySelector<HTMLElement>(
- 'button[title^="2026-09-09"] [data-usage-mark]',
+ 'button[data-day="2026-09-09"] [data-usage-mark]',
)!;
expect(mark.children).toHaveLength(35);
expect(mark.style.height).toBe('96px');
@@ -158,7 +158,7 @@ describe('Usage History model colors', () => {
<UsageModelTable rows={[row]} colorOrder={colorOrder} rangeLabel="day" />
</>,
);
- const mark = view.container.querySelector('button[title^="2026-09-08"] [data-usage-mark]')!;
+ const mark = view.container.querySelector('button[data-day="2026-09-08"] [data-usage-mark]')!;
const segment = mark.firstElementChild as HTMLElement;
const swatch = view.getByText('second').previousElementSibling as HTMLElement;
expect(segment.style.backgroundColor).toBe('var(--usage-model-2)');
diff --git a/apps/desktop/src/renderer/components/settings/usage/__tests__/usageTokenBars.test.tsx b/apps/desktop/src/renderer/components/settings/usage/__tests__/usageTokenBars.test.tsx
index a86afd196f..c111d41230 100644
--- a/apps/desktop/src/renderer/components/settings/usage/__tests__/usageTokenBars.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/usage/__tests__/usageTokenBars.test.tsx
@@ -37,7 +37,7 @@ describe('UsageTokenBars registered geometry and interaction', () => {
const view = render(<UsageTokenBars {...props} />);
const highlightedDays = () =>
[...view.container.querySelectorAll<HTMLButtonElement>('[data-highlighted="true"]')].map(
- (button) => button.title.slice(0, 10),
+ (button) => button.dataset.day,
);
expect(highlightedDays()).toEqual([]);
view.rerender(<UsageTokenBars {...props} highlightRecentWeek />);
diff --git a/apps/desktop/src/renderer/components/settings/usage/usageCharts.css b/apps/desktop/src/renderer/components/settings/usage/usageCharts.css
index 5a1d719158..12fcc82b8c 100644
--- a/apps/desktop/src/renderer/components/settings/usage/usageCharts.css
+++ b/apps/desktop/src/renderer/components/settings/usage/usageCharts.css
@@ -91,3 +91,23 @@
.usage-history-charts .usage-heatmap-month-label {
font-size: var(--text-11);
}
+
+/* Both modes render the tooltip dark; in Dark it sits on a near-identical card surface,
+ so a hairline derived from the tooltip text color keeps its edge legible. */
+.usage-bars-tooltip {
+ box-shadow:
+ inset 0 0 0 1px color-mix(in srgb, var(--tooltip-text) 10%, transparent),
+ var(--shadow-menu);
+}
+
+/* The shared daily-bars tooltip is portaled outside .usage-history-charts. It glides
+ between bars (after its first placement) instead of jumping; reduced motion snaps. */
+.usage-bars-tooltip[data-glide='true'] {
+ transition: transform var(--motion-fast) var(--motion-ease-out);
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .usage-bars-tooltip[data-glide='true'] {
+ transition: none;
+ }
+}
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 0e737077c5..8d69e5a397 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -6567,7 +6567,12 @@
},
"daily": {
"title": "Daily tokens (30d)",
- "subtitle": "Stacked by model"
+ "subtitle": "Stacked by model",
+ "tooltip": {
+ "unit": "tokens",
+ "more_one": "{{count}} more model",
+ "more_other": "{{count}} more models"
+ }
},
"byAgent": {
"title": "By Agent / harness",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index c03582817a..ed7b193b74 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -6565,7 +6565,12 @@
},
"daily": {
"title": "直近 30 日の日次トークン",
- "subtitle": "モデル別の積み上げ"
+ "subtitle": "モデル別の積み上げ",
+ "tooltip": {
+ "unit": "トークン",
+ "more_one": "ほか {{count}} モデル",
+ "more_other": "ほか {{count}} モデル"
+ }
},
"byAgent": {
"title": "Agent / harness 別",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 376e366988..bbd6e5794d 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -6565,7 +6565,12 @@
},
"daily": {
"title": "최근 30일 일별 토큰",
- "subtitle": "모델별 누적"
+ "subtitle": "모델별 누적",
+ "tooltip": {
+ "unit": "토큰",
+ "more_one": "외 {{count}}개 모델",
+ "more_other": "외 {{count}}개 모델"
+ }
},
"byAgent": {
"title": "Agent / harness별",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 73ce60d07d..39ec4e9b97 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -6565,7 +6565,12 @@
},
"daily": {
"title": "近 30 天每日 token",
- "subtitle": "按模型堆叠"
+ "subtitle": "按模型堆叠",
+ "tooltip": {
+ "unit": "token",
+ "more_one": "另有 {{count}} 个模型",
+ "more_other": "另有 {{count}} 个模型"
+ }
},
"byAgent": {
"title": "按 Agent / harness",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 2b9eef91ba..455d0f0781 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -6565,7 +6565,12 @@
},
"daily": {
"title": "近 30 天每日 token",
- "subtitle": "按模型堆疊"
+ "subtitle": "按模型堆疊",
+ "tooltip": {
+ "unit": "token",
+ "more_one": "另有 {{count}} 個模型",
+ "more_other": "另有 {{count}} 個模型"
+ }
},
"byAgent": {
"title": "按 Agent / harness",
diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.md
index 370281e8ca..078ec32e49 100644
--- a/docs/design-rules/DESIGN.md
+++ b/docs/design-rules/DESIGN.md
@@ -383,7 +383,7 @@ Reference implementation: `apps/desktop/src/renderer/components/ui/confirm-dialo
- `UsageHeatmap` and `UsageTokenBars` encode dates and quantities, including when clicking a mark filters by date. **Clickable data marks keep their data geometry; they are not ordinary pill buttons.** Their corner treatment is the registered data-mark members `usage-heatmap-day` and `usage-token-bar` (§5) — **the registration covers the coloured mark itself, not its hit region, legend, container or tooltip** — and is limited to these usage charts. For the heatmap, the transparent date hit target overlays the cell and shares its 12×12 footprint. For the token bars, the hit target may extend beyond a low or zero bar — the implementation gives it at least 24px of height — while the bar itself keeps its data height. In both charts the hit target's corner treatment is an implementation choice (currently the mark's 2px) and is not fixed by the registration; focus and selection indicators are independent of the registration and follow §5's interaction rules.
- Heatmap: 12×12px square cells, 2px radius and 3px gaps in both read-only and clickable views. Reserve a 3px outer gutter so edge cells retain their focus/selected outlines. Preserve month alignment, the complete requested history window and the existing four-level neutral intensity scale.
- Token bars: 30 equal-width slim columns fitted to the plot, 3px gaps, 2px outer radius, shared baseline and proportional stacked segments. Do not enforce a 24px minimum column width or clip the latest days behind horizontal scrolling. A low/zero bar may have a taller transparent hit target without inflating its data height.
-- Preserve native date/value tooltips, accessible date/value labels, keyboard activation and visible focus/selected outlines. Charts stay on the semantic gray palette except for the owner-approved Usage History chart colors registered in §2 (2026-09-08); this remains a geometry exception, not permission to introduce further category colors or apply chart radii to other buttons.
+- Preserve date/value tooltips (the heatmap keeps the native title; the daily token bars use the shared `UsageBarsTooltip` overlay registered in `usage-history-charts.md`, 2026-09-26), accessible date/value labels, keyboard activation and visible focus/selected outlines. Charts stay on the semantic gray palette except for the owner-approved Usage History chart colors registered in §2 (2026-09-08); this remains a geometry exception, not permission to introduce further category colors or apply chart radii to other buttons.
### Usage History Charts
diff --git a/docs/design-rules/design-decision-log.md b/docs/design-rules/design-decision-log.md
index 348e89c375..f166210c7b 100644
--- a/docs/design-rules/design-decision-log.md
+++ b/docs/design-rules/design-decision-log.md
@@ -14,6 +14,8 @@
- **09-26 移动端色板独立并改为「象牙白 / 中性近黑」,加入显示模式设置**——用户 09-25 确认移动端设计规范与组件可与桌面解耦(共享品牌与业务语义、自定色阶与对比度,要求更高对比度);09-26 在 Design Lab 对比多版方案后定稿,并要求设置里提供跟随系统 / 浅色 / 深色。被取代:2026-07-18「双端色彩同构」基线与 2026-08 待办的移动端同步、移动端浅色边框例外 `#C6C9CE`、U2 在移动端的适用(二级文字 `#8C8E94` / `#6F6F6F` 比三级更浅且仅 2.8 / 2.9:1)。现行:浅色页面 `#F9F9F6`(用户指定;比桌面 `#F2F2ED` 更亮,暖度 B = R−3)、卡片 `#FFFFFC`、正文 `#1A1A1A`、二级 `#4D4D4A`、三级 `#686864`;深色页面 `#121212`、卡片 `#1E1E1E`、正文 `#EDEDED`、二级 `#BDBDBD`、三级 `#999999`;三档文字在所在底色上均 ≥ 4.5:1。近白页面只给浅色卡片留 1.05 的抬升(桌面 1.12),因此浅色浮起面以 1px `border` 分层,代码卡改为下沉 `#F1F1EC`。落点:`DESIGN.md §15.13`(§15.5 标注仅桌面)、`apps/mobile/src/theme/tokens.ts`、`themeTokens.test.ts`、`theme-colors-snapshot.json`、`mobile-design-guide.md §2`。各轮候选与对比保留在 Design Lab `colors` 专题。本条为方向与色值裁决,不代表实机视觉验收。
+- **09-26 用量历史每日柱图改用自绘悬停浮层**——所有者看过原生 title 提示的截图后要求「重绘,要更好看、有设计感」。每日 token 柱图改用整张图共用的 `UsageBarsTooltip`:日期与大号总量、与柱段同色的占比条、按 token 降序的模型明细(色块、token、占比,最多 6 行)。深底白字与 12px 圆角沿用共享 Tooltip;色块与占比条沿用 `usage-token-bar` 的 2px 数据图元角,不新增形状登记。本条**替代 `DESIGN.md` 对两张用量图「保留原生 tooltip」的要求中柱图部分**,热力图仍用原生 title。现行规格见 `usage-history-charts.md`「每日柱图悬停浮层」;本条为需求授权记录,实机视觉验收待所有者完成。
+
- **09-21 Cindy 设备选择器沿用未读语义色**——Cindy 在多设备聚合后仍表示同一个任务的未读消息;侧栏设备行、设备选择器的入口/选项以及共享聊天头设备选择器沿用 `--bot-unread-bg` / `--bot-unread-fg`,与伙伴列表未读数量和待处理点保持一致。作用域扩展到 `features/bots` 的 Cindy 设备未读指示器,仍不用于连接状态、其它徽章或表面;两种模式保持同一蓝白配对,现行规范见 `DESIGN.md §2`、`§10`。
- **09-21 Cindy Make 个人版左对齐并常显括号状态(后续修订)**——用户指出个人版看起来没有与 main 左对齐,并要求名称后加括号描述状态。去掉标识底色与额外内边距,使图标从 main 行相同的左边界起排;显示“图标 + cindy-personal(已是最新/有更新/版本状态未确认)”,整组随状态着色,SHA 和修改数量仍在后面。取代同日仅在悬停时显示状态词的处理,现行规范见 `DESIGN.md §2`。
diff --git a/docs/design-rules/usage-history-charts.md b/docs/design-rules/usage-history-charts.md
index 8c35cf067e..00800f09a5 100644
--- a/docs/design-rules/usage-history-charts.md
+++ b/docs/design-rules/usage-history-charts.md
@@ -7,7 +7,7 @@
| 可见角色 | 半径依据 | 尺寸与数据映射 |
| --- | --- | --- |
| 热力图日格 | §5 成员 `usage-heatmap-day` | 可见格 12×12px,行列间隔 3px。金额/Token 口径、分位色阶、日期窗口算法沿用组件原逻辑;静止形状和网格密度不随点击启用与否改变;09-08 登记的交互强调见下。滚动视口内预留 3px 外围空间,容纳边缘指示器。 |
-| 每日 Token 柱 | §5 成员 `usage-token-bar` | 固定近 30 天、柱间隔 3px,均分可用绘图区宽度;不设每柱 24px 最小宽度或 807px 容器下限。非零高度按原比例计算、最低 3px;零值日保留 2px 高。总量、日期 tooltip 与纵轴刻度保留;模型分段按下述 09-09 裁决覆盖完整模型,tooltip 按实际模型列出。 |
+| 每日 Token 柱 | §5 成员 `usage-token-bar` | 固定近 30 天、柱间隔 3px,均分可用绘图区宽度;不设每柱 24px 最小宽度或 807px 容器下限。非零高度按原比例计算、最低 3px;零值日保留 2px 高。总量、日期 tooltip 与纵轴刻度保留;模型分段按下述 09-09 裁决覆盖完整模型,tooltip 按实际模型列出(样式见下「每日柱图悬停浮层」)。 |
柱体自身的裁剪采用同一登记处理。按钮的透明命中层不裁剪数据图元,不继承 pill 外形;键盘按钮语义、可访问日期/用量名称和 `aria-pressed` 保留。非交互渲染分支仍不创建按钮,其格子遵守同一成员登记。
@@ -15,6 +15,20 @@
用量历史默认合并同账号所有电脑的用量,时间范围选择器左侧增加设备选择器:所有设备(默认)/ 本机 / 其它电脑。外观、尺寸与时间范围选择器一致(36px 胶囊触发器、同一下拉菜单样式;按 `DESIGN.md §4` 面板与触发器等宽,长设备名截断、状态说明在面板内换行),选项下方以 12px tertiary 文字注明其它电脑的「数据截至」时间或读不到的原因(离线、未允许远程控制、需要更新 Cindy、读取失败)。其它电脑只列出读到过用量的(有「数据截至」),从未读到的不显示;没有这样的电脑时不显示选择器。进入页面后第一次读取其它电脑期间,控件下方显示一行 12px tertiary 的小 spinner +「正在读取其它设备的用量…」,之后每分钟的后台同步不再提示。合并视图里有电脑读不到最新数据时,控件下方显示一行 12px tertiary 提示。「最耗 token 的任务」按所选时间范围统计每个任务在该范围内产生的 token(每日 × 任务记录,从功能上线起积累;所选范围早于最早记录时副标题注明「按天统计从 X 起」),多设备范围合并其它电脑的任务并在任务名下方用 12px tertiary 标出设备名。任务标题、模型与删除状态取当前值:页面打开期间重命名或删除任务会随即反映,不等下一次用量变化。任务标题是跳转到该任务的链接,整行是鼠标的放大命中区(hover 使用 `--surface-hover`);其它电脑的任务仅在该设备已连接、能找到对应任务时可点击。各设备的用量按其本地日期计(记录只精确到天,无法按小时换算);其它电脑已跨入本机「明天」时,超出本机今天的部分计入本机今天,避免今日合计和图表漏掉。读取其它电脑走后台链路,对方不会显示「正在被控制」横幅;0.1.93 及更早版本的电脑不去读取,状态为「需要更新 Cindy」。切换账号时设备选择回到「所有设备」,不保留上一个账号的设备列表。热力图、柱图、表格与配色规则不因设备范围改变。
+## 每日柱图悬停浮层(2026-09-26 所有者要求)
+
+所有者认为原生 title 提示「不好看、没有设计感」,每日 token 柱图改用自绘浮层 `UsageBarsTooltip`,热力图仍保留原生 title。整张图共用一个浮层实例,悬停或键盘聚焦柱子时显示,离开绘图区、失焦、滚动或窗口尺寸变化时收起。
+
+| 层 | 规格 |
+| --- | --- |
+| 容器 | `--tooltip-bg` / `--tooltip-text`(两模式同为深底白字,沿用共享 Tooltip),12px 圆角、`--shadow-menu` 投影加 10% `--tooltip-text` 发丝内描边(Dark 下与卡片底色区分),内边距 12×10px,宽 220–320px |
+| 头部 | 日期(含星期,11px,60% 不透明度);当日总量 16px / 500 等宽数字,单位 11px 弱化 |
+| 占比条 | 4px 高、2px 圆角的横向分段,颜色与柱段相同,按 token 降序,段间 1px 间隔 |
+| 明细 | 8×8px、2px 圆角色块 · 模型名(截断)· token(500,等宽右对齐)· 占比(50% 不透明度);按 token 降序,最多 6 行,其余折叠为「另有 N 个模型」 |
+| 位置与动效 | portal + fixed,优先置于绘图区上方,空间不足翻到下方,水平以柱子为中心并夹在视口内;入场 `animate-fade-in`,在柱子之间以 `--motion-fast` 平滑跟随,首次定位与减少动态效果时不过渡 |
+
+浮层 `aria-hidden`,读屏仍读柱子按钮的日期与总量标签。色块与占比条沿用 `usage-token-bar` 的 2px 数据图元角,不是新的形状登记。
+
## 页面排版(2026-09-08 所有者反馈)
用量历史对齐其他设置页面的阅读层级,沿用 `DESIGN.md §3` 的现有字号 Token,不修改全局字号或共享首页排版: