Profitability map
NewEvery customer as a bubble of margin against revenue, sized by support hours, with the ones below 0% listed under it and a fix for each that moves their bubble when applied.
profitability-map/profitability-map.tsxCustomer profitability
38 customers · last 12 months
- Starter
- Growth
- Scale
- Enterprise
4 customers cost more than they pay
Tally suggests one fix for each
- Brightwater Studio−6%
- Larkspur Dental−22%
- Fig & Fern−31%
- Tidewell Coffee−12%
The live component, numbered part by part. Every measurement is read from it as it is drawn. Point at a row to outline its part, or at a part to find its row.
The choices it offers, each value drawn live and the default marked, with how to pick one.
When to use
- A book of a few dozen customers where the question is which ones pay their way: margin against revenue, with the cost of serving each as the bubble’s size.
- Finding the accounts below 0% and acting on them in the same place: a fix per customer, what the fixes add up to, and a way to apply them.
- Comparing two ways of slicing the same book, such as plan and industry, without redrawing the axes.
- A weekly or monthly review where a suggested action per row saves the reader from working out the fix on their own.
When not to use
- Hundreds of customers. The bubbles pile up and the arrow keys walk forever; use a table sorted by margin with a small histogram.
- Margin over time. The map is one period; use a line per segment or a cohort view to see a customer’s margin move.
- Fixes that need approval or negotiation. Apply changes the book at once; send those to a review queue or the account owner instead.
- Exact figures for finance. The bubbles place customers to the eye; export the numbers or use a table for reconciling.
- A single customer. Show its own page with revenue, costs and support history instead of one bubble on a map.
Reading the map
- Up is margin, right is revenue, size is support hours. A bubble’s area grows with the hours, so a big bubble low down is a customer that takes a lot of help for what it pays.
- The red zone is below 0%. Its customers cost more than they pay, and each wears a dotted red ring as well as sitting under the line.
- The dashed line is the median revenue, worked out from the book. Left of it is Keep lean, right of it Grow these.
- The axes start at −40% to 80% and $0 to $120k and widen in round steps when a customer falls outside, so a whole book always fits.
Suggested fixes
- Each fix comes from the cost model in
data.ts: cap support at 20 hours, move up a plan, add an onboarding fee under $20k a year, or review at renewal. What each adds is computed, never typed. - The suggestion is the fix that adds most margin. When renewal is two months away or less, it is a review instead, and that row starts unchecked.
- Apply changes the book at once and moves the bubbles, with Undo in a toast.
onApplygets each fix with what it adds a year: save them there. - Draft emails only calls
onDraftEmailswith the checked customers, and its toast says the drafts were requested, not written. Writing and sending the emails is yours.
Each one drawn with the component itself, used well or badly.
The component writes its own titles and totals from the book; the words you pass are the period and the assistant’s name.
- The period follows the count under the title (“38 customers · last 12 months”), so write it in lower case with no full stop.
- The assistant’s name is a proper noun, one or two words. It opens the second card’s subtitle and the empty state.
- Customer names show in the tooltip, the rows and the bubble labels: keep them as people know the account, not an ID.
- Margins and money come out formatted (
−22%,$54k) with a true minus sign. Pass revenue in thousands and margin in percent.
You can add this component with the shadcn CLI or by hand:
Into components/profitability-map of any React project, with no setup:
npx shadcn@latest add https://brunodelorence.com/r/profitability-map.json- Copy the component files
Copy these files into one folder of your project, keeping their relative imports together, or download them as a ZIP:
- Import it
As shown under Usage, below.
Either way it needs React 19 and a bundler that supports CSS Modules, such as Next.js or Vite. It has a dark colour scheme: it follows your page’s color-scheme, light unless the page sets one, or its colorScheme prop, with nothing to configure. Browsers without light-dark() show it light.
Usage
import { ProfitabilityMap } from './profitability-map';export function BookReview() { return ( <ProfitabilityMap assistant="Tally" period="last 12 months" onApply={(fixes) => console.log('Apply', fixes)} onDraftEmails={(customers) => console.log('Draft', customers)} autoplay={false} /> );}Each state below is a live instance, locked so you can study it.
The pieces it is built from, each with its measurements read live.
Below are variations of this component, each live, with its code.
Industry grouping
The same book coloured by industry: the same positions, four other colours and a legend of industries.
Healthy book
No customer below 0%: the red zone is empty and the second card says every customer pays its way, with the range of margins.
Scatter only
The map on its own for twenty customers over the last quarter, with its own median and two bubbles in the red zone.
Fixes applied
Opens just after Apply: three bubbles have climbed out of the red zone, the list keeps the one left for its renewal, and the toast offers Undo.
Two stacked cards for a review of the customer book. The first maps 38 customers: margin up the side, revenue along the bottom, support hours as the bubble’s size, a dashed line at the median revenue and a red zone below 0% where each bubble wears a dotted ring. Plan or Industry recolours the bubbles and the legend; hover, focus or the arrow keys show a tooltip. The second card lists the customers that cost more than they pay, each with the fix an assistant suggests: cap support, move up a plan, add an onboarding fee or review at renewal. The footer adds up what the checked fixes are worth from a small cost model; Apply moves their bubbles to their new margin, with Undo. A row and its bubble light together. Light and dark.
- The bubbles are buttons placed by left and top as shares of the axes, with a diameter from the square root of the support hours, so the area grows with the hours. Moving a customer is a change of those two numbers; a CSS transition carries the bubble there. The biggest are drawn first, so the small ones stay on top.
- The axes start at −40% to 80% and $0 to $120k and widen in round steps (40 points, $30k) when a customer falls outside. The median revenue is computed from the book and labelled on the axis, hiding the tick it would collide with.
- Plan / Industry is a radio group; it only swaps a data-tone on each bubble and legend key, whose colour comes from a token per group, so the colours cross-fade while the positions stay.
- The fixes are a small cost model in data.ts: a support hour costs $450, a plan one step up pays a set amount more, and accounts under $20k can take an onboarding fee. withFix returns the customer after a fix and gainOf the margin it adds, so the suggestion (the fix that adds most, or a review when renewal is a month or two away), the menu’s figures and the footer’s total are all computed.
- Apply replaces the fixed customers with their new selves: their bubbles climb out of the red zone (and right, when revenue rose), the list drops them, and a toast offers Undo, which restores the book as it was. A review stays in the list as booked.
- One hovered customer is shared by both cards: hovering or focusing a bubble lights its row, and a row lights its bubble and shows its tooltip, with the rest of the map faded.
- The stage is a container: under 560 px the switch spans the card, the middle revenue ticks drop and each fix picker moves under its name.
- While on screen and untouched, a demo pointer hovers two bubbles, switches to Industry and back, changes a fix, unchecks one and applies the rest. Any real input hands it over; it comes back after 9 s of quiet.
| Prop | Type | Default | Description |
|---|---|---|---|
customers | Customer[] | a book of 38 | The customers mapped: name, plan, industry, revenue (in thousands) and margin over the period, support hours, and months to renewal. |
assistant | string | 'Tally' | The assistant named as suggesting the fixes. |
period | string | 'last 12 months' | The period the figures cover, under the title. |
show | 'both' | 'scatter' | 'fixes' | 'both' | Both cards, or only the map or the fixes. |
defaultGroup | 'plan' | 'industry' | 'plan' | What colours the bubbles at first. |
onApply | (fixes: AppliedFix[]) => void | — | Called with each fix Apply makes: the customer, the fix and what it adds a year. |
onDraftEmails | (customers: Customer[]) => void | — | Called with the checked customers when Draft emails is pressed. |
defaultState | ProfitabilityMapState | — | Opens in a given moment, held still with no demo: the colouring, a hovered customer, changed or unchecked fixes, fixes applied, or a menu open. |
autoplay | boolean | true | While on screen and untouched, a demo pointer shows the main interactions. Any real input stops it. |
colorScheme | 'light' | 'dark' | 'system' | — | Light or dark colours, or the reader’s; without it, the page’s color-scheme. |
className | string | — | Classes for the stage. |
The map in words
- The plot is a group whose label sums it up: how many customers, how many below 0% and the median revenue. Each bubble is a button labelled with the customer, its group, revenue, margin and support hours, so no figure lives only in the picture (WCAG 1.1.1, A).
- The tooltip is hidden from screen readers, since the focused bubble’s label already says more.
Colour is never the only sign
Losing customers sit under the 0% line in a band labelled Costing you money, wear a dotted ring and show a minus sign in the list. Plan and industry colours are named in the legend and in every bubble’s label (WCAG 1.4.1, A).
Contrast
In both schemes every line of text, the axis figures included, holds 4.5:1 on its surface (WCAG 1.4.3, AA), and the bubble rings, the checkboxes and the focus ring hold 3:1 (WCAG 1.4.11, AA).
Keyboard
The bubbles take one tab stop. The arrows walk them by revenue, from the smallest account to the largest, Home and End jump to the ends and Escape hides the tooltip. Plan / Industry moves with the arrows; each fix picker and the ··· button open menus that move with the arrows, Home and End and close on Escape with focus back on their button.
Changes announced
The footer’s total is a polite live region, a change of colouring and Undo are announced, and Apply and Draft emails report in a status toast (WCAG 4.1.3, AA). The toast that carries Undo doesn’t time out, so Undo has no time limit (WCAG 2.2.1, Timing adjustable); Undo takes presses over at least 24 × 24 px (WCAG 2.5.8).
The demo
The demo pointer never plays under reduced motion. A hover or a wheel over the stage only pauses it; the reader’s first press, key or focus stops it for good, and it doesn’t start again on its own (WCAG 2.2.2, Pause, stop, hide).
In this build
- The map is a group whose label says what it shows in words: how many customers, how many below 0% and the median revenue. Each bubble is a button labelled with the customer, its group, revenue, margin and support hours.
- One bubble is in the tab order; the arrow keys walk the rest from left to right, Home and End jump to the ends, Escape hides the tooltip. The tooltip is aria-hidden, since the focused bubble says the same.
- Plan / Industry is a radio group moved with the arrow keys. The checkboxes are role="checkbox" buttons; each fix picker and the ··· button open menus that move with the arrows, Home and End, and close on Escape with the focus back on their button.
- The footer’s total is a polite live region, a change of colouring is announced, and Apply reports in a status toast with Undo.
- Under reduced motion the bubbles jump instead of gliding, nothing fades in, and the demo never plays. The demo pointer is decorative.
The complete source behind this demo. Open source under the MIT license, © 2026 Bruno Delorence: copy it, change it, ship it.
// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useEffect, useEffectEvent, useId, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent,} from 'react';import { CUSTOMERS, INDUSTRIES, INDUSTRY_NAME, PLANS, PLAN_NAME, fixLabel, fixesFor, gainOf,/* Profitability map (profitability-map.tsx): two stacked cards over a soft green backdrop, near-black by night and white on mint by day. The first card maps the customers as bubbles; the second lists the ones below 0% with a fix each and a footer that adds them up. The backdrop is gradients only: a few blurred greens over a deep base, and a fine grain of repeating gradients. Colours are the tokens below, light-dark(light, dark): the component takes the color-scheme it inherits from the page, or the one its colorScheme prop sets (data-color-scheme). Under 520 px of stage the fix rows fold the picker under the name. */.root { --base: light-dark(#e3efe6, #050806); --glow-1: light-dark(#bfe6cb, #0f5a2c); --glow-2: light-dark(#d6f0dc, #157a3a); --glow-3: light-dark(#a9d9b8, #0a3a1d); --card: light-dark(#ffffff, #141414); --card-edge: light-dark(rgb(16 40 24 / 0.08), rgb(255 255 255 / 0.07)); --well: light-dark(#f6f8f6, #191919); --well-edge: light-dark(#e8ece9, #232323); --line: light-dark(#e6eae7, #262626); --grid: light-dark(#eceeed, #232323); --ink: light-dark(#141815, #f0f0f0); --ink-2: light-dark(#5d655f, #a2a2a2); --ink-3: light-dark(#6c736d, #818181); --chip: light-dark(#eef1ef, #222222);// Copyright (c) 2026 Bruno Delorence. MIT License./* * The book the map draws: 38 customers of a small software company over the last twelve months, * each with its plan, its industry, what it paid, its margin and the support hours it took. Four * cost more than they pay. The numbers are seeded, so every load draws the same map. * * The fixes are a small cost model, so what a fix adds is computed, never typed: a support hour * costs HOUR_COST, a plan one step up pays PLAN_STEP more a year, and an onboarding fee is FEE. */export type Plan = 'starter' | 'growth' | 'scale' | 'enterprise';export type Industry = 'retail' | 'health' | 'hospitality' | 'services';export type Grouping = 'plan' | 'industry';export type FixId = 'cap' | 'upgrade' | 'fee' | 'review';export type Customer = { id: string; name: string; plan: Plan; industry: Industry; /** What it paid over the period, in thousands of dollars. */ revenue: number; /** Its margin over the period, in percent: below 0, it costs more than it pays. */// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent as ReactKeyboardEvent, type ReactNode,} from 'react';import { Icon } from './glyphs';import styles from './profitability-map.module.css';/* * The menus: the fix picker and the card's ··· menu. Placed on the stage under their trigger (over * it when there is no room below), in the stage's own px, since a gallery card may scale the * whole stage. The arrows, Home and End move between items; Escape closes and gives the focus * back; a press elsewhere closes. */const ITEMS = '[role="menuitem"], [role="menuitemradio"]';// Copyright (c) 2026 Bruno Delorence. MIT License./* * The line icons: a 24-unit box drawn with currentColor. The sparkle that marks a suggested fix * is filled. */const PATHS = { /** Dots over a baseline: the map's own tile. */ scatter: 'M4 19h16M7.5 14.5h.01M11 10.5h.01M15 13h.01M17.5 7.5h.01M9 16.5h.01', /** An arrow down into a tray: money leaving. */ leak: 'M12 4v10M8 10.5l4 4 4-4M4.5 15.5v3.5h15v-3.5', chevronDown: 'M7 10l5 5 5-5', more: 'M6 12h.01M12 12h.01M18 12h.01', check: 'M5 12.5l4.5 4.5L19 7.5', mail: 'M3.5 6.5h17v11h-17zM4 7l8 6 8-6', done: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM8 12.3l2.8 2.8L16.2 9.6', reset: 'M4.5 12a7.5 7.5 0 1 0 2.2-5.3M4.5 4.5v3.8h3.8', select: 'M5 12.5l4.5 4.5L19 7.5M5 5h14', clear: 'M6 6l12 12M18 6 6 18', download: 'M12 4v11M7.5 10.5 12 15l4.5-4.5M5 19.5h14',};export type IconName = keyof typeof PATHS;// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import type { CSSProperties, Ref } from 'react';/* * The demo's pointer, and the steps that move it. A demo is a script of awaited steps: wait, or * glide the pointer somewhere. Stopping the demo (the reader takes over, or it scrolls away) ends * the step in progress at once: its promise rejects, which ends the script right there, and the * pointer fades out. * * Each glide is a curved flight played by the Web Animations API, so nothing runs frame by frame. * The points of the flight are handed to whoever wants to move along with it. The arrow and the * hand are HTML boxes * that swap by their visibility: a change of style inside an SVG would lay the SVG out again. */export type Point = { x: number; y: number };/** A glide's path and timing, for an animation that plays along with it. */export type Flight = { points: Point[]; timing: KeyframeAnimationOptions };export type Demo = {// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useCallback, useEffect, useRef, useState } from 'react';/* * When a demo may play on its own: while part of it is on screen and the tab is visible, never * under reduced motion, and never again once the reader has used it. `take()` hands it to the * reader for good (until the component remounts), so it never starts again on its own (WCAG * 2.2.2). `hold()` only pauses it, for input that isn't a use (a hover, a wheel over it), and lets * it go on `idle` ms after the last one. */export function useAutoplay<T extends HTMLElement>(idle = 6000) { const ref = useRef<T>(null); const [visible, setVisible] = useState(false); const [reduced, setReduced] = useState(true); const [taken, setTaken] = useState(false); const [held, setHeld] = useState(false); const timer = useRef(0); useEffect(() => { const element = ref.current; if (!element) return;