CortexcnCortexcn
Pro

Spend Flow

Workload traffic converging on a meter that prices every call, then fanning out to a card of nested budgets, where each call rolls up to a service, its environment, and its project, and every level's spend counts up as a pulse reaches it.

Workload traffic through Meter to Cloud spendProject Atlas: $642.10 of $900. Environment Production: $271.35 of $300. Service Search API: $46.80 of $60.Workload traffic12,840 calls todayMeterPrices every call, checks budgets{ } Billing APICloud spendLiveSpentBudgetProjectAtlas$642.10$900EnvironmentProduction$271.35$300ServiceSearch API$46.80$60Each call counts at every level.Illustrative numbers

Installation

ProPart of Cortexcn Pro

The source for spend-flow comes with a Cortexcn Pro license, along with every other chart and the website templates. Pick a license on the pricing page.

Already have a license? Open the code

Usage

import { SpendFlow } from "@/components/spend-flow";
<SpendFlow
  title="Cloud spend"
  levels={[
    { kind: "Project", name: "Atlas", spent: 642.1, budget: 900 },
    { kind: "Environment", name: "Production", spent: 271.35, budget: 300 },
    { kind: "Service", name: "Search API", spent: 46.8, budget: 60 },
  ]}
/>

Each level is counted against the one above it, so the card steps in one level at a time and joins them with a tree line. Use it for cloud costs, an API that bills per call, or any product that meters usage against budgets at more than one level.

Examples

Over budget

A level that spends past its budget turns its marker, amount, and bar to the destructive color. While the flow is live, a level close to its limit can cross it as pulses arrive.

Workload traffic through Meter to Spend by projectProject Orion: $318.90 of $400. Service Image resize: $104.60 of $100, over budget.Workload traffic3,920 calls todayMeterPrices every call, checks budgets{ } Billing APISpend by projectLiveSpentBudgetProjectOrion$318.90$400ServiceImage resize$104.60$100Image resize is past its limit.Illustrative numbers

Static

With animated={false}, nothing moves and the numbers stay as given.

Workload traffic through Meter to Cloud spendProject Atlas: $642.10 of $900. Environment Production: $271.35 of $300. Service Search API: $46.80 of $60.Workload traffic12,840 calls todayMeterPrices every call, checks budgets{ } Billing APICloud spendLiveSpentBudgetProjectAtlas$642.10$900EnvironmentProduction$271.35$300ServiceSearch API$46.80$60Each call counts at every level.Illustrative numbers

Behavior

  • While the flow is on screen, pulses run from the left into the meter, then on to each level. The numbers count up from zero, then each level adds its perCall every time a pulse reaches it, and the call count under the source label goes up as pulses reach the meter.
  • Each bar has segments cells. The spent share fills from the left and brightens toward the newest spend.
  • With reduced motion enabled, or off screen, nothing moves and every number shows its given value.
  • The whole flow is one SVG that scales to its container. It lays out at minWidth or wider (560px by default); in a narrower container it scrolls sideways and takes keyboard focus so it can be scrolled from the keyboard.
  • Amounts are written with Intl.NumberFormat in locale and currency: what was spent to the cent, the budget in whole units.
  • Screen readers hear one summary: where the traffic goes, then each level's spend and budget, and which levels are over.
  • The caption in the corner says the numbers are illustrative. Change it when the flow shows real data.

Props

SpendFlow

PropTypeDefaultDescription
levelsSpendFlowLevel[]Three sample levelsThe levels one call is counted against, widest first
titlestring"Cloud spend"The card's title
gatewayNamestring"Meter"The name in the middle node
gatewayCaptionstring"Prices every call, checks budgets"A line under the middle node
sourceLabelstring"Workload traffic"The label over the incoming lines
callsnumber12840Calls counted so far, shown under the source label
callsLabelstring"calls today"The words after the call count
apiLabelstring"Billing API"The label on the lines into the card
notestring"Each call counts at every level."A note at the foot of the card
captionstring"Illustrative numbers"A small label in the bottom-left corner
currencystring"USD"An ISO 4217 code for the amounts
localestring"en-US"The locale numbers are written in
linesnumber22How many lines of traffic come in from the left
segmentsnumber24How many segments each budget bar has
accentstring"var(--foreground)"Color of the pulses, markers, and spent segments
animatedbooleantrueRun the pulses and count the numbers up while on screen
minWidthnumber560Narrowest layout width in pixels; below it, scroll
ariaLabelstring"Spend flow"Names the flow for screen readers
classNamestring-Extra classes on the frame

SpendFlowLevel

PropTypeDefaultDescription
kindstring-What the level is, such as "Environment"
namestring-Its name, such as "Production"
spentnumber-Spent so far, in currency
budgetnumber-The limit, in currency
perCallnumberA 400th of budgetAdded each time a pulse reaches the level while it is live