Skip to main content
cngx-src documentation

createOrdinalScale

Functioncommon/chart/scales

projects/common/chart/scales/ordinal.ts

Description#

Pure-TS ordinal scale. Maps a discrete categorical domain to a cycling palette of values (typically colours). When the domain is longer than the palette, mappings wrap modulo palette length.

Signature#

createOrdinalScale(domain, colors)

Parameters#

@paramdomain

Ordered list of categorical values. Values are matched by reference equality on lookup.

@paramcolors

Palette to cycle through. Must have at least one entry; an empty palette throws synchronously at construction time.

Returns#

string

Callable (v: T) => string returning the palette entry for v. Lookup of an unknown value returns the palette's first entry.