nearestDomainValue
Import from @pibbl/core/viz. nearestDomainValue(values, rangeValue, scale) accepts
plain numeric values and a resolved linear scale. It returns the original value
whose mapped position is closest, or undefined for empty/all-invalid input.
Equal distances choose the earliest source value. No sorting or inversion is
needed, including for collapsed ranges. The query must be finite; invalid source
values are skipped and arithmetic overflow throws. This pure O(n) helper owns
no observers or persistent cache.
API details from source
Section titled “API details from source”
Finds the domain value nearest to a logical range coordinate; returns undefined for no candidate.
nearestDomainValue: (values: readonly number[], rangeValue: number, scale: ResolvedContinuousScale) => number | undefinedRelated API: nearestDomainValue, ResolvedContinuousScale.
Parameters
Section titled “Parameters”-
values— Candidate domain values. -
rangeValue— Pointer coordinate in the scale’s range. -
scale— Scale mapping candidates into range coordinates. See ResolvedContinuousScale.
Returns
Section titled “Returns”The nearest domain value, or undefined when no candidate can be selected.
See also
Section titled “See also”View source — packages/core/src/features/viz/lib/nearest.ts:69
Implementation guidance for agents
Section titled “Implementation guidance for agents”Read the Data visualization companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.
Complete minimal examples
Section titled “Complete minimal examples”- Nearest-point lookup: Locate the nearest observation in pixel and domain space. Plain source
Documentation version
Section titled “Documentation version”Documentation built with @pibbl/core 0.0.2, revision 380919b. ALPHA — NOT FOR PRODUCTION USE.