simple-ascii-chart
Version:
Simple ascii chart generator
210 lines (209 loc) • 9.61 kB
TypeScript
import { CustomSymbol, Formatter, Graph, LineFormatterArgs, MaybePoint, MultiLine, Point, Symbols } from '../types';
/**
* Places a symbol at a specific position on the graph.
* @param {Object} params - Object containing parameters.
* @param {Graph} params.graph - The graph matrix where the symbol will be drawn.
* @param {number} params.scaledX - X-coordinate on the graph (scaled).
* @param {number} params.scaledY - Y-coordinate on the graph (scaled).
* @param {string} params.symbol - Symbol to draw on the graph.
*/
export declare const drawPosition: ({ graph, scaledX, scaledY, symbol, debugMode, }: {
graph: Graph;
scaledX: number;
scaledY: number;
symbol: string;
debugMode?: boolean;
}) => void;
/**
* Draws a tick mark at the end of the X-axis, handling bounds and axis center.
* @param {Object} params - Configuration options for drawing the X-axis tick.
* @param {boolean} params.hasPlaceToRender - True if there is enough space to render the tick.
* @param {Point | [number | undefined, number | undefined]} [params.axisCenter] - Coordinates of the axis center (optional).
* @param {number} params.yPos - The Y-position of the tick mark.
* @param {Graph} params.graph - The graph matrix being drawn on.
* @param {number} params.yShift - The Y-axis shift offset.
* @param {number} params.i - The current iteration index.
* @param {number} params.scaledX - The scaled X-position for rendering the tick.
* @param {number} params.shift - X-axis offset to adjust tick positioning.
* @param {number} params.signShift - Additional shift based on the sign of the axis.
* @param {Symbols['axis']} params.axisSymbols - Symbols used for the axis rendering.
* @param {string[]} params.pointXShift - Array of characters representing the X-axis labels.
*/
export declare const drawXAxisEnd: ({ hasPlaceToRender, axisCenter, yPos, graph, yShift, i, scaledX, shift, signShift, axisSymbols, pointXShift, debugMode, }: {
hasPlaceToRender: boolean;
axisCenter?: Point | [number | undefined, number | undefined];
yPos: number;
graph: Graph;
yShift: number;
i: number;
scaledX: number;
shift: number;
signShift: number;
axisSymbols: Symbols["axis"];
pointXShift: string[];
debugMode?: boolean;
}) => void;
/**
* Draws tick marks for the Y-axis based on axis configurations and scales.
* @param {Object} params - Configuration options for drawing the Y-axis ticks.
* @param {Graph} params.graph - The graph matrix.
* @param {number} params.scaledY - Scaled Y-coordinate.
* @param {number} params.yShift - Shift applied to the Y-axis.
* @param {Object} params.axis - Object defining the axis position.
* @param {MaybePoint} [params.axisCenter] - Optional axis center coordinates.
* @param {number} params.pointY - The actual Y-coordinate of the point.
* @param {Formatter} params.transformLabel - Function to format the label for the Y-axis.
* @param {Symbols['axis']} params.axisSymbols - Symbols used for drawing the axis.
* @param {number[]} params.expansionX - Array of X-axis expansion factors.
* @param {number[]} params.expansionY - Array of Y-axis expansion factors.
* @param {number} params.plotHeight - The height of the plot.
* @param {boolean} [params.showTickLabel] - If true, displays tick labels for all points.
*/
export declare const drawYAxisEnd: ({ graph, scaledY, yShift, axis, axisCenter, pointY, transformLabel, axisSymbols, expansionX, expansionY, plotHeight, showTickLabel, debugMode, }: {
graph: Graph;
scaledY: number;
yShift: number;
plotHeight: number;
axis: {
x: number;
y: number;
};
axisCenter?: MaybePoint;
pointY: number;
transformLabel: Formatter;
axisSymbols: Symbols["axis"];
expansionX: number[];
expansionY: number[];
showTickLabel?: boolean;
debugMode?: boolean;
}) => void;
/**
* Draws both X and Y axes on the graph according to visibility and center configurations.
* @param {Object} params - Configuration options for drawing axes.
* @param {Graph} params.graph - The graph matrix.
* @param {boolean} [params.hideXAxis] - If true, hides the X-axis.
* @param {boolean} [params.hideYAxis] - If true, hides the Y-axis.
* @param {MaybePoint} [params.axisCenter] - Optional axis center coordinates.
* @param {Symbols['axis']} params.axisSymbols - Symbols used for axis rendering.
* @param {Object} params.axis - Object defining the axis position (x and y coordinates).
*/
export declare const drawAxis: ({ graph, hideXAxis, hideYAxis, axisCenter, axisSymbols, axis, debugMode, }: {
graph: Graph;
axis: {
x: number;
y: number;
};
hideXAxis?: boolean;
axisCenter?: MaybePoint;
hideYAxis?: boolean;
axisSymbols: Symbols["axis"];
debugMode?: boolean;
}) => void;
/**
* Initializes an empty graph based on plot dimensions and a given symbol.
* @param {Object} params - Configuration options for the graph.
* @param {number} params.plotWidth - Width of the plot area.
* @param {number} params.plotHeight - Height of the plot area.
* @param {string} params.emptySymbol - Symbol used to fill empty cells.
* @returns {Graph} - An initialized empty graph matrix.
*/
export declare const drawGraph: ({ plotWidth, plotHeight, emptySymbol, }: {
plotWidth: number;
plotHeight: number;
emptySymbol: string;
}) => string[][];
/**
* Renders the graph into a string format for output.
* @param {Object} params - Configuration options for rendering the graph.
* @param {Graph} params.graph - The graph matrix to render.
* @returns {string} - The rendered graph as a string.
*/
export declare const drawChart: ({ graph }: {
graph: Graph;
}) => string;
/**
* Renders a custom line on the graph based on formatter specifications.
* @param {Object} params - Configuration options for rendering custom lines.
* @param {Point[]} params.sortedCoords - Sorted list of coordinates.
* @param {number} params.scaledX - X-axis scaling.
* @param {number} params.scaledY - Y-axis scaling.
* @param {number} params.minY - Minimum Y value.
* @param {number} params.minX - Minimum X value.
* @param {MultiLine} params.input - Input data points.
* @param {number[]} params.expansionX - X-axis expansion range.
* @param {number[]} params.expansionY - Y-axis expansion range.
* @param {function} params.toPlotCoordinates - Function to convert coordinates to plot positions.
* @param {number} params.index - Current index in the coordinate array.
* @param {function} params.lineFormatter - Custom function for line formatting.
* @param {Graph} params.graph - The graph matrix to modify.
*/
export declare const drawCustomLine: ({ sortedCoords, scaledX, scaledY, input, index, lineFormatter, graph, toPlotCoordinates, expansionX, expansionY, minY, minX, debugMode, }: {
sortedCoords: Point[];
scaledX: number;
scaledY: number;
input: MultiLine;
index: number;
minY: number;
minX: number;
expansionX: number[];
expansionY: number[];
toPlotCoordinates: (x: number, y: number) => Point;
lineFormatter: (args: LineFormatterArgs) => CustomSymbol | CustomSymbol[];
graph: Graph;
debugMode?: boolean;
}) => void;
/**
* Renders a line between two points on the graph using defined chart symbols.
* @param {Object} params - Configuration options for drawing a line.
* @param {number} params.index - Current index in the coordinate array.
* @param {Point[]} params.arr - List of points for the line.
* @param {Graph} params.graph - The graph matrix to modify.
* @param {number} params.scaledX - X-axis scaling.
* @param {number} params.scaledY - Y-axis scaling.
* @param {boolean} params.horizontalBarChart - Whether to fill the width of the bars.
* @param {boolean} params.barChart - Whether to fill the width of the bars.
* @param {number} params.plotHeight - Height of the plot area.
* @param {string} params.emptySymbol - Symbol used to fill empty cells.
* @param {Object} params.axis - Axis position.
* @param {MaybePoint} axisCenter - Axis position selected by user.
* @param {Symbols['chart']} params.chartSymbols - Symbols used for chart rendering.
*/
export declare const drawLine: ({ index, arr, graph, scaledX, scaledY, plotHeight, emptySymbol, chartSymbols, horizontalBarChart, barChart, axisCenter, debugMode, axis, }: {
index: number;
arr: Point[];
graph: Graph;
scaledX: number;
scaledY: number;
plotHeight: number;
emptySymbol: string;
chartSymbols: Symbols["chart"];
horizontalBarChart?: boolean;
barChart?: boolean;
axisCenter: MaybePoint;
axis: {
x: number;
y: number;
};
debugMode?: boolean;
}) => void;
/**
* Applies shifts to the graph and adjusts empty symbols and scaling factors.
* @param {Object} params - Configuration options for applying shifts.
* @param {Graph} params.graph - The graph matrix.
* @param {number} params.plotWidth - The width of the plot area.
* @param {string} params.emptySymbol - The symbol used to fill empty cells.
* @param {number[][]} params.scaledCoords - Scaled coordinates for shifting.
* @param {number} params.xShift - X-axis shift offset.
* @param {number} params.yShift - Y-axis shift offset.
* @returns {Object} - An object indicating if the graph needs to be moved.
*/
export declare const drawShift: ({ graph, plotWidth, emptySymbol, scaledCoords, xShift, yShift, }: {
graph: Graph;
plotWidth: number;
emptySymbol: string;
scaledCoords: number[][];
xShift: number;
yShift: number;
}) => {
hasToBeMoved: boolean;
};