Skip to main content
cngx-src documentation

createLinearScale

Functioncommon/chart/scales

projects/common/chart/scales/linear.ts

Description#

Pure-TS linear scale. Maps a numeric domain [d0, d1] to a numeric range [r0, r1] via standard linear interpolation. Domain may be inverted (d0 > d1) for SVG Y-axes where the top of the chart is the highest data value but the lowest pixel coordinate.

Values outside the domain extrapolate. Charts that need overflow clamping clamp at the data layer, not the scale.

Signature#

createLinearScale(domain, range)

Parameters#

@paramdomain

[start, end] data range. Equal endpoints collapse the scale to a constant function returning range[0].

@paramrange

[start, end] output range (typically pixel coordinates).

Returns#

number

(v: number) => number mapping domain values to range values.