Skip to content

nearestDomainValue

Read as Markdown

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.

Finds the domain value nearest to a logical range coordinate; returns undefined for no candidate.

nearestDomainValue: (values: readonly number[], rangeValue: number, scale: ResolvedContinuousScale) => number | undefined

Related API: nearestDomainValue, ResolvedContinuousScale.

  • values — Candidate domain values.

  • rangeValue — Pointer coordinate in the scale’s range.

  • scale — Scale mapping candidates into range coordinates. See ResolvedContinuousScale.

The nearest domain value, or undefined when no candidate can be selected.

ResolvedContinuousScale

View source — packages/core/src/features/viz/lib/nearest.ts:69

Read the Data visualization companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.

Documentation built with @pibbl/core 0.0.2, revision 2dccb19. ALPHA — NOT FOR PRODUCTION USE.