simple-ascii-chart
Version:
Simple ascii chart generator
121 lines (120 loc) • 6.24 kB
TypeScript
import { SingleLine, Point, MultiLine } from '../types/index';
/**
* Creates an array filled with a specified string.
* @param {number} size - The size of the array.
* @param {string} empty - The value to fill the array with (default: EMPTY).
* @returns {string[]} - An array filled with the specified string.
*/
export declare const toEmpty: (size: number, empty?: string) => string[];
/**
* Converts a number or string to an array of its characters.
* @param {number | string} input - The input to convert.
* @returns {string[]} - An array of characters.
*/
export declare const toArray: (input: number | string) => string[];
/**
* Removes duplicate values from an array.
* @param {number[]} array - The array of numbers.
* @returns {number[]} - An array containing only unique values.
*/
export declare const toUnique: (array: number[]) => number[];
/**
* Calculates the distance between two integer coordinates by rounding to the nearest integers.
* @param {number} x - The x-coordinate of the first point.
* @param {number} y - The y-coordinate of the second point.
* @returns {number} - The absolute distance between the rounded points.
*/
export declare const distance: (x: number, y: number) => number;
/**
* Flattens a multi-line array of points into a single array of points.
* @param {MultiLine} array - The multi-line array.
* @returns {Point[]} - A flat array of points.
*/
export declare const toFlat: (array: MultiLine) => Point[];
/**
* Converts a multi-line array into arrays of unique x and y values.
* @param {MultiLine} array - The multi-line array.
* @returns {[number[], number[]]} - Arrays of unique x and y values.
*/
export declare const toArrays: (array: MultiLine) => [number[], number[]];
/**
* Sorts a single-line array of points in ascending order based on the x-coordinate.
* @param {SingleLine} array - The single-line array to sort.
* @returns {SingleLine} - The sorted array.
*/
export declare const toSorted: (array: SingleLine) => SingleLine;
/**
* Returns a function that converts a coordinate (x, y) to scaled plot coordinates.
* @param {number} plotWidth - The width of the plot.
* @param {number} plotHeight - The height of the plot.
* @returns {function} - A function that takes (x, y) and returns scaled plot coordinates [scaledX, scaledY].
*/
export declare const toPlot: (plotWidth: number, plotHeight: number) => (x: number, y: number) => Point;
/**
* Returns a function that converts scaled plot coordinates (scaledX, scaledY) back to the original coordinates.
* @param {number} plotWidth - The width of the plot.
* @param {number} plotHeight - The height of the plot.
* @returns {function} - A function that takes (scaledX, scaledY) and returns original coordinates [x, y].
*/
export declare const fromPlot: (plotWidth: number, plotHeight: number) => (scaledX: number, scaledY: number) => [number, number];
/**
* Finds the maximum or minimum value in a single-line array of points.
* @param {SingleLine} arr - The single-line array to search for extrema.
* @param {'max' | 'min'} type - 'max' to find the maximum value, 'min' for minimum (default is 'max').
* @param {number} position - The position of the value within each point (default is 1).
* @returns {number} - The maximum or minimum value found in the array.
*/
export declare const getExtrema: (arr: SingleLine, type?: "max" | "min", position?: number) => number;
/**
* Finds the maximum value in an array of numbers.
* @param {number[]} arr - The array of numbers.
* @returns {number} - The maximum value in the array.
*/
export declare const getMax: (arr: number[]) => number;
/**
* Finds the minimum value in an array of numbers.
* @param {number[]} arr - The array of numbers.
* @returns {number} - The minimum value in the array.
*/
export declare const getMin: (arr: number[]) => number;
/**
* Returns a function that scales coordinates to fit within a specified range.
* @param {[number, number]} domain - The original value range (min and max).
* @param {[number, number]} range - The range to scale the values into.
* @returns {(value: number) => number} - A function for scaling coordinates.
*/
export declare const scaler: ([domainMin, domainMax]: number[], [rangeMin, rangeMax]: number[]) => (domainValue: number) => number;
/**
* Scales a point's coordinates to fit within the specified plot dimensions.
* @param {Point} point - The point to scale.
* @param {number} plotWidth - The width of the plot.
* @param {number} plotHeight - The height of the plot.
* @param {number[]} rangeX - The range of x values.
* @param {number[]} rangeY - The range of y values.
* @returns {Point} - The scaled point.
*/
export declare const toCoordinates: (point: Point, plotWidth: number, plotHeight: number, rangeX: number[], rangeY: number[]) => Point;
/**
* Scales a list of coordinates to fit within the specified plot dimensions.
* @param {SingleLine} coordinates - The list of coordinates to scale.
* @param {number} plotWidth - The width of the plot.
* @param {number} plotHeight - The height of the plot.
* @param {number[]} [rangeX] - The range of x values (defaults to min and max from coordinates).
* @param {number[]} [rangeY] - The range of y values (defaults to min and max from coordinates).
* @returns {SingleLine} - The scaled list of coordinates.
*/
export declare const getPlotCoords: (coordinates: SingleLine, plotWidth: number, plotHeight: number, rangeX?: number[], rangeY?: number[]) => SingleLine;
/**
* Computes the axis center point based on specified plot dimensions and ranges.
* @param {MaybePoint} axisCenter - The center point for the axis.
* @param {number} plotWidth - The width of the plot.
* @param {number} plotHeight - The height of the plot.
* @param {number[]} rangeX - The range of x values.
* @param {number[]} rangeY - The range of y values.
* @param {number[]} initialValue - The initial axis values.
* @returns {Point} - The center point of the axis.
*/
export declare const getAxisCenter: (axisCenter: Point | [number | undefined, number | undefined] | undefined, plotWidth: number, plotHeight: number, rangeX: number[], rangeY: number[], initialValue: [number, number]) => {
x: number;
y: number;
};