/** * @file data-transforms.ts * @description * Composable data transformation utilities for chart data processing. * All transforms follow the functional pattern: (data: T[]) => T[] or Record * * Transforms can be composed using the `compose()` function for declarative * data pipelines. * * @example * ```typescript * import { DataTransforms } from '@composable-svelte/charts'; * * // Compose multiple transforms * const transform = DataTransforms.compose( * DataTransforms.filter(d => d.value > 100), * DataTransforms.sortBy('date', 'desc'), * DataTransforms.topN(10, 'value') * ); * * const result = transform(data); * ``` */ import type { DataTransform } from '../types/chart.types'; /** * @function filter * @description * Creates a transform that filters data by a predicate function. * * @example * ```typescript * const filterHighValues = filter(d => d.value > 100); * const result = filterHighValues(data); * ``` * * @template T - Type of data items * @param {(d: T) => boolean} predicate - Filter predicate * @returns {DataTransform} Transform function */ export declare function filter(predicate: (d: T) => boolean): DataTransform; /** * @function sortBy * @description * Creates a transform that sorts data by a field or accessor function. * * @example * ```typescript * // Sort by field * const sortByValue = sortBy('value', 'desc'); * * // Sort by accessor * const sortByComputed = sortBy(d => d.x * d.y, 'asc'); * ``` * * @template T - Type of data items * @param {keyof T | ((d: T) => any)} field - Field name or accessor * @param {'asc' | 'desc'} [order='asc'] - Sort order * @returns {DataTransform} Transform function */ export declare function sortBy(field: keyof T | ((d: T) => any), order?: 'asc' | 'desc'): DataTransform; /** * Group data by a key * Returns a function that transforms data into groups */ export declare function groupBy(key: keyof T | ((d: T) => string)): (data: T[]) => Record; /** * Aggregate data */ export declare function aggregate(operation: 'sum' | 'mean' | 'median' | 'count' | 'min' | 'max', field?: keyof T): (data: T[]) => number; /** * @function compose * @description * Composes multiple transforms into a single transform function. * Transforms are applied left-to-right (first transform receives original data). * * This enables declarative data pipelines: * ```typescript * const pipeline = compose( * filter(d => d.active), * sortBy('date', 'desc'), * topN(10, 'score') * ); * const result = pipeline(data); * ``` * * @example * ```typescript * // Filter, sort, then take top 5 * const transform = compose( * filter(d => d.category === 'A'), * sortBy('value', 'desc'), * topN(5, 'value') * ); * * const result = transform(data); * // Result: Top 5 category A items by value * ``` * * @template T - Type of data items * @param {...DataTransform} transforms - Transform functions to compose * @returns {DataTransform} Composed transform function */ export declare function compose(...transforms: DataTransform[]): DataTransform; /** * @function binData * @description * Creates a transform that bins continuous data into discrete intervals. * Useful for creating histograms or grouping continuous values. * * Each data point is augmented with: * - `binIndex`: Index of the bin (0-based) * - `binStart`: Lower bound of the bin * - `binEnd`: Upper bound of the bin * * Uses D3's bin() under the hood for optimal bin calculation. * * @example * ```typescript * // Bin values into 10 equal intervals * const bin10 = binData('value', 10); * const binned = bin10(data); * // Each item now has binIndex, binStart, binEnd * * // Custom thresholds * const binCustom = binData('value', [0, 50, 100, 150]); * ``` * * @template T - Type of data items * @param {keyof T | ((d: T) => number)} field - Field to bin or accessor * @param {number | number[]} thresholds - Number of bins or explicit thresholds * @returns Transform function that adds bin metadata */ export declare function binData(field: keyof T | ((d: T) => number), thresholds: number | number[]): (data: T[]) => Array; /** * Rolling window aggregation * Applies operation to sliding window of data */ export declare function rollup(window: number, field: keyof T | ((d: T) => number), operation?: (values: number[]) => number | undefined): (data: T[]) => Array; /** * Top N items by field */ export declare function topN(n: number, field: keyof T | ((d: T) => number)): DataTransform; /** * Remove duplicates by field */ export declare function unique(field: keyof T | ((d: T) => any)): DataTransform; /** * Sample random subset of data */ export declare function sample(n: number): DataTransform; /** * Pre-built transform pipeline helpers */ export declare const DataTransforms: { filter: typeof filter; groupBy: typeof groupBy; aggregate: typeof aggregate; sortBy: typeof sortBy; binData: typeof binData; rollup: typeof rollup; compose: typeof compose; topN: typeof topN; unique: typeof unique; sample: typeof sample; }; //# sourceMappingURL=data-transforms.d.ts.map