Skip to content

RevenueWaterfall

Deferred balance recognizing by future period.
Implemented
Status
Implemented
Family
9 of 13
Registry
@lopifi/revenue-waterfall
npx shadcn@latest add @lopifi/theme @lopifi/revenue-waterfall

The component, rendering

Real data, the shipped component. Switch the theme to check the claims the spec makes below.

Preview

The four-layer spec

The deferred revenue balance recognizing by future period, by performance obligation. The number every SaaS board asks for. Bars, not a table, with the table equivalent behind DataTableToggle.

Lifted verbatim from Accounting core (GL). The doc and this page are the same paragraphs, so they cannot disagree.

What lands in your repository

One component is never one file. Everything below is copied into your project, where you own it.

Files

components/ledger/revenue-waterfall.tsx

Lopifi dependencies · 7
chart-primitiveschart-utilscnformat-moneymoneymoney.typestooltip
npm packages
@base-ui-components/reactclass-variance-authorityclsxtailwind-merge
Registry entry
/r/revenue-waterfall.json

The whole component

No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.

components/ledger/revenue-waterfall.tsx
"use client";
import { axisLabel, niceTicks, vizColorFor } from "@/lib/ledger/chart-utils";
import { DataTableToggle } from "@/components/ledger/chart-primitives";
import { Money } from "@/components/ledger/money";

export type RecognitionBucket = {
  period: string;
  /** Minor units, by performance obligation. */
  byObligation: Record<string, number>;
};

export interface RevenueWaterfallProps {
  buckets: RecognitionBucket[];
  className?: string;
  currency: string;
  obligations: string[];
}

/**
 * The deferred revenue balance recognizing by future period, by performance
 * obligation. The number every SaaS board asks for.
 */
export function RevenueWaterfall({ buckets, obligations, currency, className }: RevenueWaterfallProps) {
  const width = 720;
  const height = 280;
  const PAD = { bottom: 40, left: 72, right: 16, top: 16 };

  const totals = buckets.map((b) => obligations.reduce((s, o) => s + (b.byObligation[o] ?? 0), 0));
  const ticks = niceTicks(0, Math.max(...totals, 1));
  const max = ticks[ticks.length - 1];
  const plotW = width - PAD.left - PAD.right;
  const plotH = height - PAD.top - PAD.bottom;
  const y = (v: number) => PAD.top + plotH - (v / (max || 1)) * plotH;
  const slot = plotW / buckets.length;
  const barW = slot * 0.66;

  return (
    <DataTableToggle
      className={className}
      table={
        <table className="w-full text-body">
          <caption className="sr-only">Deferred revenue recognition schedule</caption>
          <thead>
            <tr className="border-b border-border-subtle">
              <th className="py-2 text-left text-label text-text-secondary" scope="col">
                Period
              </th>
              {obligations.map((o) => (
                <th className="py-2 text-right text-label text-text-secondary" key={o} scope="col">
                  {o}
                </th>
              ))}
              <th className="py-2 text-right text-label text-text-secondary" scope="col">
                Total
              </th>
            </tr>
          </thead>
          <tbody>
            {buckets.map((b, i) => (
              <tr className="border-b border-border-subtle" key={b.period}>
                <th className="py-2 text-left font-normal" scope="row">
                  {b.period}
                </th>
                {obligations.map((o) => (
                  <td className="py-2 text-right" key={o}>
                    <Money accounting value={{ amount: b.byObligation[o] ?? 0, currency }} />
                  </td>
                ))}
                <td className="py-2 text-right">
                  <Money accounting value={{ amount: totals[i], currency }} />
                </td>
              </tr>
            ))}
          </tbody>
        </table>
      }
    >
      <svg
        aria-label="Deferred revenue recognizing by future period"
        className="w-full"
        role="img"
        style={{ height }}
        viewBox={`0 0 ${width} ${height}`}
      >
        {ticks.map((t) => (
          <g key={t}>
            <line stroke="var(--border-subtle)" x1={PAD.left} x2={width - PAD.right} y1={y(t)} y2={y(t)} />
            <text
              className="numeric"
              fill="var(--text-tertiary)"
              fontSize="12"
              textAnchor="end"
              x={PAD.left - 8}
              y={y(t) + 4}
            >
              {axisLabel(t, currency)}
            </text>
          </g>
        ))}
        <line stroke="var(--border-strong)" x1={PAD.left} x2={width - PAD.right} y1={y(0)} y2={y(0)} />

        {buckets.map((b, i) => {
          const x = PAD.left + i * slot + (slot - barW) / 2;
          let cursor = 0;
          return (
            <g key={b.period}>
              {obligations.map((o) => {
                const v = b.byObligation[o] ?? 0;
                const top = y(cursor + v);
                const h = Math.max(0, y(cursor) - y(cursor + v));
                cursor += v;
                return <rect fill={vizColorFor(o)} height={h} key={o} width={barW} x={x} y={top} />;
              })}
              <text
                className="numeric"
                fill="var(--text-secondary)"
                fontSize="11"
                textAnchor="middle"
                x={x + barW / 2}
                y={y(totals[i]) - 6}
              >
                {axisLabel(totals[i], currency)}
              </text>
              <text
                className="numeric"
                fill="var(--text-tertiary)"
                fontSize="12"
                textAnchor="middle"
                x={x + barW / 2}
                y={height - 20}
              >
                {b.period}
              </text>
            </g>
          );
        })}
      </svg>
      <ul className="mt-3 flex flex-wrap gap-4">
        {obligations.map((o) => (
          <li className="flex items-center gap-2 text-caption" key={o}>
            <span
              aria-hidden="true"
              className="size-2.5 rounded-[2px]"
              style={{ background: vizColorFor(o) }}
            />
            {o}
          </li>
        ))}
      </ul>
    </DataTableToggle>
  );
}

The accounting it encodes

Concepts this component renders. Each one is defined once, in the lexicon, and used identically in the code and the copy.

Also in Accounting core (GL)

See also

A component is specified in one place, defined in another, and running in a third. All three, from here.

Elsewhere in the system

Where RevenueWaterfall sits in the rest of the system — the live section it renders in, the calculators that compute what it displays, and the ledger payloads it is fed from.

Components are copied into your repository and meant to be edited — rounding policy, fiscal calendar and compliance copy differ per company.

Told when Accounting core (GL) changes

Components are copied into your repo, so a fix here does not reach you on its own. One email when a component in this family changes in a way that needs a migration — and nothing when it does not.

One address, no list rental, unsubscribe in one click.

Works in your QuickBooks Online or Xero file

Get your books closed every month

Lopifi is building AI bookkeeping that keeps your books closed on US GAAP as transactions happen, with a CPA review every quarter, for $200 a month. We’re not open yet.

$200/month when we open. No card now.