/** Dim-dropdown and range-slider event wiring for the deck.gl scene controller. @example ```ts wireDimDropdowns({ session, probes, commit }); wireRanges({ session, commit }); ``` */ import { computeSceneBounds, } from '../deck-config.ts'; import type { PackageProbe, } from '../probe.ts'; import { elInput, elSelect, } from './controller-dom.ts'; import { CHANNEL_KEYS, DIM_KEYS, } from './controller-event-constants.ts'; import type { Commit, Session, } from './controller-event-types.ts'; import { type DataDimKey, DIM_UNKNOWN, extractDim, } from './filter.ts'; //region Helpers /** Computes inclusive `[min, max]` extent across probes for one data dim, skipping unknowns. @param probes - Source probes. @param dim - Dim whose extent to compute. @returns Inclusive `[min, max]` bounds, or `[0, 0]` if no probe has known value. @example ```ts const extent = computeRangeExtent({ probes, dim: 'logDownloads' }); ``` */ function computeRangeExtent( { probes, dim, }: { readonly probes: readonly PackageProbe[]; readonly dim: DataDimKey; }, ): readonly [ number, number, ] { /** Known non-null values for `dim` across `probes`; basis for `[min, max]` extent. */ const values = probes .map(function pluck(probe,) { return extractDim({ probe, dim, },); },) .filter(function known(value,): value is number { return value !== DIM_UNKNOWN; },); if (values.length === 0) { return [ 0, 0, ]; } return [ Math.min(...values,), Math.max(...values,), ]; } //endregion Helpers //region Wire functions /** Wires the six dim dropdowns. Changing a dim resets that channel's range slider to the new dim's extent, because old bounds are in old dim units and become meaningless. @param session - Mutable session. @param probes - Source probes. @param commit - Callback that re-renders and syncs hash. @example ```ts wireDimDropdowns({ session, probes, commit }); ``` */ export function wireDimDropdowns( { session, probes, commit, }: { session: Session; probes: readonly PackageProbe[]; commit: Commit; }, ): void { CHANNEL_KEYS.forEach(function bind(channel,) { /** Dim-dropdown `