import { ComputedRef, MaybeRefOrGetter } from '../../node_modules/vue'; /** * Reactive inputs driving {@link useStackedChart}. They mirror the data and * stacking-related props shared by the `StackedBarChart` and * `StackedColumnChart` components, accepted as plain values, refs or getters so * the composable adapts to how each caller wires its state. */ export interface UseStackedChartOptions { /** * The chart's loaded data (inline array or fetched), as exposed by `useChart`. */ loadedData: MaybeRefOrGetter[] | null>; /** * Whether the data has finished loading. Until then `sortedData` is empty so * the chart never reads from half-loaded data. */ isLoaded: MaybeRefOrGetter; /** * Field name(s) to sort the data by, or `null`/`undefined` to keep the * loaded order. */ sortBy: MaybeRefOrGetter; /** * Explicit list of stacked segment keys. When empty, the keys are discovered * from the first datum (every field except the label field). */ keys: MaybeRefOrGetter; /** * Field name in each datum holding the row label, excluded from the * discovered keys. */ labelField: MaybeRefOrGetter; /** * Display names for each key, used by {@link UseStackedChart.groupName}. The * name at the key's index wins, falling back to the key itself. */ groups: MaybeRefOrGetter; /** * Colors for each segment, mapped to the discovered keys by an ordinal scale. */ barColors: MaybeRefOrGetter; } /** * Reactive API returned by {@link useStackedChart}. */ export interface UseStackedChart { /** * The loaded data, optionally sorted by the `sortBy` option, or an empty * array until the data has loaded. */ sortedData: ComputedRef; /** * The stacked segment keys, either the explicit `keys` option or the fields * discovered from the first datum (minus the label field). */ discoveredKeys: ComputedRef; /** * The ordinal scale mapping each key to its color. */ colorScale: ComputedRef<(key: string) => string>; /** * Sums every key's value for the row at the given index. */ totalRowValue: (i: number | string) => number; /** * The largest row total across the data, driving the relative bar sizing. */ maxStackValue: ComputedRef; /** * The display name for a key: the matching `groups` entry, or the key itself. */ groupName: (key: string) => string; } /** * Owns the pure data logic shared by the `StackedBarChart` and * `StackedColumnChart` components: it sorts the data, discovers the stacked * keys, builds the ordinal color scale, sums each row and exposes the maximum * row total. It holds no DOM state — measurement, highlighting and the * width/height geometry stay in each component because they differ between the * horizontal and vertical layouts. * * @param options - Reactive stacking options (see {@link UseStackedChartOptions}). * @returns The {@link UseStackedChart} API of derived data. * @example * // Internal building block of the stacked chart components; not exported from * // the package root. Inside a `