Cohort grid
Retention by cohort, with a linked retention curve, each period's trend in its heading, shading against the average, and full keyboard reading.
| period | Average | Cohort |
|---|---|---|
| Week 0 | 100% | |
| Week 1 | 67% | |
| Week 2 | 48% | |
| Week 3 | 38% | |
| Week 4 | 33% | |
| Week 5 | 29% | |
| Week 6 | 28% | |
| Week 7 | 27% | |
| Week 8 | 27% |
Installation
npx shadcn@latest add @quireui-pro/cohort-gridPart of Pro. Add the Pro registry with your token once, as shown in Installation, and the CLI brings in the free parts it builds on as well.
Usage
<CohortGrid
label="Weekly retention"
cohorts={[
{ label: "Oct 27", size: 1612, values: [1612, 905, 701] },
{ label: "Nov 3", size: 1655, values: [1655, 512, null] },
]}
/>Each row is a cohort, a group of people who started together, with how many started. Each column is a period since they started, period 0 first, and each cell how many were still active in it, as a share of the cohort. null is a period not reached yet. How "still active" is counted, on that period or on or after it, by calendar week or rolling, is up to your data; the grid shows what you give it.
The newest period of each cohort is still being counted, so it wears stripes, reads "so far", and is left out of the averages and trends; partial={false} turns that off. A cohort's own partial overrides it, for cohorts whose periods run past the ones shown, whose last shown period is long finished.
The curve and the trends
The curve above the grid is the average retention, period by period. Point at a cell, or arrow to it, and that cohort's curve joins it, so a cohort that holds on better or worse shows at once. curve={false} leaves it out.
The small line in each period's heading is that period across cohorts, oldest to newest: if week 4 rises from left to right, later cohorts are staying longer. In the example, the cohorts from Sep 29 on, when onboarding changed, keep a few points more at every week. It turns green or red by where it ended against where it started; trends={false} leaves it out.
Averages
The average row is weighted by cohort size by default, so a small cohort does not swing it, and counts finished periods only. average="simple" takes a plain mean, and average={false} leaves the row out.
Shading
By default every cell is shaded against the whole grid, from light to dark. scale="row" shades each cohort against itself, to compare a cohort's own drop-off, and scale="average" shades each cell above or below the average row in two colours, with grey at the average, so the cohorts that did better or worse stand out.
Counts and choosing a cell
The switch over the grid shows shares or counts; show and defaultShow set it yourself. onPick is called with a cohort's label and a period's index when a cell is clicked or chosen with Enter, so your app can list who stayed.
Click a cell, or press Enter on one, to list who stayed.
Many periods
The cohort and size columns stay in place while the periods scroll sideways, with a slim scroll bar that shows on hover. Put the grid on something other than the surface and set --cohort-bg to match, so the fixed columns keep its colour.
Loading
Accessibility
The grid is one tab stop. The arrow keys move between cells and screen readers read each one in full, like "Oct 6, Week 3: 41%, 663 of 1,615 users", with "so far" on a period still being counted. Its headings are real column and row headings, and every share is written in its cell, so nothing is told by shade alone.
| Key | Action |
|---|---|
| ← / → | Previous or next period |
| ↑ / ↓ | Previous or next cohort |
| Home / End | First or latest period of the cohort |
| Enter | With onPick: chooses the cell |
| Esc | Leaves the cell |
Motion
The rows arrive one after another, once, when the grid first scrolls into view, and each cell's shade eases when the numbers or the scale change. Reading a cell follows the pointer and the keys without easing.
Cohort grid or something else?
- How many reach each step once, rather than how many come back: a Funnel.
- One retention number with its trend: a Stat card.
API reference
CohortGrid
Retention by cohort: a row per group that started together, a column per period since, each cell the share still active. With a curve above it, each period's trend in its heading, and arrow keys.
Prop
Type
Also takes every <figure> attribute. Style it with [data-slot="cohort-grid"].
Funnelnew
How many make it through each step, as one shape that narrows like a funnel. Each step sits flat at its true size, with its share and the drop beside it, and can split into bands like mobile and desktop.
Waterfallpro
How an amount got from one figure to another, like MRR. Totals are worked out for you, every change says its share of the start, and the period before shows as outlines.