Skip to main content

Type Alias: LabelFormatSpec

LabelFormatSpec = { extended?: boolean; separator?: string; type: "range"; unit?: string; } | { abbreviate?: boolean; extended?: boolean; type: "count"; } | { decimals?: number; denominator?: number; extended?: boolean; type: "percentage"; } | { extended?: boolean; type: "stdDev"; unit?: "σ" | "sd"; } | { extended?: boolean; formatter: (lower, upper, index) => string; type: "custom"; } | { extended?: boolean; labels: string[]; type: "labels"; }

Defined in: spec/types.legend.ts:92

Controls how quantitative legend bin labels are formatted.

  • 'range' – raw break values joined by a configurable separator. Example: 50k – 100k.
  • 'count' – compact integer counts with optional SI abbreviation. Example: < 50k, 50k ≤ 100k, > 250k.
  • 'percentage' – percentage display for values already in the [0, 1] range. Example: 0% – 10%.
  • 'stdDev' – standard deviation labels for diverging schemes. Example: < −2σ, −1σ – +1σ, > +2σ.
  • 'custom' – escape hatch; caller supplies a formatter function.

All variants support an optional extended flag. When true, a semantic suffix derived from the legend's normalization metadata is appended to each label (e.g. unit, ratio, rate description).

Union Members

Type Literal

{ extended?: boolean; separator?: string; type: "range"; unit?: string; }


Type Literal

{ abbreviate?: boolean; extended?: boolean; type: "count"; }


Type Literal

{ decimals?: number; denominator?: number; extended?: boolean; type: "percentage"; }


Type Literal

{ extended?: boolean; type: "stdDev"; unit?: "σ" | "sd"; }


Type Literal

{ extended?: boolean; formatter: (lower, upper, index) => string; type: "custom"; }

extended?

optional extended?: boolean

formatter

formatter: (lower, upper, index) => string

Custom formatter function. Receives the lower and upper bounds (null for open-ended bins) and the zero-based bin index. Not serialisable to JSON — use this only in TypeScript-driven specs.

Parameters
ParameterType
lowernumber | null
uppernumber | null
indexnumber
Returns

string

type

type: "custom"


Type Literal

{ extended?: boolean; labels: string[]; type: "labels"; }

extended?

optional extended?: boolean

labels

labels: string[]

Ordered list of explicit labels, one entry per legend bin.

type

type: "labels"

Explicit label list. Each entry maps to the bin at the same position (zero-based). Bins without a corresponding entry fall back to the default range-style formatting (< N, N - M, > N).

This variant is JSON-serialisable and is the recommended choice when the label text is known ahead of time (e.g. classification categories such as 'Low', 'Medium', 'High'). Prefer 'custom' only when runtime computation is needed.