call method
Given a value from the domain
, returns the corresponding value from the
range
.
If the given value is outside the domain, and clamp
ing is not enabled,
the mapping will be extrapolated such that the returned value is outside
the range. For example, to apply a position encoding:
var x = ScaleLinear(
domain: [10, 130],
range: [0, 960],
interpolate: interpolate,
);
x(20); // 80
x(50); // 320
Or to apply a color encoding:
var x = ScaleLinear(
domain: [10, 100],
range: ["brown", "steelblue"],
interpolate: interpolate,
);
x(20); // "#9a3439"
x(50); // "#7b5167"
Implementation
@override
Y? call(X? x) {
final num nx;
return x == null || (nx = _numberize(x)).isNaN
? _unknown
: (_output ??
(_output = _piecewise(
_domain.map((x) => _transform(_numberize(x))).toList(),
_range,
_interpolate)))(_transform(_clampf(nx)));
}