/** * LTTB (Largest-Triangle-Three-Buckets) Downsampling Algorithm * * This algorithm downsamples time-series data while preserving visual features. * It's much better than naive sampling for preserving peaks and valleys. * * Reference: https://skemman.is/bitstream/1946/15343/3/SS_MSthesis.pdf */ export interface DownsampleResult { x: Float32Array; y: Float32Array; /** Original indices of selected points */ indices: Uint32Array; } /** * Downsample data using LTTB algorithm * * @param x - X values (e.g., potential) * @param y - Y values (e.g., current) * @param targetPoints - Number of output points * @returns Downsampled data */ export declare function lttbDownsample(x: Float32Array | Float64Array, y: Float32Array | Float64Array, targetPoints: number): DownsampleResult; /** * Min-Max per bucket downsampling * * Simpler alternative to LTTB that preserves extremes in each bucket. * Uses 2 points per bucket (min and max), so output is ~2x target. */ export declare function minMaxDownsample(x: Float32Array | Float64Array, y: Float32Array | Float64Array, bucketCount: number): DownsampleResult; /** * Calculate optimal target points based on canvas width */ export declare function calculateTargetPoints(dataLength: number, canvasWidth: number, pointsPerPixel?: number): number; export interface OhlcDownsampleResult { x: Float32Array; open: Float32Array; high: Float32Array; low: Float32Array; close: Float32Array; indices: Uint32Array; } /** * Aggregate OHLC bars into fewer buckets while preserving extremes. * Each bucket: open=first open, close=last close, high=max high, low=min low, x=last x. */ export declare function ohlcMinMaxDownsample(x: Float32Array | Float64Array, open: Float32Array | Float64Array, high: Float32Array | Float64Array, low: Float32Array | Float64Array, close: Float32Array | Float64Array, targetBars: number): OhlcDownsampleResult; /** Binary search lower bound: first index where x[i] >= value */ export declare function lowerBoundX(x: Float32Array | Float64Array, value: number): number; /** Binary search upper bound: first index where x[i] > value */ export declare function upperBoundX(x: Float32Array | Float64Array, value: number): number; export interface ViewportSlice { x: Float32Array; y?: Float32Array; open?: Float32Array; high?: Float32Array; low?: Float32Array; close?: Float32Array; start: number; end: number; } /** * Slice sorted x-series to visible range plus buffer (fraction of visible width). */ export declare function sliceSeriesToViewport(source: { x: Float32Array | Float64Array; y?: Float32Array | Float64Array; open?: Float32Array | Float64Array; high?: Float32Array | Float64Array; low?: Float32Array | Float64Array; close?: Float32Array | Float64Array; }, xMin: number, xMax: number, bufferRatio?: number): ViewportSlice;