ag-charts-community
Version:
Advanced Charting / Charts supporting Javascript / Typescript / React / Angular / Vue
86 lines (85 loc) • 3.26 kB
TypeScript
import { EventEmitter } from 'ag-charts-core';
export interface AggregationManagerEvents {
filtersChanged: void;
}
/**
* Base interface for aggregation filters used by AggregationManager.
*/
export interface AggregationFilterBase {
maxRange: number;
}
/**
* Result type for partial aggregation with deferred computation.
*/
export interface PartialAggregationResult<TFilter> {
immediate: TFilter[];
computeRemaining?: () => TFilter[];
}
/**
* Manages aggregation state and deferred computation for series.
*
* This class consolidates the common pattern used by Bar, OHLC, and RangeBar series
* for managing multi-level aggregation with deferred computation of coarser levels.
*
* @example
* ```typescript
* private readonly aggregationManager = new AggregationManager<MyFilter>();
*
* private aggregateData(...) {
* return this.aggregationManager.aggregate({
* computePartial: () => computePartial(...),
* computeFull: () => computeFull(...),
* targetRange: this.estimateTargetRange(),
* });
* }
* ```
*/
export declare class AggregationManager<TFilter extends AggregationFilterBase> {
private _filters;
private _dataLength;
private readonly executor;
/**
* Emits `filtersChanged` on every filter-set mutation: aggregation
* rebuilds (immediate + deferred coarser levels), staleness-driven
* discards (`markStale`), and on-demand level merges
* (`ensureLevelForRange`). `BucketLookupFeature` subscribes here to
* keep the per-bucket SELECTED roll-up cache in sync with the active
* filter list.
*/
readonly events: EventEmitter<AggregationManagerEvents>;
get filters(): TFilter[] | undefined;
/**
* Perform aggregation with deferred computation of coarser levels.
* Returns immediate filters suitable for current zoom level.
*
* @param options.computePartial - Function to compute partial aggregation (receives existing filters for reuse)
* @param options.computeFull - Function to compute full aggregation (receives existing filters for reuse)
* @param options.targetRange - Current pixel range for determining which level to compute immediately
* @returns The computed filters (immediate level for partial, or all levels for full)
*/
aggregate(options: {
computePartial?: (existingFilters: TFilter[] | undefined) => PartialAggregationResult<TFilter> | undefined;
computeFull: (existingFilters: TFilter[] | undefined) => TFilter[] | undefined;
targetRange: number;
}): TFilter[] | undefined;
/**
* Ensure we have an aggregation level suitable for the given range.
* Forces deferred computation if needed.
*/
ensureLevelForRange(range: number): void;
/**
* Get the best filter for a given range.
*/
getFilterForRange(range: number): TFilter | undefined;
/**
* Cancel any pending deferred computation.
*/
cancel(): void;
/**
* Mark filters as stale or discard them based on data size change.
* When data size changes significantly (>=2x), filters are discarded to prevent
* incorrect array reuse.
*/
markStale(dataLength: number): void;
private mergeFilters;
}