-
-
-
{error && (
{error}
@@ -306,31 +322,51 @@ export function AdaptiveDashboard({
}
const styles = stylex.create({
- toolbar: {
- marginBottom: 24,
- paddingBottom: 16,
- borderBottomWidth: 1,
- borderBottomStyle: "solid",
- borderBottomColor: colors.border,
+ toolbar: { marginBottom: 22 },
+ controls: {
+ display: "flex",
+ alignItems: "center",
+ flexWrap: "wrap",
+ gap: 8,
},
- controls: { display: "flex", alignItems: "center", flexWrap: "wrap", gap: 8 },
- label: { color: colors.muted, fontSize: 12 },
- select: {
- fontFamily: "inherit",
+ pills: { display: "flex", flexWrap: "wrap", gap: 6 },
+ pill: {
+ font: "inherit",
fontSize: 13,
- color: colors.foreground,
- backgroundColor: colors.surface,
+ minHeight: { default: 32, "@media (max-width: 700px)": 40 },
+ paddingInline: 14,
+ borderRadius: radii.full,
borderWidth: 1,
borderStyle: "solid",
borderColor: colors.border,
- borderRadius: 6,
- paddingInline: 10,
- minHeight: { default: 32, "@media (max-width: 700px)": 44 },
- maxWidth: "100%",
- outlineOffset: 3,
+ backgroundColor: {
+ default: colors.background,
+ "@media (hover: hover)": { ":not(:disabled):hover": colors.bubble },
+ },
+ color: colors.foreground,
+ cursor: { default: "pointer", ":disabled": "default" },
+ outlineOffset: 2,
+ },
+ pillOn: {
+ borderColor: colors.action,
+ backgroundColor: {
+ default: colors.action,
+ "@media (hover: hover)": { ":not(:disabled):hover": colors.action },
+ },
+ color: colors.onAccent,
+ },
+ describe: {
+ borderStyle: "dashed",
+ borderColor: colors.faint,
+ backgroundColor: {
+ default: "transparent",
+ "@media (hover: hover)": { ":not(:disabled):hover": colors.bubble },
+ },
+ color: colors.muted,
},
+ spacer: { flex: 1 },
status: { fontSize: 12, color: colors.muted },
- form: { marginTop: 16, maxWidth: 580 },
+ form: { flexBasis: "100%", order: 2, marginTop: 8, maxWidth: 580 },
intentLabel: {
display: "block",
fontSize: 13,
@@ -361,7 +397,9 @@ const styles = stylex.create({
color: colors.onAccent,
},
intent: {
- marginTop: 12,
+ flexBasis: "100%",
+ order: 2,
+ marginTop: 4,
marginBottom: 0,
fontSize: 12,
color: colors.muted,
@@ -373,10 +411,10 @@ const styles = stylex.create({
color: colors.muted,
marginBlock: 12,
},
+ // Each widget is a full-width section; its blocks form the tile grid.
grid: {
- display: "grid",
- gridTemplateColumns: "repeat(auto-fit, minmax(min(100%, 340px), 1fr))",
- gap: 20,
- alignItems: "start",
+ display: "flex",
+ flexDirection: "column",
+ gap: 40,
},
});
diff --git a/apps/web/src/components/create-tracker.tsx b/apps/web/src/components/create-tracker.tsx
index 8952da2..5111264 100644
--- a/apps/web/src/components/create-tracker.tsx
+++ b/apps/web/src/components/create-tracker.tsx
@@ -30,11 +30,13 @@ export function CreateTracker({
return (
setOpen(!open)}
disabled={saving || !hydrated}
>
- Add tracker
+ + Add tracker
{open && (
@@ -79,8 +69,46 @@ export function DashboardChart({
);
}
+function DatasetSvgChart({
+ chart,
+ style,
+ dataset,
+ width,
+}: {
+ chart: DatasetChart;
+ style: "line" | "area" | "bar" | "stacked-bar";
+ dataset: DashboardDataset;
+ width: number;
+}) {
+ const x = dataset.columns.findIndex((column) => column.key === chart.x);
+ const rows =
+ dataset.columns[x]?.type === "number"
+ ? [...dataset.rows].sort((a, b) => Number(a[x]) - Number(b[x]))
+ : dataset.rows;
+ return (
+
String(row[x]))}
+ series={chart.series.map((series) => {
+ const index = dataset.columns.findIndex(
+ (column) => column.key === series.column,
+ );
+ return {
+ label: series.label,
+ values: rows.map((row) =>
+ typeof row[index] === "number" ? row[index] : null,
+ ),
+ };
+ })}
+ />
+ );
+}
+
const styles = stylex.create({
figure: { margin: 0, minWidth: 0 },
- title: { fontSize: 13, fontWeight: 500, marginBottom: 12 },
+ title: { fontSize: 15, fontWeight: 600, marginBottom: 14 },
container: { width: "100%", minWidth: 0, overflowX: "auto" },
});
diff --git a/apps/web/src/components/dashboard-data.tsx b/apps/web/src/components/dashboard-data.tsx
index 9706481..826bd9e 100644
--- a/apps/web/src/components/dashboard-data.tsx
+++ b/apps/web/src/components/dashboard-data.tsx
@@ -104,7 +104,7 @@ const styles = stylex.create({
borderColor: colors.border,
borderRadius: 12,
padding: 16,
- marginBottom: 20,
+ marginTop: 32,
fontSize: 12,
backgroundColor: colors.surface,
},
diff --git a/apps/web/src/components/dashboard-svg-chart.tsx b/apps/web/src/components/dashboard-svg-chart.tsx
new file mode 100644
index 0000000..3071b04
--- /dev/null
+++ b/apps/web/src/components/dashboard-svg-chart.tsx
@@ -0,0 +1,409 @@
+// biome-ignore-all lint/suspicious/noArrayIndexKey: Chart marks are positional and never reordered.
+import * as stylex from "@stylexjs/stylex";
+import { type RefObject, useEffect, useRef, useState } from "react";
+import { colors, fonts } from "../styles/tokens.stylex";
+
+export type ChartSeries = {
+ label: string;
+ values: readonly (number | null)[];
+};
+
+export type ChartGoal = { min: number; max?: number; label?: string };
+
+// Theme-derived so every preset and manual light/dark mode stays legible.
+export const seriesColors = [
+ colors.accent,
+ colors.review,
+ colors.action,
+ colors.muted,
+];
+
+/** Tracks an element's content width so SVG charts draw at true pixel size. */
+export function useElementWidth(): [
+ RefObject,
+ number,
+] {
+ const element = useRef(null);
+ const [width, setWidth] = useState(0);
+ useEffect(() => {
+ const current = element.current;
+ if (!current) return;
+ const observer = new ResizeObserver((entries) =>
+ setWidth(Math.floor(entries[0]?.contentRect.width ?? 0)),
+ );
+ observer.observe(current);
+ return () => observer.disconnect();
+ }, []);
+ return [element, width];
+}
+
+const HEIGHT = 200;
+const TOP = 14;
+const BOTTOM = 26;
+const LEFT = 40;
+const RIGHT = 8;
+
+const compact = new Intl.NumberFormat("en", {
+ notation: "compact",
+ maximumFractionDigits: 1,
+});
+const full = new Intl.NumberFormat("en", { maximumFractionDigits: 2 });
+
+function niceStep(range: number, count: number) {
+ const raw = range / count;
+ const power = 10 ** Math.floor(Math.log10(raw));
+ const fraction = raw / power;
+ return (
+ (fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10) * power
+ );
+}
+
+/** Shortens ISO dates such as 2026-11-18 to "Nov 18"; other labels pass through. */
+export function axisLabel(label: string) {
+ const date = /^(\d{4})-(\d{2})-(\d{2})$/.exec(label);
+ if (date) {
+ const value = new Date(
+ Date.UTC(Number(date[1]), Number(date[2]) - 1, Number(date[3])),
+ );
+ return value.toLocaleDateString("en", {
+ month: "short",
+ day: "numeric",
+ timeZone: "UTC",
+ });
+ }
+ return label.length > 14 ? `${label.slice(0, 13)}…` : label;
+}
+
+// Every `every`th label, plus the last one when it will not crowd its neighbour.
+function showLabel(index: number, count: number, every: number) {
+ if (index % every === 0)
+ return count - 1 - index >= every || index === count - 1 || every === 1;
+ return index === count - 1;
+}
+
+export function SvgChart({
+ title,
+ labels,
+ series,
+ style,
+ goal,
+ width,
+}: {
+ title: string;
+ labels: readonly string[];
+ series: readonly ChartSeries[];
+ style: "line" | "area" | "bar" | "stacked-bar";
+ goal?: ChartGoal;
+ width: number;
+}) {
+ const stacked = style === "stacked-bar";
+ const totals = labels.map((_, index) =>
+ series.reduce((sum, item) => sum + (item.values[index] ?? 0), 0),
+ );
+ const values = [
+ ...(stacked
+ ? totals
+ : series.flatMap((item) =>
+ item.values.filter((value) => value !== null),
+ )),
+ ...(goal ? [goal.min, goal.max ?? goal.min] : []),
+ ];
+ const step = niceStep(
+ Math.max(...values, 0) - Math.min(...values, 0) || 1,
+ 3,
+ );
+ const min = Math.floor(Math.min(0, ...values) / step) * step;
+ const max = Math.ceil(Math.max(0, ...values) / step) * step || step;
+ const ticks: number[] = [];
+ for (let tick = min; tick <= max + step / 2; tick += step) ticks.push(tick);
+ const plotWidth = Math.max(120, width - LEFT - RIGHT);
+ const plotHeight = HEIGHT - TOP - BOTTOM;
+ const y = (value: number) =>
+ TOP + plotHeight - ((value - min) / (max - min)) * plotHeight;
+ const band = plotWidth / Math.max(1, labels.length);
+ const center = (index: number) =>
+ style === "line" || style === "area"
+ ? labels.length === 1
+ ? LEFT + plotWidth / 2
+ : LEFT + (index / (labels.length - 1)) * plotWidth
+ : LEFT + band * index + band / 2;
+ const labelCount = Math.max(2, Math.floor(plotWidth / 72));
+ const every = Math.max(1, Math.ceil(labels.length / labelCount));
+ const zero = y(Math.max(min, Math.min(0, max)));
+ const groups = stacked ? 1 : series.length;
+ const barWidth = Math.max(
+ 2,
+ Math.min(28, (band * 0.72) / groups - (groups > 1 ? 2 : 0)),
+ );
+ const missing = labels.map((_, index) =>
+ series.every((item) => item.values[index] === null),
+ );
+ const description = `${title}. ${labels
+ .map(
+ (label, index) =>
+ `${label}: ${series
+ .map(
+ (item) =>
+ `${series.length > 1 ? `${item.label} ` : ""}${
+ item.values[index] === null
+ ? "not recorded"
+ : full.format(item.values[index] ?? 0)
+ }`,
+ )
+ .join(", ")}`,
+ )
+ .join("; ")}${
+ goal
+ ? `. Goal ${full.format(goal.min)}${goal.max === undefined ? "" : `–${full.format(goal.max)}`}`
+ : ""
+ }`;
+
+ return (
+
+ {(series.length > 1 || goal || missing.some(Boolean)) && (
+
+ {series.length > 1 &&
+ series.map((item, index) => (
+ -
+
+ {item.label}
+
+ ))}
+ {goal && (
+ -
+
+ {goal.label ?? "Goal"}
+
+ )}
+ {missing.some(Boolean) && (
+ -
+
+ Not recorded
+
+ )}
+
+ )}
+
+
+ );
+}
+
+const styles = stylex.create({
+ svg: { display: "block", overflow: "visible", maxWidth: "100%" },
+ tick: {
+ fill: colors.muted,
+ fontSize: 11,
+ fontFamily: fonts.sans,
+ fontVariantNumeric: "tabular-nums",
+ },
+ legend: {
+ listStyle: "none",
+ margin: 0,
+ marginBottom: 10,
+ padding: 0,
+ display: "flex",
+ flexWrap: "wrap",
+ gap: "4px 14px",
+ fontSize: 12,
+ color: colors.muted,
+ },
+ legendItem: { display: "inline-flex", alignItems: "center", gap: 6 },
+ swatch: { width: 10, height: 10, borderRadius: 3, flexShrink: 0 },
+ goalSwatch: {
+ backgroundColor: `color-mix(in srgb, ${colors.review} 28%, transparent)`,
+ },
+ missingSwatch: {
+ borderWidth: 1.5,
+ borderStyle: "dashed",
+ borderColor: colors.faint,
+ boxSizing: "border-box",
+ },
+ goalBand: {
+ fill: `color-mix(in srgb, ${colors.review} 20%, transparent)`,
+ },
+ goalLine: { stroke: colors.review },
+ missing: {
+ fill: "none",
+ stroke: colors.faint,
+ strokeWidth: 1.5,
+ strokeDasharray: "3 3",
+ },
+});
diff --git a/apps/web/src/components/dashboard-widget.tsx b/apps/web/src/components/dashboard-widget.tsx
index fd827ba..3c56c91 100644
--- a/apps/web/src/components/dashboard-widget.tsx
+++ b/apps/web/src/components/dashboard-widget.tsx
@@ -1,127 +1,385 @@
// biome-ignore-all lint/suspicious/noArrayIndexKey: Read-only report snapshots allow duplicate labels and cells, with no editable row state to preserve.
import * as stylex from "@stylexjs/stylex";
import { Link } from "@tanstack/react-router";
+import { type ReactNode, useEffect, useRef, useState } from "react";
import type {
DashboardBlock,
DashboardDataset,
DashboardWidget as Widget,
} from "../features/dashboards/schema";
-import { colors } from "../styles/tokens.stylex";
+import { colors, radii } from "../styles/tokens.stylex";
import { MessageContent } from "./conversation/message-content";
import { DashboardChart } from "./dashboard-chart";
+import { SvgChart, seriesColors, useElementWidth } from "./dashboard-svg-chart";
import { DashboardTracker } from "./dashboard-tracker";
import { DashboardWeather } from "./dashboard-weather";
+import { Badge } from "./ui/badge";
import { Button } from "./ui/button";
+import { cardStyles } from "./ui/card";
+
+type Tone = "neutral" | "positive" | "attention";
+type Metric = Extract["items"][number];
+type StatusItem = Extract<
+ DashboardBlock,
+ { type: "item-status" }
+>["items"][number];
+
+const TABLE_PREVIEW_ROWS = 6;
function Chart({
block,
}: {
block: Extract;
}) {
- const min = Math.min(0, ...block.points.map((point) => point.value));
- const max = Math.max(0, ...block.points.map((point) => point.value));
- const range = max - min || 1;
- const y = (value: number) => 150 - ((value - min) / range) * 130;
-
- const x = (index: number) =>
- block.points.length === 1
- ? 230
- : 50 + (index / (block.points.length - 1)) * 380;
- const width = Math.min(30, 340 / block.points.length);
- const axisLabel = (label: string) =>
- label.length > 20 ? `${label.slice(0, 19)}…` : label;
+ const [container, width] = useElementWidth();
return (
-
- {block.title}
-
-
+ );
+}
+
+function Sparkline({ values }: { values: readonly (number | null)[] }) {
+ const numbers = values.filter((value) => value !== null);
+ const min = Math.min(...numbers);
+ const range = Math.max(...numbers) - min || 1;
+ const segments: string[][] = [[]];
+ values.forEach((value, index) => {
+ if (value === null) segments.push([]);
+ else
+ segments
+ .at(-1)
+ ?.push(
+ `${(index / (values.length - 1)) * 100},${26 - ((value - min) / range) * 24}`,
+ );
+ });
+ return (
+