usage: the chart's tooltip says counts short, as the axis does (skyhuang1994)

The Usage page's bar chart tooltip wrote each row, the sum and the
request count in full (31,846,455 · 32,292,989). It now uses the page's
compact formatter: K/M in every language, 万/亿 (萬/億 in zh-TW) when
Chinese units are on. Cost and speed keep their long forms.

usage-compact-counts.test.cjs gets a chart point with the reporter's
numbers and hovers it in every language, at 1100px and 420px.

Run on mote:
- usage-compact-counts, chromium and webkit: 15/15 each.
- Related GUI files in both engines (gui-de/ja/zh-tw, i18n-keys,
  number-units, panel-units-follow, panel-usage, quota-curve,
  usage-chart-*, usage-ledger*, usage-speed*, usage-ttft-rounding,
  usage-compact-counts, usage-model-at-provider, usage-sum-whole,
  click-scroll): 674/681. The 7 reds are i18n-keys "a plugin's words
  are its own" (#5332, #5426) and usage-ledger "newest live route needs
  no return-to-live button" in both engines (#3104). Both are red the
  same way at origin/main 1493acb46 without this change.
- TestCoreScriptBudget at the pushed head: under budget, not raised.

Broken by hand: with the old app.js the new test is red 0/15
("the tooltip says [31,846,455, 446,534, 32,292,989 · 123,456 requests]").

