94 lines
3 KiB
TypeScript
94 lines
3 KiB
TypeScript
|
|
/**
|
||
|
|
* Pure math utilities for SVG chart rendering.
|
||
|
|
* Scales, path generation, sparklines, and axis computation.
|
||
|
|
*/
|
||
|
|
export interface ChartDimensions {
|
||
|
|
width: number;
|
||
|
|
height: number;
|
||
|
|
padding: number;
|
||
|
|
chartWidth: number;
|
||
|
|
chartHeight: number;
|
||
|
|
}
|
||
|
|
export interface ScaleConfig {
|
||
|
|
min: number;
|
||
|
|
max: number;
|
||
|
|
range: number;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Calculate chart dimensions with padding
|
||
|
|
*/
|
||
|
|
export declare function calculateChartDimensions(width: number, height: number, padding: number): ChartDimensions;
|
||
|
|
/**
|
||
|
|
* Calculate scale configuration for a set of values
|
||
|
|
*/
|
||
|
|
export declare function calculateScale(values: number[], includeZero?: boolean): ScaleConfig;
|
||
|
|
/**
|
||
|
|
* Create a linear scale function
|
||
|
|
*/
|
||
|
|
export declare function createLinearScale(domain: [number, number], range: [number, number]): (value: number) => number;
|
||
|
|
/**
|
||
|
|
* Generate evenly spaced tick values
|
||
|
|
*/
|
||
|
|
export declare function generateTicks(min: number, max: number, count: number): number[];
|
||
|
|
/**
|
||
|
|
* Generate SVG path for line chart
|
||
|
|
*/
|
||
|
|
export declare function generateLinePath(points: Array<{
|
||
|
|
x: number;
|
||
|
|
y: number;
|
||
|
|
}>, curve?: boolean): string;
|
||
|
|
/**
|
||
|
|
* Generate SVG path for area under line
|
||
|
|
*/
|
||
|
|
export declare function generateAreaPath(linePath: string, firstX: number, lastX: number, baselineY: number): string;
|
||
|
|
/**
|
||
|
|
* Calculate points for a sparkline
|
||
|
|
*/
|
||
|
|
export declare function calculateSparklinePoints(data: number[], width: number, height: number): Array<{
|
||
|
|
x: number;
|
||
|
|
y: number;
|
||
|
|
}>;
|
||
|
|
/**
|
||
|
|
* Format timestamp as HH:MM:SS for chart axis labels
|
||
|
|
*
|
||
|
|
* @param timestamp - Unix timestamp in milliseconds
|
||
|
|
* @returns Formatted time string (e.g., "14:30:05")
|
||
|
|
*/
|
||
|
|
export declare function formatChartTime(timestamp: number): string;
|
||
|
|
/**
|
||
|
|
* Auto-scale configuration for Y-axis
|
||
|
|
*/
|
||
|
|
export interface AutoYScaleConfig {
|
||
|
|
/** Minimum value on the axis */
|
||
|
|
min: number;
|
||
|
|
/** Maximum value on the axis */
|
||
|
|
max: number;
|
||
|
|
/** Range (max - min) */
|
||
|
|
range: number;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Calculate auto-scaling Y-axis bounds based on visible data with padding.
|
||
|
|
* Automatically adds 10% padding above and below the data range.
|
||
|
|
*
|
||
|
|
* @param values - Array of numeric values to calculate scale for
|
||
|
|
* @param options - Optional configuration
|
||
|
|
* @param options.paddingPercent - Padding percentage (default: 0.1 = 10%)
|
||
|
|
* @param options.minPadding - Minimum padding in data units (default: 5)
|
||
|
|
* @param options.includeZero - Whether to always include zero in the scale (default: false)
|
||
|
|
* @returns Scale configuration with min, max, and range
|
||
|
|
*/
|
||
|
|
export declare function calculateAutoYScale(values: number[], options?: {
|
||
|
|
paddingPercent?: number;
|
||
|
|
minPadding?: number;
|
||
|
|
includeZero?: boolean;
|
||
|
|
}): AutoYScaleConfig;
|
||
|
|
/**
|
||
|
|
* Get color from chart series palette by index.
|
||
|
|
* Cycles through palette if index exceeds palette length.
|
||
|
|
*
|
||
|
|
* @param index - Zero-based index of the data series
|
||
|
|
* @param palette - Array of color hex strings
|
||
|
|
* @returns Hex color string
|
||
|
|
*/
|
||
|
|
export declare function getSeriesColor(index: number, palette: readonly string[]): string;
|
||
|
|
//# sourceMappingURL=chart.d.ts.map
|