Customization/Dashboards and charts

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.

FileWhat it holds
lib/data/dashboards.tsCardType, CARDS (title, description, category, icon, the sizes people can pick and the default size) and DEFAULT_DASHBOARDS
components/home/dashboard-cards.tsxWhat each card shows, picked by type
components/home/use-dashboards.tsThe dashboards people have, saved in the browser as accordion:dashboards
components/home/panel.tsxPanel, 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.

src/lib/data/dashboards.ts
{
  type: "churn-trend",
  title: "Churned per month",
  description: "Contracts that ended without renewing, last 12 months.",
  category: "charts",
  icon: ChartLine,
  sizes: CHART_SIZES,
  defaultSize: { w: 6, h: 4 },
},

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.

src/components/home/dashboard-cards.tsx
case "churn-trend":
  return <ChurnTrendCard />

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.

ComponentUse it for
LineChartValues over time, one or more series, with an optional area wash and a crosshair tooltip
SparklineA small trend line next to a number
DonutChartParts of a whole, such as contracts by status
FunnelChartSteps that narrow, such as leads by stage
StackedBarChartTotals per month split by category
RangeTabsThe 3, 6 and 12 month switch shown in a card's header
A line chart
import { LineChart } from "@/components/charts"
import { lastMonths, monthLabel } from "@/lib/data/trends"

const keys = lastMonths(12)

<LineChart
  title="Collected per month, last 12 months"
  labels={keys.map(monthLabel)}
  series={[{ id: "collected", label: "Collected", values: collected }]}
  format={formatUsd}
/>

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.