simple-ascii-chart
Version:
Simple ascii chart generator
110 lines (109 loc) • 4.48 kB
TypeScript
import { Symbols, MultiLine, Formatter, Coordinates, GraphPoint, Threshold, MaybePoint } from '../types/index.js';
/**
* Merges custom symbols with default axis symbols and defines plot symbols.
* @param {object} options - An object containing optional custom symbols.
* @param {Symbols} options.symbols - Custom symbols for the plot.
* @returns {object} - Object containing the merged axis symbols, and defined symbols for empty, background, and border.
*/
export declare const getSymbols: ({ symbols }: {
symbols?: Symbols;
}) => {
axisSymbols: {
n: string;
ns: string;
y: string;
nse: string;
x: string;
we: string;
e: string;
intersectionXY: string;
intersectionX: string;
intersectionY: string;
};
emptySymbol: string;
backgroundSymbol: string;
borderSymbol: string | undefined;
thresholdSymbols: {
x: string;
y: string;
};
pointSymbol: string;
};
/**
* Determines plot size and range based on provided data and dimensions.
* @param {object} options - An object containing input data and optional dimensions.
* @param {MultiLine} options.input - The multiline array of points.
* @param {number} [options.width] - Optional width of the plot.
* @param {number} [options.height] - Optional height of the plot.
* @param {MaybePoint} [options.axisCenter] - Optional axis center point.
* @param {[number, number]} [options.yRange] - Optional range for the y-axis.
* @returns {object} - Object containing min x value, plot width, plot height, and x and y expansions.
*/
export declare const getChartSize: ({ input, width, height, yRange, axisCenter, }: {
input: MultiLine;
width?: number;
height?: number;
axisCenter?: MaybePoint;
yRange?: [number, number];
}) => {
minX: number;
minY: number;
plotWidth: number;
plotHeight: number;
expansionX: number[];
expansionY: [number, number];
};
/**
* Calculates shifts for x and y labels, based on the longest label length.
* @param {object} options - The input data and formatting options.
* @param {MultiLine} options.input - The multiline array of points.
* @param {Formatter} options.transformLabel - A function to transform label values.
* @param {number[]} options.expansionX - The x-axis range.
* @param {number[]} options.expansionY - The y-axis range.
* @param {number} options.minX - The minimum x value for label calculation.
* @param {boolean} [options.showTickLabel] - Flag to indicate if tick labels should be shown.
* @returns {object} - Object containing the calculated xShift and yShift.
*/
export declare const getLabelShift: ({ input, transformLabel, expansionX, expansionY, minX, showTickLabel, }: {
input: MultiLine;
transformLabel: Formatter;
expansionX: number[];
expansionY: number[];
minX: number;
showTickLabel?: boolean;
}) => {
xShift: number;
yShift: number;
};
/**
* Normalizes raw input data into a consistent multi-line format.
* @param {object} options - Contains the raw input data.
* @param {Coordinates} options.rawInput - Input coordinates, either single or multi-line.
* @returns {MultiLine} - The formatted data as a multi-line array of points.
*/
export declare const getInput: ({ rawInput }: {
rawInput: Coordinates;
}) => MultiLine;
/**
* Generates legend data based on the provided points, thresholds, and series.
* @param {object} options - Contains points, thresholds, and series data.
* @param {MultiLine} options.input - The input data for the plot.
* @param {GraphPoint[]} options.points - The coordinates of the points.
* @param {Threshold[]} options.thresholds - The thresholds for the plot.
* @param {string[] | string} options.pointsSeries - The series names for the points.
* @param {string[] | string} options.thresholdsSeries - The series names for the thresholds.
* @param {string[] | string} options.dataSeries - The series names for the data.
* @returns {object} - Object containing the series, points, and thresholds for the legend.
*/
export declare const getLegendData: ({ input, thresholds, points, pointsSeries, thresholdsSeries, dataSeries, }: {
input: MultiLine;
points?: GraphPoint[];
thresholds?: Threshold[];
pointsSeries?: string[] | string;
thresholdsSeries?: string[] | string;
dataSeries?: string[] | string;
}) => {
series: string[];
points: string[];
thresholds: string[];
};