import { scaleSequential } from 'd3-scale' import type { ScaleSequential } from 'd3-scale' import get from 'lodash/get' import maxFn from 'lodash/max' import minFn from 'lodash/min' import values from 'lodash/values' import { computed, toValue } from 'vue' import type { ComputedRef, MaybeRefOrGetter } from 'vue' /** * Reactive inputs driving {@link useChoropleth}. They mirror the * `ChoroplethMap` component's loaded data, the color-scale bounds and the * endpoint colors, accepted as plain values, refs or getters so the composable * adapts to how the caller wires its state. */ export interface UseChoroplethOptions { /** * The map's loaded data, keyed by feature identifier, as exposed by `useChart`. */ loadedData: MaybeRefOrGetter | null> /** * Path (dot notation supported) to a feature's identifier inside the geojson * datum, used to look its value up in `loadedData`. */ topojsonObjectsPath: MaybeRefOrGetter /** * Forced maximum value for the color scale, or `null` to derive it from the data. */ max: MaybeRefOrGetter /** * Forced minimum value for the color scale, or `null` to derive it from the data. */ min: MaybeRefOrGetter /** * A custom scale function overriding the default sequential scale, or `null` * to use the default. */ featureColorScale: MaybeRefOrGetter<((v: any) => string) | null> /** * Color mapped to the scale's low end. */ colorScaleStart: MaybeRefOrGetter /** * Color mapped to the scale's high end. */ colorScaleEnd: MaybeRefOrGetter } /** * Reactive API returned by {@link useChoropleth}. */ export interface UseChoropleth { /** * The maximum value used by the color scale (forced or derived). */ maxValue: ComputedRef /** * The minimum value used by the color scale (forced or derived). */ minValue: ComputedRef /** * The default sequential scale, from the start color to the end color. */ defaultFeatureColorScale: ComputedRef> /** * The active scale function: the custom one when provided, the default otherwise. */ featureColorScaleFunction: ComputedRef<(v: any) => string> /** * Maps a geojson datum to its color, or `null` when the feature has no data. */ featureColor: ComputedRef<(d: any) => string | null> } /** * Owns the pure color-scale logic of the `ChoroplethMap` component: it derives * the value bounds, builds the default sequential scale between the two * endpoint colors, and resolves a per-feature color from the loaded data. It * holds no DOM state — the endpoint colors are measured by the component and * passed in. * * @param options - Reactive color-scale options (see {@link UseChoroplethOptions}). * @returns The {@link UseChoropleth} API of derived color logic. * @example * // Internal building block of the `ChoroplethMap` component; not exported * // from the package root. Inside a `