Not tried: the whole GUI suite; the real app with a live ledger.
This commit is contained in:
yetone
2026-11-06 10:05:15 +08:00
parent e1d4dca967
commit ce2a59daa9
2 changed files with 28 additions and 8 deletions
+6 -4
View File
@@ -18959,6 +18959,8 @@ function drawLedColumns(box, l, split, metric, compact, chooseDay, focusDay) {
tip.hidden = true;
plot.append(g, tip);
const name = (c) => t(c.name || c.id || "—");
// counts short, as the axis says them (skyhuang1994)
const val = (v) => speed || metric === "cost" ? ledFormatLong(metric, v) : ledFormat(metric, v);
const at = (e) => {
const r = g.getBoundingClientRect();
const i = Math.max(0, Math.min(n - 1, Math.floor(((e.clientX - r.left) / r.width * W - M.l) / slot)));
@@ -18976,17 +18978,17 @@ function drawLedColumns(box, l, split, metric, compact, chooseDay, focusDay) {
const row = el("div");
const sw = el("i");
sw.style.background = color;
row.append(sw, el("span", "", nm), el("em", "", ledFormatLong(metric, v)));
row.append(sw, el("span", "", nm), el("em", "", val(v)));
if (speed) row.append(el("em", "ttft", ledTTFT(part) ? t("TTFT {ms}", { ms: ledTook(ledTTFT(part)) }) : ""));
tip.append(row);
}
const sum = el("div", "sum");
const calls = metric !== "calls" && p.calls ? t(p.calls === 1 ? "{n} request" : "{n} requests", { n: ledNum(p.calls) }) : "";
const calls = metric !== "calls" && p.calls ? t(p.calls === 1 ? "{n} request" : "{n} requests", { n: fmtN(p.calls) }) : "";
if (speed) {
sum.append(el("span", "", t("All") + (calls ? " · " + calls : "")), el("em", "", ledFormatLong(metric, totals[i])),
sum.append(el("span", "", t("All") + (calls ? " · " + calls : "")), el("em", "", val(totals[i])),
el("em", "ttft", ledTTFT(p) ? t("TTFT {ms}", { ms: ledTook(ledTTFT(p)) }) : ""));
} else {
sum.append(el("span", "", t("Total")), el("em", "", ledFormatLong(metric, totals[i]) + (calls ? " · " + calls : "")));
sum.append(el("span", "", t("Total")), el("em", "", val(totals[i]) + (calls ? " · " + calls : "")));
}
tip.append(sum);
tip.hidden = false;
@@ -4,7 +4,9 @@
// in full (52,345,678), and the Requests total, the line over the list, the
// ranking and the Routing page's counts said requests in full. Each says
// fmtN's short form now (52M, 123K, or 5234.6 万 with Settings' 万 / 亿), and
// its exact value on hover. In every language, both engines, at 1100 and
// its exact value on hover. The chart's tooltip said a column's tokens in full
// too (31,846,455 of 32,292,989, skyhuang1994 again) and says them short now,
// as its axis does. In every language, both engines, at 1100 and
// 420 wide; the API is faked.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
@@ -16,6 +18,12 @@ const assets = path.resolve(__dirname, "../assets");
const now = Date.now();
const IN = 1234567, OUT = 98765, READ = 52345678, WRITE = 400, CALLS = 123456;
const ALL = IN + OUT + READ + WRITE;
// the reporter's column: one model's tokens of the hour's total
const COL = 31846455, COL_ALL = 32292989;
const POINT = {
time: new Date(now - 60e3).toISOString(), calls: CALLS, errors: 0, input: COL_ALL, output: 0, cache_read: 0, cache_write: 0, cost: 2,
by: { model: { "claude-opus-5": { calls: CALLS, tokens: COL, cost: 2 } }, provider: { claude: { calls: CALLS, tokens: COL, cost: 2 } }, agent: { claude: { calls: CALLS, tokens: COL, cost: 2 } } },
};
const ROWS = [{
t: new Date(now - 60e3).toISOString(), agent: "claude", agentName: "Claude Code", icon: "claudecode-color",
provider: "claude", providerName: "Claude", providerAccount: "a@example.com", req: "claude-opus-5", model: "claude-opus-5", served: "claude-opus-5",
@@ -23,7 +31,7 @@ const ROWS = [{
}];
const tot = { calls: CALLS, errors: 0, input: IN, output: OUT, cache_read: READ, cache_write: WRITE, reasoning: 0, cost: 2, unpriced: 0 };
const ledger = {
period: "today", rows: ROWS, offset: 0, total: CALLS, ...tot, bucket: "hour", series: [],
period: "today", rows: ROWS, offset: 0, total: CALLS, ...tot, bucket: "hour", series: [POINT],
by: { provider: [{ id: "claude", name: "Claude", icon: "claude-color", ...tot }], agent: [{ id: "claude", name: "Claude Code", icon: "claudecode-color", ...tot }], model: [{ id: "claude-opus-5", name: "claude-opus-5", ...tot }] },
agents: [{ id: "claude", name: "Claude Code", icon: "claudecode-color" }], providers: [{ id: "claude", name: "Claude", icon: "claude-color" }],
};
@@ -58,8 +66,8 @@ function serve(lang, units) {
const LOCALE = { en: "en", zh: "zh-CN", "zh-TW": "zh-TW", ja: "ja-JP", de: "de-DE" };
// the short forms: K / M by default, 万 / 亿 in Chinese with Settings' units
const KMB = { [IN]: "1.2M", [OUT]: "98.8K", [READ]: "52M", [CALLS]: "123K", [ALL]: "54M", 1234: "1.2K", 23456: "23.5K" };
const WAN = { [IN]: "123.5 万", [OUT]: "9.9 万", [READ]: "5234.6 万", [CALLS]: "12.3 万", [ALL]: "5367.9 万", 1234: "1234", 23456: "2.3 万" };
const KMB = { [COL]: "32M", [COL_ALL]: "32M", [COL_ALL - COL]: "447K", [IN]: "1.2M", [OUT]: "98.8K", [READ]: "52M", [CALLS]: "123K", [ALL]: "54M", 1234: "1.2K", 23456: "23.5K" };
const WAN = { [COL]: "3184.6 万", [COL_ALL]: "3229.3 万", [COL_ALL - COL]: "44.7 万", [IN]: "123.5 万", [OUT]: "9.9 万", [READ]: "5234.6 万", [CALLS]: "12.3 万", [ALL]: "5367.9 万", 1234: "1234", 23456: "2.3 万" };
const CASES = [...Object.keys(LOCALE).map((lang) => [lang, false]), ["zh", true], ["zh-TW", true]];
const short = (lang, units, n) => units ? WAN[n].replace("万", lang === "zh-TW" ? "萬" : "万") : KMB[n];
@@ -101,6 +109,16 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal((await val.textContent()).trim(), s(ALL), `${at}: the ranking's tokens`);
assert.equal(await val.getAttribute("title"), x(ALL), `${at}: the ranking's tooltip`);
assert.ok(!(await rank.textContent()).includes(x(CALLS)), `${at}: the ranking says requests in full`);
// the chart's tooltip over the column: the model, the rest, the total and its requests
await page.locator("#ledChart svg").hover();
const tip = page.locator("#ledChart .tip");
await tip.waitFor();
const said = await tip.locator("em").allTextContents();
const tipText = await tip.innerText();
assert.deepEqual(said.slice(0, 2), [s(COL), s(COL_ALL - COL)], `${at}: the tooltip says ${JSON.stringify(said)}`);
assert.ok(said[2]?.startsWith(s(COL_ALL) + " · ") && said[2].includes(s(CALLS)), `${at}: the tooltip's total says ${said[2]}`);
for (const n of [COL, COL_ALL, CALLS]) assert.ok(!tipText.includes(x(n)), `${at}: the tooltip says ${x(n)} in full: ${tipText}`);
await page.mouse.move(1, 1);
let over = await page.evaluate(() => document.documentElement.scrollWidth - innerWidth);
assert.ok(over <= 1, `${at}: the Usage page is ${over}px past`);