invert method
Given a value from the range
, returns the corresponding value from the
domain
.
Inversion is useful for interaction, say to determine the data value corresponding to the position of the mouse. For example, to invert a position encoding:
var x = ScaleLinear(
domain: [10, 130],
range: [0, 960],
interpolate: interpolate,
);
x(80); // 20
x(320); // 50
If the given value is outside the range, and clamp
ing is not enabled,
the mapping may be extrapolated such that the returned value is outside
the domain. This method is only supported if the range is numeric.
For a valid value y in the range, continuous(continuous.invert(y)) approximately equals y; similarly, for a valid value x in the domain, continuous.invert(continuous(x)) approximately equals x. The scale and its inverse may not be exact due to the limitations of floating point precision.
Implementation
X invert(num y) {
return _unnumberize(_clampf(_untransform((_input ??
(_input = _piecewise(
_range,
_domain.map((x) => _transform(_numberize(x))).toList(),
interpolateNumber)))(y))));
}