simple-ascii-chart
Version:
Simple ascii chart generator
374 lines (373 loc) • 17.8 kB
TypeScript
import { AXIS } from '../constants/index.js';
import { CustomSymbol, Formatter, Graph, GraphMode, LineFormatterArgs, MaybePoint, MultiLine, Point, Symbols } from '../types/index.js';
/**
* 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.
* @param {boolean} [params.debugMode=false] - If true, logs errors for out-of-bounds access.
*/
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 {boolean} [params.hideXAxisTicks] - If true, hides the X-axis ticks.
* @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.
* @param {boolean} [params.debugMode=false] - If true, logs errors for out-of-bounds access.
*/
export declare const drawXAxisEnd: ({ hasPlaceToRender, yPos, graph, yShift, i, scaledX, hideXAxisTicks, pointXShift, debugMode, axisCenter, }: {
hasPlaceToRender: boolean;
yPos: number;
graph: Graph;
hideXAxisTicks?: boolean;
yShift: number;
i: number;
scaledX: number;
axisCenter?: MaybePoint;
pointXShift: string[];
debugMode?: boolean;
}) => void;
export declare const drawXAxisTick: ({ graph, xPosition, hideXAxisTicks, axisSymbols, debugMode, axis, }: {
axis: {
x: number;
y: number;
};
graph: Graph;
hideXAxisTicks?: boolean;
xPosition: number;
axisSymbols: Symbols["axis"];
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 {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.
* @param {number} params.axis.x - X-position of the Y-axis on the graph.
* @param {number} params.axis.y - Y-position of the X-axis on the graph.
* @param {boolean} [params.hideYAxisTicks] - If true, hides Y-axis ticks.
* @param {boolean} [params.debugMode=false] - If true, logs errors for out-of-bounds access.
*/
export declare const drawYAxisEnd: ({ graph, scaledY, yShift, axis, pointY, transformLabel, axisSymbols, expansionX, expansionY, plotHeight, showTickLabel, hideYAxisTicks, debugMode, }: {
graph: Graph;
scaledY: number;
yShift: number;
plotHeight: number;
axis: {
x: number;
y: number;
};
pointY: number;
transformLabel: Formatter;
axisSymbols: Symbols["axis"];
expansionX: number[];
expansionY: number[];
hideYAxisTicks?: boolean;
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).
* @param {number} params.axis.x - X-position of the Y-axis on the graph.
* @param {number} params.axis.y - Y-position of the X-axis on the graph.
* @param {boolean} [params.debugMode=false] - If true, logs errors for out-of-bounds access.
*/
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.
* @param {boolean} [params.debugMode=false] - If true, logs errors for out-of-bounds access.
*/
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 {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 {Symbols['chart']} params.chartSymbols - Symbols used for chart rendering.
* @param {MaybePoint} params.axisCenter - Axis position selected by user.
* @param {number} params.axis.x - X-position of the Y-axis on the graph.
* @param {number} params.axis.y - Y-position of the X-axis on the graph.
* @param {string} params.mode - Graph mode (e.g., 'line', 'point').
* @param {boolean} [params.debugMode=false] - If true, logs errors for out-of-bounds access.
*/
export declare const drawLine: ({ index, arr, graph, scaledX, scaledY, plotHeight, emptySymbol, chartSymbols, axisCenter, debugMode, axis, mode, }: {
index: number;
arr: Point[];
graph: Graph;
scaledX: number;
scaledY: number;
plotHeight: number;
emptySymbol: string;
chartSymbols: Symbols["chart"];
axisCenter: MaybePoint;
axis: {
x: number;
y: number;
};
debugMode?: boolean;
mode: GraphMode;
}) => 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;
realYShift: number;
realXShift: number;
};
/**
* Draws ticks on the Y-axis based on axis configurations and scaling.
* @param {Object} params - Configuration options for drawing the Y-axis ticks.
* @param {boolean} [params.debugMode=false] - If true, logs errors for out-of-bounds access.
* @param {boolean} [params.showTickLabel] - If true, shows tick labels for all points.
* @param {boolean} [params.hideYAxisTicks] - If true, hides the Y-axis ticks.
* @param {number} params.plotHeight - The height of the plot area.
* @param {Graph} params.graph - The graph matrix.
* @param {number} params.plotWidth - The width of the plot area.
* @param {number} params.yShift - Shift applied to the Y-axis.
* @param {Object} params.axis - Object defining the axis position.
* @param {number} params.axis.x - X-position of the Y-axis on the graph.
* @param {number} params.axis.y - Y-position of the X-axis on the graph.
* @param {function} params.transformLabel - Function to format the label for the ticks.
* @param {Symbols['axis']} params.axisSymbols - Symbols used for axis rendering.
* @param {number[]} params.expansionX - X-axis expansion range.
* @param {number[]} params.expansionY - Y-axis expansion range.
* @returns {Void} - Applies the drawing of Y-axis ticks.
*/
export declare const getDrawYAxisTicks: ({ debugMode, showTickLabel, hideYAxisTicks, plotHeight, graph, plotWidth, yShift, axis, transformLabel, axisSymbols, expansionX, expansionY, }: {
debugMode?: boolean;
showTickLabel?: boolean;
hideYAxisTicks?: boolean;
plotHeight: number;
graph: Graph;
plotWidth: number;
yShift: number;
axis: {
x: number;
y: number;
};
transformLabel: Formatter;
axisSymbols: Symbols["axis"];
expansionX: number[];
expansionY: number[];
}) => (points: Point[]) => void;
/**
* Draws ticks on the X-axis based on axis configurations and scaling.
* @param {Object} params - Configuration options for drawing the X-axis ticks.
* @param {boolean} [params.debugMode=false] - If true, logs errors for out-of-bounds access.
* @param {boolean} [params.hideXAxisTicks] - If true, hides the X-axis ticks.
* @param {number} params.plotWidth - The width of the plot area.
* @param {number} params.plotHeight - The height of the plot area.
* @param {number} params.yShift - Shift applied to the Y-axis.
* @param {Graph} params.graph - The graph matrix.
* @param {MaybePoint} [params.axisCenter] - Optional axis center coordinates.
* @param {string} params.emptySymbol - Symbol used to fill empty cells.
* @param {Point[]} params.points - List of points for the X-axis.
* @param {Symbols['axis']} params.axisSymbols - Symbols used for axis rendering.
* @param {boolean} [params.hasToBeMoved] - If true, indicates that the graph needs to be moved.
* @param {Object} params.axis - Object defining the axis position.
* @param {number} params.axis.x - X-position of the Y-axis on the graph.
* @param {number} params.axis.y - Y-position of the X-axis on the graph.
* @param {function} params.transformLabel - Function to format the label for the ticks.
* @param {number[]} params.expansionX - X-axis expansion range.
* @param {number[]} params.expansionY - Y-axis expansion range.
* @param {boolean} [params.hideXAxis] - If true, hides the X-axis.
* @returns {Void} - Applies the drawing of X-axis ticks.
*/
export declare const getDrawXAxisTicks: ({ debugMode, hideXAxisTicks, plotWidth, plotHeight, yShift, graph, axisCenter, emptySymbol, axisSymbols, axis, transformLabel, expansionX, expansionY, }: {
debugMode?: boolean;
hideXAxisTicks?: boolean;
plotWidth: number;
plotHeight: number;
emptySymbol: string;
yShift: number;
graph: Graph;
axisCenter?: MaybePoint;
axis: {
x: number;
y: number;
};
transformLabel: Formatter;
axisSymbols: typeof AXIS;
expansionX: number[];
expansionY: number[];
}) => (points: Point[]) => void;
/**
* Draws ticks on the graph based on the provided configuration.
* @param {Object} params - Configuration options for drawing ticks.
* @param {MultiLine} params.input - Input data points.
* @param {Graph} params.graph - The graph matrix.
* @param {number} params.plotWidth - The width of the plot area.
* @param {number} params.plotHeight - The height of the plot area.
* @param {Object} params.axis - Object defining the axis position.
* @param {number} params.axis.x - X-position of the Y-axis on the graph.
* @param {number} params.axis.y - Y-position of the X-axis on the graph.
* @param {MaybePoint} [params.axisCenter] - Optional axis center coordinates.
* @param {number} params.yShift - Shift applied to the Y-axis.
* @param {string} params.emptySymbol - Symbol used to fill empty cells.
* @param {boolean} [params.debugMode=false] - If true, logs errors for out-of-bounds access.
* @param {boolean} [params.hideXAxis] - If true, hides the X-axis.
* @param {boolean} [params.hideYAxis] - If true, hides the Y-axis.
* @param {number[]} params.expansionX - X-axis expansion range.
* @param {number[]} params.expansionY - Y-axis expansion range.
* @param {number[]} [params.customYAxisTicks] - Custom Y-axis ticks.
* @param {number[]} [params.customXAxisTicks] - Custom X-axis ticks.
* @param {boolean} [params.hideYAxisTicks] - If true, hides Y-axis ticks.
* @param {boolean} [params.hideXAxisTicks] - If true, hides X-axis ticks.
* @param {boolean} [params.showTickLabel] - If true, displays tick labels for all points.
* @param {function} params.transformLabel - Function to format the label for the ticks.
* @param {Symbols['axis']} params.axisSymbols - Symbols used for axis rendering.
* @param {boolean} [params.hasToBeMoved] - If true, indicates that the graph needs to be moved.
*/
export declare const drawTicks: ({ input, graph, plotWidth, plotHeight, axis, axisCenter, yShift, emptySymbol, debugMode, hideXAxis, expansionX, expansionY, hideYAxis, customYAxisTicks, customXAxisTicks, hideYAxisTicks, hideXAxisTicks, showTickLabel, axisSymbols, transformLabel, }: {
input: MultiLine;
graph: Graph;
plotWidth: number;
plotHeight: number;
axis: {
x: number;
y: number;
};
axisCenter?: MaybePoint;
yShift: number;
emptySymbol: string;
axisSymbols: typeof AXIS;
hideYAxis?: boolean;
hideXAxis?: boolean;
debugMode?: boolean;
expansionX: number[];
expansionY: number[];
customYAxisTicks?: number[];
customXAxisTicks?: number[];
hideYAxisTicks?: boolean;
hideXAxisTicks?: boolean;
showTickLabel?: boolean;
transformLabel: Formatter;
}) => void;
export declare const drawAxisCenter: ({ graph, realXShift, axis, debugMode, axisSymbols, emptySymbol, backgroundSymbol, }: {
graph: Graph;
axis: {
x: number;
y: number;
};
realXShift: number;
axisSymbols: typeof AXIS;
debugMode?: boolean;
emptySymbol: string;
backgroundSymbol: string;
}) => void;