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

    Function inferAccessor

    • Resolves a string accessor with optional fallback-key inference.

      Call AFTER queryD3Elements returns so the first datum can be sampled. When the user did NOT provide an explicit accessor (config[configKey] is undefined), and the canonical defaultKey is missing from the first datum, each name in alternatives is tried in order. The first alternative present on the datum is returned. If nothing matches, defaultKey is returned — which will trigger the helpful "Available properties: …" error inside resolveAccessor.

      When the user DID provide an accessor (string or function), it is returned verbatim — explicit user intent always wins.

      The config parameter is typed as object so each binder's typed config (e.g. D3BarConfig) can be passed directly without the as unknown as Record<string, unknown> double-cast at the call site. The narrowing to a string-keyed record is performed once, internally.

      Type Parameters

      • T

      Parameters

      • config: object

        The user's config object, looked up by configKey.

      • configKey: string

        The property name on config to check.

      • defaultKey: string

        Canonical key used when user is silent.

      • alternatives: string[]

        Alternative keys to try if defaultKey is missing.

      • firstDatum: unknown

        First D3-bound datum; used only when the user was silent and the default key is missing.

      Returns DataAccessor<T>

      A DataAccessor ready to pass to resolveAccessor.