path-rite

scaleLinearMap

Map a value from a continuous domain to a continuous range using linear interpolation.

scaleLinearMap(domainMin: number, domainMax: number, rangeMin: number, rangeMax: number, value: number): number

domainMin — Lower bound of the input domain.

domainMax — Upper bound of the input domain.

rangeMin — Lower bound of the output range.

rangeMax — Upper bound of the output range.

value — The domain value to map.

Returns — The corresponding range value. Values outside the domain are extrapolated (not clamped).

// Map data value 50 from domain [0, 100] to pixel range [0, 500]
const px = pathRite.scaleLinearMap(0, 100, 0, 500, 50);
// px === 250

// Temperature to color position
const pos = pathRite.scaleLinearMap(-20, 40, 0, 1, 15);
// pos === 0.5833...