MAIDR Documentation - v3.65.0
    Preparing search index...

    Function resolveAccessor

    • Resolves a DataAccessor to extract a value from a datum.

      Two accessor shapes are supported:

      1. Function accessor — invoked with (datum, index) and the return value is used verbatim. The function may return any value, including falsy values (0, '', false, null); these are preserved and returned unchanged. Function accessors are NOT validated — if they throw, the error propagates to the binder.

      2. String accessor — treated as a property key on datum. Presence is checked with the in operator (NOT a truthiness/!= null check), so properties whose value is 0, '', false, or null are still considered "found" and returned as-is. Only an actually-missing property triggers the helpful "Available properties: …" error.

      The returned value is asserted to be of type T without runtime verification — callers that expect a specific shape (e.g. number) should either pass a typed function accessor or validate the result themselves.

      Use resolveAccessorOptional when an absent property should resolve to undefined instead of throwing (e.g. optional fill, outlier arrays).

      Type Parameters

      • T

      Parameters

      • datum: unknown

        The data object bound to a D3 element. Must be an object when accessor is a string; passing null or undefined will produce a non-actionable runtime error from the property lookup. Validate beforehand with the === undefined || === null guard used by the binders.

      • accessor: DataAccessor<T>

        Property key or function to extract the value.

      • index: number

        The index of the element in its selection. Forwarded to function accessors and surfaced in the missing-property error to help locate the offending datum.

      Returns T

      The extracted value of type T.

      Error if the string accessor references a property not present on the datum (using in-operator semantics, NOT truthiness).