Dashboards and charts
Add your own dashboard cards, change the dashboards people start with, and use the five chart components anywhere in the app.
How dashboards work
The Dashboard page and the Overview tab of each customer and contract are grids of cards. The cards a dashboard can hold are listed in src/lib/data/dashboards.ts, and each one is drawn by DashboardCardView in src/components/home/dashboard-cards.tsx. The grid is 12 columns wide; a card's size is its width in columns and its height in rows.
| File | What it holds |
|---|---|
lib/data/dashboards.ts | CardType, CARDS (title, description, category, icon, the sizes people can pick and the default size) and DEFAULT_DASHBOARDS |
components/home/dashboard-cards.tsx | What each card shows, picked by type |
components/home/use-dashboards.ts | The dashboards people have, saved in the browser as accordion:dashboards |
components/home/panel.tsx | Panel, the frame every list and chart card uses (title, link, an action on the right) |
Add a card
Add a name to CardType and an entry to CARDS. For a single number, the metric() helper fills in the metric sizes; charts and lists list their sizes themselves.
Draw it: add a case to DashboardCardView that returns your card. Wrap it in Panel so it matches the others, and read records from a provider hook (such as useContracts()) so it follows changes people make.
Open Edit Cards › Add Card on the Dashboard: the new card is listed under its category. Drag its edges to try each size you offered.
Cards that a customer or contract Overview can hold are listed separately, in components/customers/customer-dashboard.tsx and components/contracts/contract-dashboard.tsx. They use the same grid.
Change the starting dashboards
DEFAULT_DASHBOARDS is what someone sees the first time: Overview, Revenue, Renewals, Pipeline and Relationships. Add, remove or reorder dashboards and their cards there.
Once someone changes a dashboard, their own copy is saved and the defaults no longer apply to them. They keep their cards when you add new ones; new cards reach them through Add Card, and the dashboard tab menu has Reset all dashboards to start again from your defaults. Cards whose type no longer exists are dropped when saved dashboards load, so removing a card type is safe.
With a backend, save dashboards per person in your database instead of the browser: use-dashboards.ts reads and writes them in one place.
The chart components
The charts in src/components/charts/ are hand-built in SVG with no chart library. Import them from @/components/charts.
| Component | Use it for |
|---|---|
LineChart | Values over time, one or more series, with an optional area wash and a crosshair tooltip |
Sparkline | A small trend line next to a number |
DonutChart | Parts of a whole, such as contracts by status |
FunnelChart | Steps that narrow, such as leads by stage |
StackedBarChart | Totals per month split by category |
RangeTabs | The 3, 6 and 12 month switch shown in a card's header |
Every chart takes a title, which screen readers announce along with a hidden table of the values. Hover or use the arrow keys to read each value. Charts size themselves to their container, and draw in without motion when reduced motion is on.
Chart colours
Series take their colours from --series-1 to --series-4 in src/app/globals.css, always in that order, with lighter or darker values in dark mode. With a theme colour other than Neutral, the first series follows the theme colour. Pass color on a series only when it means something, such as red for overdue.
Keep a chart to four series. For more categories, show the biggest three and put the rest under "Other", as the Pipeline by source card does.