@wings-j/chart-data-preprocess
v0.4.0
Published
Tools for preprocessing data before generating charts.
Downloads
90
Readme
chart-data-preprocess is a lightweight TypeScript library for preparing numeric data before generating charts. It provides utility functions for parsing values, formatting numbers, and transforming data arrays to support common chart preprocessing tasks.
Installation
npm install @wings-j/chart-data-preprocessAPI
Types
Math
Utility
Methods
combine
compress
split
transform
Document
Vector1
interface Vector1 {
x: number;
}Vector2
interface Vector2 {
x: number;
y: number;
}min
/**
* Min
* @description Find the minimum value in an array.
* @param [array] Array
* @return Value
*/
function min(array: number[]): number;max
/**
* Max
* @description Find the maximum value in an array.
* @param [array] Array
* @return Value
*/
function max(array: number[]): number;minMax
/**
* Min Max
* @description Find both the minimum and maximum values in an array.
* @param [array] Array
* @return Min Value and Max Value
*/
function minMax(array: number[]): [number, number];sum
/**
* Sum
* @description Calculate the sum of all values in an array.
* @param [array] Array
* @return Value
*/
function sum(array: number[]): number;mean
/**
* Mean
* @description Calculate the average (mean) of all values in an array.
* @param [array] Array
* @return Value
*/
function mean(array: number[]): number;median
/**
* Median
* @description Calculate the median of an array of numbers.
* @param [array] Array of numbers
* @return Median value
*/
function median(array: number[]): number;parse
/**
* Parse
* @param [value] Value
* @return Number
*/
function parse(value: any): number;format
/**
* Format
* @param [value] Value
* @param [fraction] Fraction
* @param [trim] Trim
* @return String
*/
function format(value: number, fraction: number, trim?: boolean): string;successionCombine
/**
* Succession Combine
* @description Merge multiple arrays into one by identifier, removing duplicates while preserving the succession order.
* @type [T] Data Type
* @param [array] Array
* @param [xGetter] X Getter
* @param [unit] Unit
* @return Combined Array
*/
function successionCombine<T = any>(array: T[], xGetter: (item: T) => number, unit: number): { start: T; end: T; middle: T[] }[];multiplePartsCombine
/**
* Multiple Parts Combine
* @description Merge multiple arrays into one by identifier, removing duplicates while preserving the first-seen order.
* @type [T] Data Type
* @param [array] Array Groups
* @param [vGetter] Value Getter
* @return Combined Array
*/
function multiplePartsCombine<T = any>(array: T[][], vGetter: (item: T) => any): T[];consecutiveDuplicateCompress
/**
* Consecutive Duplicate Compress
* @description Compresses the input array by removing consecutive duplicate entries while preserving order.
* @type [T] Data Type
* @param [array] Array
* @param [vGetter] Value Getter
* @return Compressed Array
*/
function consecutiveDuplicateCompress<T = any>(array: T[], vGetter?: (item: T) => any): T[];distanceThresholdCompress
/**
* Distance Threshold Compress
* @description Compresses the input vector array by removing points whose x-distance to the previous kept point is within the given unit threshold.
* @type [T] Data Type
* @param [array] Array
* @param [xGetter] X Getter
* @param [unit] Unit Size
* @returns Compressed Array
*/
function distanceThresholdCompress<T = any>(array: T[], xGetter: (item: T) => number, unit: number): T[];largestTriangleThreeBucketsCompress
/**
* Largest Triangle Three Buckets Compress
* @description Downsamples the input vector array to the requested length using the largest-triangle-three-buckets (LTTB) algorithm.
* @type [T] Data Type
* @param [array] Array
* @param [length] Target Length
* @return Compressed Array
*/
function largestTriangleThreeBucketsCompress<T = any>(array: T[], xGetter: (item: T) => number, yGetter: (item: T) => number, length: number): T[];autoGapSplit
/**
* Auto Gap Split
* @description Split an array into sub arrays based on gaps between consecutive elements.
* @type [T] Data Type
* @param [array] Array to split
* @param [xGetter] Function to extract the numeric value for gap calculation
* @param [tolerance] Multiplier for the normal gap to determine the threshold
* @return Array of Sub Arrays
*/
function autoGapSplit<T extends Vector1 = any>(array: T[], xGetter: (item: T) => number, tolerance?: number): T[][];ratio
/**
* Ratio
* @description Calculate ratio.
* @type [T] Data Type
* @param [array] Array
* @param [xGetter] X Getter
* @return Array with X Ratio
*/
function ratio<T = any>(array: T[], xGetter: (item: T) => number): { value: T; x: number }[];