Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: optional Chart view with labelled axes for weekly and cumulative token activity (#13558)

Daniel Han8f9ea7a54284
diff --git a/studio/frontend/src/features/profile/components/stats/stat-primitives.tsx b/studio/frontend/src/features/profile/components/stats/stat-primitives.tsx
index c6967ae2e62..ee1d8cdc6dc 100644
--- a/studio/frontend/src/features/profile/components/stats/stat-primitives.tsx
+++ b/studio/frontend/src/features/profile/components/stats/stat-primitives.tsx
@@ -27,7 +27,7 @@ export function StatsCard({
)}
>
{title ? (
- <header className="flex items-start justify-between gap-3">
+ <header className="flex flex-wrap items-start justify-between gap-3">
<div className="flex min-w-0 flex-col gap-0.5">
<h3 className="text-sm font-semibold font-heading text-foreground">
{title}
@@ -36,7 +36,7 @@ export function StatsCard({
<p className="text-xs text-muted-foreground">{description}</p>
) : null}
</div>
- {action ? <div className="shrink-0">{action}</div> : null}
+ {action ? <div className="max-w-full shrink-0">{action}</div> : null}
</header>
) : null}
{children}
diff --git a/studio/frontend/src/features/profile/components/stats/token-activity-card.tsx b/studio/frontend/src/features/profile/components/stats/token-activity-card.tsx
index bc0c034800e..e823f12a303 100644
--- a/studio/frontend/src/features/profile/components/stats/token-activity-card.tsx
+++ b/studio/frontend/src/features/profile/components/stats/token-activity-card.tsx
@@ -1,18 +1,32 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+import { ChartContainer, ChartTooltip } from "@/components/ui/chart";
+import type { ChartConfig } from "@/components/ui/chart";
import { useLocale, useT } from "@/i18n";
import { cn } from "@/lib/utils";
import { useEffect, useMemo, useRef, useState } from "react";
+import {
+ Bar,
+ BarChart,
+ CartesianGrid,
+ Line,
+ LineChart,
+ XAxis,
+ YAxis,
+} from "recharts";
import type { ProfileStatsDay } from "../../api/profile-stats";
+import { useActivityChartStore } from "../../stores/activity-chart-store";
import {
type ActivityMode,
+ type WeekChartPoint,
activitySummaryForMode,
formatCompactNumber,
formatProfileCount,
heatLevel,
parseDayKey,
seriesForMode,
+ weekChartPoints,
windowBaseline,
} from "../../utils/stats-format";
import { StatsCard } from "./stat-primitives";
@@ -252,6 +266,111 @@ function BarColumn({
);
}
+const WEEK_CHART_CONFIG = {
+ tokens: { color: "var(--primary)" },
+} satisfies ChartConfig;
+
+/** Opt-in view: Weekly as bars, Cumulative as a line, on labelled token and date axes. */
+function WeekChart({
+ grid,
+ mode,
+ dateFormatter,
+}: {
+ grid: Cell[][];
+ mode: ActivityMode;
+ dateFormatter: Intl.DateTimeFormat;
+}) {
+ const t = useT();
+ const locale = useLocale();
+ const data = useMemo(() => weekChartPoints(grid), [grid]);
+ const tickFormatter = useMemo(
+ () => new Intl.DateTimeFormat(locale, { month: "short", day: "numeric" }),
+ [locale],
+ );
+ const xAxis = (
+ <XAxis
+ dataKey="week"
+ tickLine={true}
+ axisLine={true}
+ tickMargin={6}
+ minTickGap={24}
+ interval="preserveStartEnd"
+ tickFormatter={(value) =>
+ tickFormatter.format(parseDayKey(String(value)))
+ }
+ />
+ );
+ const yAxis = (
+ <YAxis
+ tickLine={true}
+ axisLine={true}
+ tickMargin={4}
+ tickCount={4}
+ allowDecimals={false}
+ width={48}
+ tickFormatter={(value) => formatCompactNumber(Number(value), locale)}
+ />
+ );
+ const tooltip = (
+ <ChartTooltip
+ cursor={mode === "weekly" ? undefined : false}
+ content={({ active, payload }) => {
+ const point = payload?.[0]?.payload as WeekChartPoint | undefined;
+ if (!(active && point)) {
+ return null;
+ }
+ return (
+ <div className="rounded-md border border-border/50 bg-background px-2 py-1 text-xs shadow-md">
+ {t("settings.profile.stats.weekTooltip", {
+ date: dateFormatter.format(parseDayKey(point.week)),
+ tokens: formatProfileCount(point.tokens, "token", locale),
+ })}
+ </div>
+ );
+ }}
+ />
+ );
+ const margin = { top: 6, right: 8, bottom: 0, left: 0 };
+
+ return (
+ <ChartContainer
+ config={WEEK_CHART_CONFIG}
+ className="h-[calc(140px*var(--ui-space-scale,1))] w-full"
+ >
+ {mode === "weekly" ? (
+ <BarChart data={data} margin={margin} accessibilityLayer={true}>
+ <CartesianGrid vertical={false} strokeDasharray="3 3" />
+ {xAxis}
+ {yAxis}
+ {tooltip}
+ <Bar
+ dataKey="tokens"
+ fill="var(--color-tokens)"
+ radius={[3, 3, 0, 0]}
+ isAnimationActive={false}
+ />
+ </BarChart>
+ ) : (
+ <LineChart data={data} margin={margin} accessibilityLayer={true}>
+ <CartesianGrid vertical={false} strokeDasharray="3 3" />
+ {xAxis}
+ {yAxis}
+ {tooltip}
+ <Line
+ type="linear"
+ dataKey="tokens"
+ stroke="var(--color-tokens)"
+ strokeWidth={2}
+ dot={data.length <= 1 ? { r: 3, strokeWidth: 0 } : false}
+ activeDot={{ r: 3, strokeWidth: 0 }}
+ isAnimationActive={false}
+ />
+ </LineChart>
+ )}
+ </ChartContainer>
+ );
+}
+
export function TokenActivityCard({ daily }: { daily: ProfileStatsDay[] }) {
const t = useT();
const [mode, setMode] = useState<ActivityMode>("daily");
@@ -259,6 +378,9 @@ export function TokenActivityCard({ daily }: { daily: ProfileStatsDay[] }) {
const { ref, columns } = useVisibleColumns(maxColumns);
const shaded = mode === "daily";
+ const showChart = useActivityChartStore((state) => state.showChart);
+ const setShowChart = useActivityChartStore((state) => state.setShowChart);
+ const charted = !shaded && showChart;
const values = useMemo(() => seriesForMode(daily, mode), [daily, mode]);
const grid = useMemo(
() => buildColumns(daily, values, columns, mode),
@@ -319,59 +441,85 @@ export function TokenActivityCard({ daily }: { daily: ProfileStatsDay[] }) {
weeks: formatProfileCount(grid.length, "week", locale),
})}
action={
- <div className="hub-tab-toggle inline-flex h-8 w-fit items-center rounded-full">
- {MODES.map((option) => (
- <button
- key={option}
- type="button"
- onClick={() => setMode(option)}
- aria-pressed={mode === option}
- className={cn(
- "inline-flex h-8 items-center rounded-full px-3 text-ui-13 font-medium transition-colors",
- mode === option
- ? "hub-tab-toggle-pill text-foreground"
- : "text-muted-foreground hover:text-foreground",
- )}
- >
- {t(`settings.profile.stats.mode.${option}`)}
- </button>
- ))}
+ <div className="flex flex-wrap items-center justify-end gap-2">
+ {shaded ? null : (
+ <div className="hub-tab-toggle inline-flex h-8 w-fit items-center rounded-full">
+ <button
+ type="button"
+ onClick={() => setShowChart(!showChart)}
+ aria-pressed={showChart}
+ title={t("settings.profile.stats.chartToggleHint")}
+ className={cn(
+ "inline-flex h-8 items-center rounded-full px-3 text-ui-13 font-medium transition-colors",
+ showChart
+ ? "hub-tab-toggle-pill text-foreground"
+ : "text-muted-foreground hover:text-foreground",
+ )}
+ >
+ {t("settings.profile.stats.chartToggle")}
+ </button>
+ </div>
+ )}
+ <div className="hub-tab-toggle inline-flex h-8 w-fit items-center rounded-full">
+ {MODES.map((option) => (
+ <button
+ key={option}
+ type="button"
+ onClick={() => setMode(option)}
+ aria-pressed={mode === option}
+ className={cn(
+ "inline-flex h-8 items-center rounded-full px-3 text-ui-13 font-medium transition-colors",
+ mode === option
+ ? "hub-tab-toggle-pill text-foreground"
+ : "text-muted-foreground hover:text-foreground",
+ )}
+ >
+ {t(`settings.profile.stats.mode.${option}`)}
+ </button>
+ ))}
+ </div>
</div>
}
>
{/* Measured, never scrolled: the grid is trimmed to fit instead. */}
<div ref={ref} className="w-full overflow-hidden">
- <div className="flex gap-[3px]">
- {grid.map((column) =>
- shaded ? (
- <DayColumn
- key={column[0]?.key ?? "column"}
- column={column}
- peak={peak}
- dateFormatter={dateFormatter}
- />
- ) : (
- <BarColumn
- key={column[0]?.key ?? "column"}
- column={column}
- peak={peak}
- dateFormatter={dateFormatter}
- />
- ),
- )}
- </div>
+ {charted ? (
+ <WeekChart grid={grid} mode={mode} dateFormatter={dateFormatter} />
+ ) : (
+ <>
+ <div className="flex gap-[3px]">
+ {grid.map((column) =>
+ shaded ? (
+ <DayColumn
+ key={column[0]?.key ?? "column"}
+ column={column}
+ peak={peak}
+ dateFormatter={dateFormatter}
+ />
+ ) : (
+ <BarColumn
+ key={column[0]?.key ?? "column"}
+ column={column}
+ peak={peak}
+ dateFormatter={dateFormatter}
+ />
+ ),
+ )}
+ </div>
- <div className="relative mt-2 h-4">
- {monthLabels.map((label) => (
- <span
- key={label.key}
- className="absolute top-0 text-ui-11 text-muted-foreground"
- style={{ left: `${label.column * COLUMN_WIDTH}px` }}
- >
- {label.text}
- </span>
- ))}
- </div>
+ <div className="relative mt-2 h-4">
+ {monthLabels.map((label) => (
+ <span
+ key={label.key}
+ className="absolute top-0 text-ui-11 text-muted-foreground"
+ style={{ left: `${label.column * COLUMN_WIDTH}px` }}
+ >
+ {label.text}
+ </span>
+ ))}
+ </div>
+ </>
+ )}
</div>
</StatsCard>
);
diff --git a/studio/frontend/src/features/profile/stores/activity-chart-store.ts b/studio/frontend/src/features/profile/stores/activity-chart-store.ts
new file mode 100644
index 00000000000..85e53bdba57
--- /dev/null
+++ b/studio/frontend/src/features/profile/stores/activity-chart-store.ts
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import { create } from "zustand";
+import { persist } from "zustand/middleware";
+
+export const ACTIVITY_CHART_STORAGE_KEY = "unsloth_profile_activity_chart";
+
+interface ActivityChartState {
+ showChart: boolean;
+ setShowChart: (showChart: boolean) => void;
+}
+
+/** Opt-in: Weekly and Cumulative keep the block grid until the user picks Chart. */
+export const useActivityChartStore = create<ActivityChartState>()(
+ persist(
+ (set) => ({
+ showChart: false,
+ setShowChart: (showChart) => set({ showChart }),
+ }),
+ { name: ACTIVITY_CHART_STORAGE_KEY },
+ ),
+);
diff --git a/studio/frontend/src/features/profile/utils/stats-format.ts b/studio/frontend/src/features/profile/utils/stats-format.ts
index 91034ccc3c0..44ef42d9f5d 100644
--- a/studio/frontend/src/features/profile/utils/stats-format.ts
+++ b/studio/frontend/src/features/profile/utils/stats-format.ts
@@ -72,7 +72,8 @@ export function formatCompactNumber(value: number, locale: Locale): string {
// reads as false precision where the pre-localization code said 13. Asked of Intl (is there
// a `compact` part?) rather than a hardcoded 1000, because the first unit is per-locale:
// en and hi compact at 1K, ja and de not until 万 and Mio.
- if (!hasCompactUnit(locale, value)) return compactFormatter(locale, 0).format(value);
+ if (!hasCompactUnit(locale, value))
+ return compactFormatter(locale, 0).format(value);
return compactInteger(locale, value) < 100
? compactFormatter(locale, 1).format(value)
: compactFormatter(locale, 0).format(value);
@@ -378,6 +379,34 @@ export function activitySummaryForMode(
);
}
+export type WeekChartPoint = { week: string; tokens: number };
+
+/**
+ * One chart point per visible week, keyed by its first shown day. Weekly
+ * series carry the week total on every day and cumulative ones only grow, so
+ * the week's largest value is its total or its end-of-week running total.
+ */
+export function weekChartPoints(
+ grid: Array<Array<{ day: { date: string } | null; value: number }>>,
+): WeekChartPoint[] {
+ const points: WeekChartPoint[] = [];
+ for (const column of grid) {
+ let week: string | null = null;
+ let tokens = 0;
+ for (const cell of column) {
+ if (!cell.day) {
+ continue;
+ }
+ week ??= cell.day.date;
+ tokens = Math.max(tokens, cell.value);
+ }
+ if (week !== null) {
+ points.push({ week, tokens });
+ }
+ }
+ return points;
+}
+
export function seriesForMode(
daily: Array<{ date: string; tokens: number }>,
mode: ActivityMode,
diff --git a/studio/frontend/src/features/settings/tabs/general-tab.tsx b/studio/frontend/src/features/settings/tabs/general-tab.tsx
index 5e0b152f140..ca793c3fe55 100644
--- a/studio/frontend/src/features/settings/tabs/general-tab.tsx
+++ b/studio/frontend/src/features/settings/tabs/general-tab.tsx
@@ -164,6 +164,7 @@ const PREFS_KEYS: string[] = [
...TRAINING_UI_PREFERENCE_KEYS,
// Profile personalization
"unsloth_user_profile",
+ "unsloth_profile_activity_chart",
// Guided tour flags
"tour:studio:v1",
// Update notifications
diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.ts
index 778229896d4..1d0d7bfd7bf 100644
--- a/studio/frontend/src/i18n/locales/ar.ts
+++ b/studio/frontend/src/i18n/locales/ar.ts
@@ -2004,6 +2004,8 @@ export const ar = {
},
cellTooltip: "{date} · {tokens}، {messages}",
weekTooltip: "أسبوع {date} · {tokens}",
+ chartToggle: "مخطط",
+ chartToggleHint: "عرض الأسبوعي والتراكمي كمخطط بمحاور معنونة",
less: "أقل",
more: "أكثر",
insightsTitle: "تحليل النشاط",
diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.ts
index d92e60dcb55..90f1ee89d01 100644
--- a/studio/frontend/src/i18n/locales/de.ts
+++ b/studio/frontend/src/i18n/locales/de.ts
@@ -2031,6 +2031,8 @@ export const de = {
},
cellTooltip: "{date} · {tokens}, {messages}",
weekTooltip: "Woche vom {date} · {tokens}",
+ chartToggle: "Diagramm",
+ chartToggleHint: "Wöchentlich und Kumuliert als Diagramm mit beschrifteten Achsen anzeigen",
less: "Weniger",
more: "Mehr",
insightsTitle: "Aktivitätsauswertung",
diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.ts
index a48c12bbf50..86c4aa22d8e 100644
--- a/studio/frontend/src/i18n/locales/en.ts
+++ b/studio/frontend/src/i18n/locales/en.ts
@@ -2049,6 +2049,8 @@ export const en = {
},
cellTooltip: "{date} · {tokens}, {messages}",
weekTooltip: "Week of {date} · {tokens}",
+ chartToggle: "Chart",
+ chartToggleHint: "Show Weekly and Cumulative as a chart with labelled axes",
less: "Less",
more: "More",
insightsTitle: "Activity insights",
diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.ts
index 20fcdfdb8e1..94171dbf11e 100644
--- a/studio/frontend/src/i18n/locales/es.ts
+++ b/studio/frontend/src/i18n/locales/es.ts
@@ -2026,6 +2026,8 @@ export const es = {
},
cellTooltip: "{date} · {tokens}, {messages}",
weekTooltip: "Semana del {date} · {tokens}",
+ chartToggle: "Gráfico",
+ chartToggleHint: "Mostrar Semanal y Acumulada como gráfico con ejes etiquetados",
less: "Menos",
more: "Más",
insightsTitle: "Análisis de actividad",
diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.ts
index 90f176804dd..e2497591384 100644
--- a/studio/frontend/src/i18n/locales/fr.ts
+++ b/studio/frontend/src/i18n/locales/fr.ts
@@ -2030,6 +2030,8 @@ export const fr = {
},
cellTooltip: "{date} · {tokens}, {messages}",
weekTooltip: "Semaine du {date} · {tokens}",
+ chartToggle: "Graphique",
+ chartToggleHint: "Afficher Hebdomadaire et Cumulée sous forme de graphique avec axes légendés",
less: "Moins",
more: "Plus",
insightsTitle: "Analyse de l'activité",
diff --git a/studio/frontend/src/i18n/locales/he.ts b/studio/frontend/src/i18n/locales/he.ts
index fedad3f8a70..48ab8dc76cd 100644
--- a/studio/frontend/src/i18n/locales/he.ts
+++ b/studio/frontend/src/i18n/locales/he.ts
@@ -2087,6 +2087,8 @@ export const he = {
},
cellTooltip: "{date} · {tokens}, {messages}",
weekTooltip: "שבוע של {date} · {tokens}",
+ chartToggle: "תרשים",
+ chartToggleHint: "הצגת שבועי ומצטבר כתרשים עם צירים מסומנים",
less: "פחות",
more: "יותר",
insightsTitle: "תובנות פעילות",
diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.ts
index 7b6e7432008..03f1a8d42ca 100644
--- a/studio/frontend/src/i18n/locales/hi.ts
+++ b/studio/frontend/src/i18n/locales/hi.ts
@@ -2008,6 +2008,8 @@ export const hi = {
},
cellTooltip: "{date} · {tokens}, {messages}",
weekTooltip: "{date} वाला हफ़्ता · {tokens}",
+ chartToggle: "चार्ट",
+ chartToggleHint: "साप्ताहिक और संचयी को लेबल वाले अक्षों के साथ चार्ट के रूप में दिखाएँ",
less: "कम",
more: "ज़्यादा",
insightsTitle: "गतिविधि विश्लेषण",
diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.ts
index a4c31e9584c..2074631f921 100644
--- a/studio/frontend/src/i18n/locales/it.ts
+++ b/studio/frontend/src/i18n/locales/it.ts
@@ -1938,6 +1938,8 @@ export const it = {
},
cellTooltip: "{date} · {tokens}, {messages}",
weekTooltip: "Settimana del {date} · {tokens}",
+ chartToggle: "Grafico",
+ chartToggleHint: "Mostra Settimanale e Cumulativa come grafico con assi etichettati",
less: "Meno",
more: "Più",
insightsTitle: "Analisi dell'attività",
diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.ts
index b66bfbf8f72..7831ca21022 100644
--- a/studio/frontend/src/i18n/locales/ja.ts
+++ b/studio/frontend/src/i18n/locales/ja.ts
@@ -1985,6 +1985,8 @@ export const ja = {
},
cellTooltip: "{date} · {tokens}、{messages}",
weekTooltip: "{date} の週 · {tokens}",
+ chartToggle: "グラフ",
+ chartToggleHint: "週次と累計を軸ラベル付きのグラフで表示",
less: "少ない",
more: "多い",
insightsTitle: "アクティビティの分析",
diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.ts
index 4eb93c8319d..b13c04cc37c 100644
--- a/studio/frontend/src/i18n/locales/ko.ts
+++ b/studio/frontend/src/i18n/locales/ko.ts
@@ -2000,6 +2000,8 @@ export const ko = {
},
cellTooltip: "{date} · {tokens}, {messages}",
weekTooltip: "{date} 주간 · {tokens}",
+ chartToggle: "차트",
+ chartToggleHint: "주별 및 누적을 축 레이블이 있는 차트로 표시",
less: "적음",
more: "많음",
insightsTitle: "활동 분석",
diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.ts
index 182685dfa38..fea5524ade7 100644
--- a/studio/frontend/src/i18n/locales/pt-br.ts
+++ b/studio/frontend/src/i18n/locales/pt-br.ts
@@ -2018,6 +2018,8 @@ export const ptBR = {
},
cellTooltip: "{date} · {tokens}, {messages}",
weekTooltip: "Semana de {date} · {tokens}",
+ chartToggle: "Gráfico",
+ chartToggleHint: "Mostrar Semanal e Acumulada como gráfico com eixos rotulados",
less: "Menos",
more: "Mais",
insightsTitle: "Análise de atividade",
diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.ts
index 3c1972e8604..aff6d718c9c 100644
--- a/studio/frontend/src/i18n/locales/ru.ts
+++ b/studio/frontend/src/i18n/locales/ru.ts
@@ -2010,6 +2010,8 @@ export const ru = {
},
cellTooltip: "{date} · {tokens}, {messages}",
weekTooltip: "Неделя с {date} · {tokens}",
+ chartToggle: "График",
+ chartToggleHint: "Показывать режимы «По неделям» и «Накопительно» графиком с подписанными осями",
less: "Меньше",
more: "Больше",
insightsTitle: "Сводка по активности",
diff --git a/studio/frontend/src/i18n/locales/sv.ts b/studio/frontend/src/i18n/locales/sv.ts
index d1a86a5bf72..c0bfd1c4b95 100644
--- a/studio/frontend/src/i18n/locales/sv.ts
+++ b/studio/frontend/src/i18n/locales/sv.ts
@@ -2157,6 +2157,8 @@ export const sv = {
},
cellTooltip: "{date} · {tokens}, {messages}",
weekTooltip: "Veckan som börjar {date} · {tokens}",
+ chartToggle: "Diagram",
+ chartToggleHint: "Visa Veckovis och Kumulativt som ett diagram med märkta axlar",
less: "Mindre",
more: "Mer",
insightsTitle: "Aktivitetsinsikter",
diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.ts
index d159848fd32..c16cb6fd19e 100644
--- a/studio/frontend/src/i18n/locales/zh-CN.ts
+++ b/studio/frontend/src/i18n/locales/zh-CN.ts
@@ -1981,6 +1981,8 @@ export const zhCN = {
},
cellTooltip: "{date} · {tokens},{messages}",
weekTooltip: "{date} 当周 · {tokens}",
+ chartToggle: "图表",
+ chartToggleHint: "以带坐标轴标签的图表显示按周和累计",
less: "较少",
more: "较多",
insightsTitle: "活跃度分析",
diff --git a/studio/frontend/tests/profile-stats-format.test.ts b/studio/frontend/tests/profile-stats-format.test.ts
index 9ad47bd7792..d51609066ad 100644
--- a/studio/frontend/tests/profile-stats-format.test.ts
+++ b/studio/frontend/tests/profile-stats-format.test.ts
@@ -16,6 +16,7 @@ import {
heatLevel,
parseDayKey,
seriesForMode,
+ weekChartPoints,
windowBaseline,
} from "../src/features/profile/utils/stats-format.ts";
@@ -317,3 +318,50 @@ test("only cumulative rebases: daily and weekly are already per-window", () => {
assert.equal(windowBaseline(values, 2, "daily"), 0);
assert.equal(windowBaseline(values, 2, "weekly"), 0);
});
+
+test("week chart points carry the week total and the running total", () => {
+ // Monday 2026-09-07 through Wednesday 2026-09-16: one full week, one partial.
+ const daily = [
+ { date: "2026-09-07", tokens: 100 },
+ { date: "2026-09-08", tokens: 0 },
+ { date: "2026-09-09", tokens: 50 },
+ { date: "2026-09-10", tokens: 0 },
+ { date: "2026-09-11", tokens: 0 },
+ { date: "2026-09-12", tokens: 0 },
+ { date: "2026-09-13", tokens: 25 },
+ { date: "2026-09-14", tokens: 10 },
+ { date: "2026-09-15", tokens: 0 },
+ { date: "2026-09-16", tokens: 5 },
+ ];
+ const columns = (values: number[]) => [
+ daily.slice(0, 7).map((day, index) => ({ day, value: values[index] ?? 0 })),
+ [
+ ...daily
+ .slice(7)
+ .map((day, index) => ({ day, value: values[7 + index] ?? 0 })),
+ { day: null, value: 0 },
+ ],
+ ];
+ assert.deepEqual(weekChartPoints(columns(seriesForMode(daily, "weekly"))), [
+ { week: "2026-09-07", tokens: 175 },
+ { week: "2026-09-14", tokens: 15 },
+ ]);
+ assert.deepEqual(
+ weekChartPoints(columns(seriesForMode(daily, "cumulative"))),
+ [
+ { week: "2026-09-07", tokens: 175 },
+ { week: "2026-09-14", tokens: 190 },
+ ],
+ );
+ // Leading pad cells before the first shown day do not create a point.
+ assert.deepEqual(
+ weekChartPoints([
+ [
+ { day: null, value: 0 },
+ { day: { date: "2026-09-16" }, value: 7 },
+ ],
+ [{ day: null, value: 0 }],
+ ]),
+ [{ week: "2026-09-16", tokens: 7 }],
+ );
+});