/** * Clear the canvas with the current clear color * @param gl WebGL2 rendering context * @param backgroundColor Optional background color to set before clearing */ export declare function clearCanvas(gl: WebGL2RenderingContext, backgroundColor?: string | [number, number, number, number]): void; export declare class ColorRGBA { r: number; g: number; b: number; a: number; constructor(r: number, g: number, b: number, a: number); toArray(): number[]; } /** * Create a WebGL2 rendering context with common options * @param canvas HTMLCanvasElement to get context from * @param options WebGL context creation options * @returns WebGL2RenderingContext * @throws Error if WebGL2 is not supported or context creation fails */ export declare function createWebGL2Context(canvas: HTMLCanvasElement, options?: WebGL2ContextOptions): WebGL2RenderingContext; export declare type DataBounds = { minX: number; maxX: number; minY: number; maxY: number; coordinateSpace: { x: "linear" | "log"; y: "linear" | "log"; }; }; /** * Debug logging utility for webgl-plot * Provides centralized debug logging with [webglplot] prefix */ export declare class DebugLogger { private static debugEnabled; /** * Set debug mode globally */ static setDebugMode(enabled: boolean): void; /** * Get current debug mode status */ static isDebugEnabled(): boolean; /** * Debug log - only shows when debug mode is enabled */ static log(message: string): void; /** * Debug warn - only shows when debug mode is enabled */ static warn(message: string): void; /** * Error logging - always shows (not affected by debug flag) */ static error(message: string): void; } /** * Resize handler that updates both canvas and WebGL viewport * Useful for window resize events or responsive layouts * @param canvas HTMLCanvasElement to resize * @param gl WebGL2 rendering context * @param devicePixelRatio Optional device pixel ratio */ export declare function handleCanvasResize(canvas: HTMLCanvasElement, gl: WebGL2RenderingContext, devicePixelRatio?: number): void; export declare interface LineConfig { points: Float32Array; color: [number, number, number, number]; thickness?: number; scale?: [number, number]; offset?: [number, number]; enabled?: boolean; } export declare interface PolygonConfig { fillColor: [number, number, number, number]; strokeColor: [number, number, number, number]; strokeWeight: number; isFilled: boolean; isStroked: boolean; points: Float32Array; scale?: [number, number]; offset?: [number, number]; enabled?: boolean; } /** * Set the background clear color for WebGL context * @param gl WebGL2 rendering context * @param color Either: * - CSS color string in format "rgba(r, g, b, a)" where r,g,b are 0-255 and a is 0-1 * - Array of [r, g, b, a] where all values are 0-1 * - Individual RGBA values (r, g, b, a) * @example * setBackgroundColor(gl, "rgba(25, 0, 100, 1)"); * setBackgroundColor(gl, [0.1, 0, 0.4, 1]); * setBackgroundColor(gl, 0.1, 0, 0.4, 1); */ export declare function setBackgroundColor(gl: WebGL2RenderingContext, color: string | [number, number, number, number]): void; export declare function setBackgroundColor(gl: WebGL2RenderingContext, r: number, g: number, b: number, a: number): void; /** * Set up canvas with proper pixel ratio scaling * @param canvas HTMLCanvasElement to configure * @param devicePixelRatio Optional device pixel ratio, defaults to window.devicePixelRatio || 1 */ export declare function setupCanvas(canvas: HTMLCanvasElement, devicePixelRatio?: number): void; /** * Create a combined setup function that handles both canvas and WebGL context * @param canvas HTMLCanvasElement to set up * @param options Configuration options * @returns WebGL2RenderingContext ready for use */ export declare function setupCanvasAndWebGL(canvas: HTMLCanvasElement, options?: WebGL2ContextOptions & { devicePixelRatio?: number; backgroundColor?: string | [number, number, number, number]; }): WebGL2RenderingContext; /** * Transforms data bounds from log space back to linear space. * * **Usage**: Convert logarithmic coordinate bounds back to linear coordinate bounds. * This is the inverse operation of transformBoundsToLogSpace() and is used when * switching from log back to linear axes while preserving the current view. * * @param bounds Log space bounds (log₁₀ values) * @param logX Whether X bounds are currently in log₁₀ space and need conversion * @param logY Whether Y bounds are currently in log₁₀ space and need conversion * @returns Linear space bounds (values in original data units) * * @example * ```typescript * const logBounds = { minX: 0, maxX: 3, minY: -1, maxY: 2 }; * const linearBounds = transformBoundsToLinearSpace(logBounds, true, true); * // Result: { minX: 1, maxX: 1000, minY: 0.1, maxY: 100 } * ``` */ export declare function transformBoundsToLinearSpace(bounds: DataBounds, logX: boolean, logY: boolean): DataBounds; /** * Transforms data bounds from linear space to log space. * * **Usage**: Convert linear coordinate bounds to logarithmic coordinate bounds. * This is used when switching from linear to log axes or when preparing bounds * for log-space calculations. * * @param bounds Linear space bounds (values in original data units) * @param logX Whether to transform X bounds to log₁₀ space * @param logY Whether to transform Y bounds to log₁₀ space * @returns Log space bounds (log₁₀ values) or null if transformation not possible * * @example * ```typescript * const linearBounds = { minX: 1, maxX: 1000, minY: 0.1, maxY: 100 }; * const logBounds = transformBoundsToLogSpace(linearBounds, true, true); * // Result: { minX: 0, maxX: 3, minY: -1, maxY: 2 } * ``` */ export declare function transformBoundsToLogSpace(bounds: DataBounds, logX: boolean, logY: boolean): DataBounds | null; export declare class UnifiedLinePlot { private gl; private maxLines; private internalPlotter; constructor(gl: WebGL2RenderingContext, maxLines: number); /** * Initializes or re-initializes lines. Determines the internal plotter type * based on the thickness of the first line in the configuration array. * @param linesConfig Array of LineConfig objects. */ initLines(linesConfig: LineConfig[]): void; draw(): void; cleanup(): void; updateLinePoints(lineId: number, points: Float32Array): void; updateLineY(lineId: number, newY: Float32Array): void; updateLineColor(lineId: number, color: [number, number, number, number]): void; updateLineTransform(lineId: number, scale: [number, number], offset: [number, number]): void; updateLineThickness(lineId: number, thickness: number): void; setLineEnabled(lineId: number, enabled: boolean): void; /** * Enable or disable rendering for multiple lines at once. * @param lineIds Array of line IDs to enable/disable * @param enabled True to enable rendering, false to disable */ setMultipleLinesEnabled(lineIds: number[], enabled: boolean): void; /** * Update transform parameters for multiple lines at once. * @param lineIds Array of line IDs to update * @param scale Scale factors [scaleX, scaleY] * @param offset Offset values [offsetX, offsetY] */ updateMultipleLinesTransform(lineIds: number[], scale: [number, number], offset: [number, number]): void; setGlobalTransform(scale: [number, number], offset: [number, number]): void; /** * Auto-scale to fit all enabled lines in the current coordinate space. * * **IMPORTANT**: This method operates within the current coordinate space (linear or log) * and does NOT change coordinate spaces. It calculates bounds appropriate for the current * axis configuration and applies the transform. * * **Use autoScale() when:** * - Want to fit all data in the current coordinate space * - Need simple auto-scaling without changing coordinate spaces * - Don't need to preserve current zoom/pan state * * **⚠️ WARNING: Do NOT combine autoScale() with coordinate transforms!** * - autoScale() already works in the current coordinate space * - Calling transformToLogSpace() after autoScale() causes double-conversion * * **For coordinate space changes, use:** * - `transformToLogSpace()` - Switch to or operate in log space * - `transformToLinearSpace()` - Switch to or operate in linear space * * @returns DataBounds object with calculated bounds in current coordinate space, or null if no valid data * * @example * ```typescript * // ✅ CORRECT: Simple auto-scaling in current coordinate space * plotter.setLogAxis(false, true); // Enable log Y * plotter.autoScale(); // Auto-scales in log Y space - NO conversion needed! * * // ❌ WRONG: Don't combine autoScale() with coordinate transforms * // const bounds = plotter.autoScale(); * // plotter.transformToLogSpace(bounds); // This causes double-conversion! * * // ✅ CORRECT: For coordinate space conversion, use getAllDataBounds(): * // plotter.setLogAxis(false, true); // Enable log Y * // const bounds = plotter.getAllDataBounds(); // Gets linear data bounds * // if (bounds) plotter.transformToLogSpace(bounds); // Converts to log space * ``` */ autoScale(): DataBounds | null; getLineConfig(lineId: number): Partial | LineConfig | undefined; /** * Get the data bounds of the current coordinate space (viewport) with coordinate space information. * This preserves the current zoom/pan when transforming to log space. * * **ENHANCED**: This method now includes coordinate space information for each axis, * eliminating ambiguity about whether bounds are in linear or log space. * * **Use getDataBounds() when:** * - You want to preserve current zoom/pan state * - You need to know the coordinate space of the returned bounds * - Followed by transformToLogSpace() which automatically handles coordinate conversion * * @returns Object with minX, maxX, minY, maxY of the current view and coordinateSpace info, or null if no valid data * * @example * ```typescript * // Enhanced API automatically handles coordinate spaces * const bounds = plotter.getDataBounds(); // Returns bounds with coordinate space info * if (bounds) { * console.log(`X axis in ${bounds.coordinateSpace.x} space, Y axis in ${bounds.coordinateSpace.y} space`); * plotter.transformToLogSpace(bounds); // Automatically converts coordinate spaces as needed * } * * // Works seamlessly in any coordinate mode - no manual conversion needed! * ``` */ getDataBounds(): DataBounds | null; /** * Get the data bounds of all enabled lines (for autoscaling purposes) with coordinate space information. * This returns the complete extent of all data and should be used with autoScale(). * For preserving current coordinate space, use getDataBounds() instead. * * @returns Object with minX, maxX, minY, maxY of all the data and coordinateSpace info, or null if no valid data */ getAllDataBounds(): DataBounds | null; /** * Enable or disable logarithmic scaling for X and/or Y axes. * * **After calling setLogAxis(), you need to apply appropriate scaling:** * * **For view preservation (recommended):** * 1. Get current bounds: `const bounds = plotter.getDataBounds()` * 2. Convert to linear space if needed: `transformBoundsToLinearSpace(bounds, oldLogX, oldLogY)` * 3. Apply new coordinate space: `transformToLogSpace(linearBounds)` or linear transform * * **For simple auto-scaling:** * - **Enabling log axes**: Use `getAllDataBounds()` → `transformToLogSpace()` * - **Disabling log axes**: Use `autoScale()` (resets to linear) * * @param x Enable logarithmic base-10 scaling for X-axis * @param y Enable logarithmic base-10 scaling for Y-axis * * @example * ```typescript * // View preservation when toggling axes * const currentBounds = plotter.getDataBounds(); // Current coordinate space * const linearBounds = transformBoundsToLinearSpace(currentBounds, wasLogX, wasLogY); * plotter.setLogAxis(true, false); // Toggle to log X * plotter.transformToLogSpace(linearBounds); // Preserve view * * // Simple auto-scaling approach * plotter.setLogAxis(false, true); // Enable log Y * const bounds = plotter.getAllDataBounds(); * if (bounds) plotter.transformToLogSpace(bounds); * ``` */ setLogAxis(x: boolean, y: boolean): void; /** * Transform data bounds to logarithmic space and apply appropriate scaling. * * **ENHANCED**: This method now automatically handles coordinate space conversion. * It detects the coordinate space of input bounds and converts as needed. * * **Typical usage patterns:** * - **Any coordinate mode**: getDataBounds() → transformToLogSpace() (always works!) * - **Initial setup**: getAllDataBounds() → transformToLogSpace() * - **Zoom/pan operations**: getDataBounds() → transformToLogSpace() * * @param dataBounds Optional data bounds with coordinate space information. * If not provided, will attempt to get bounds from internal plotter. * @returns True if log space transformation was applied successfully, * false if transformation not feasible (e.g., no positive data for log axes) * * @example * ```typescript * // Works seamlessly in any coordinate mode * plotter.setLogAxis(false, true); // Enable log Y * const bounds = plotter.getDataBounds(); // Gets bounds with coordinate space info * const success = plotter.transformToLogSpace(bounds); // Automatically handles conversion * if (!success) console.log("Failed to transform - check for positive data"); * * // Even works when switching between coordinate spaces * // (bounds might be in log space, but transformToLogSpace handles this automatically) * const currentBounds = plotter.getDataBounds(); * plotter.transformToLogSpace(currentBounds); // Always works correctly! * ``` */ transformToLogSpace(dataBounds?: DataBounds | null): boolean; /** * Transform data bounds to linear space and apply appropriate scaling. * * **ENHANCED**: This method automatically handles coordinate space conversion. * It detects the coordinate space of input bounds and converts as needed. * * **Typical usage patterns:** * - **Switching to linear axes**: `getDataBounds()` → `transformToLinearSpace()` (preserves view) * - **Zoom/pan in linear space**: `getDataBounds()` → `transformToLinearSpace()` * - **Initial linear setup**: `getAllDataBounds()` → `transformToLinearSpace()` * * @param dataBounds Optional data bounds with coordinate space information. * If not provided, will attempt to get bounds from internal plotter. * @returns True if linear space transformation was applied successfully, * false if transformation not feasible * * @example * ```typescript * // Switching from log to linear axes while preserving view * const bounds = plotter.getDataBounds(); // Gets bounds with coordinate space info * plotter.setLogAxis(false, false); // Switch to linear axes * const success = plotter.transformToLinearSpace(bounds); // Preserves current view * * // Works seamlessly from any coordinate mode * const currentBounds = plotter.getDataBounds(); * plotter.transformToLinearSpace(currentBounds); // Always handles conversion correctly! * ``` */ transformToLinearSpace(dataBounds?: DataBounds | null): boolean; /** * Gets the type of the currently active internal plotter. * @returns A string indicating the type of the internal plotter: * 'WebglLinePlot', 'WebglLineThick', or 'null'. */ getInternalPlotterType(): "WebglLinePlot" | "WebglLineThick" | "null"; /** * Get the current global transform scale values. * @returns [scaleX, scaleY] array or [1, 1] if no plotter is initialized */ getGlobalScale(): [number, number]; /** * Get the current global transform offset values. * @returns [offsetX, offsetY] array or [0, 0] if no plotter is initialized */ getGlobalOffset(): [number, number]; } /** * Update WebGL viewport when canvas size changes * @param gl WebGL2 rendering context * @param canvas HTMLCanvasElement to get dimensions from */ export declare function updateViewport(gl: WebGL2RenderingContext, canvas: HTMLCanvasElement): void; /** * WebGL Helper Functions * * Pure utility functions for common WebGL operations that users can use * when managing their own WebGL2 context instead of using WebglPlot wrapper. */ declare type WebGL2ContextOptions = { antialias?: boolean; transparent?: boolean; powerPerformance?: "default" | "high-performance" | "low-power"; deSync?: boolean; preserveDrawing?: boolean; }; /** * The standard Line class */ export declare class WebglAux { private lines; private gl; private coord; private vbuffer; prog: WebGLProgram; constructor(gl: WebGL2RenderingContext); addLine(line: WebglLine): void; draw(): void; } declare namespace WebGLHelpers { export { setupCanvas, createWebGL2Context, setBackgroundColor, clearCanvas, updateViewport, setupCanvasAndWebGL, handleCanvasResize, WebGL2ContextOptions } } export { WebGLHelpers } /** * @deprecated Use WebglLinePlot instead. */ export declare class WebglLine { xy: number[]; color: ColorRGBA; constructor(xy?: number[], color?: ColorRGBA); getSize(): number; setY(y: number): void; setYs(ys: number[]): void; setXYArray(xy: number[]): void; setX(x: number): void; lineSpaceX(lineSize: number): void; emptyLine(lineSize: number): void; setColor(color: ColorRGBA): void; } export declare class WebglLinePlot { private gl; private maxLines; private linesConfig; private numLines; private vertexBuffer; private colorBuffer; prog: WebGLProgram | null; private lineStarts; private lineLengths; private globalScale; private globalOffset; private locations; logX: boolean; logY: boolean; constructor(gl: WebGL2RenderingContext, maxLines: number); private _createShaderProgram; initLines(linesConfig: LineConfig[]): void; cleanup(): void; updateLinePoints(lineId: number, points: Float32Array): void; updateLineY(lineId: number, newY: Float32Array): void; updateLineColor(lineId: number, color: [number, number, number, number]): void; updateLineTransform(lineId: number, scale: [number, number], offset: [number, number]): void; /** * Update the thickness for a specific line. * @param lineId ID of the line to update * @param thickness New thickness value for the line */ updateLineThickness(lineId: number, thickness: number): void; /** * Enable or disable rendering for a specific line. * @param lineId ID of the line to enable/disable * @param enabled True to enable rendering, false to disable */ setLineEnabled(lineId: number, enabled: boolean): void; /** * Enable or disable rendering for multiple lines at once. * @param lineIds Array of line IDs to enable/disable * @param enabled True to enable rendering, false to disable */ setMultipleLinesEnabled(lineIds: number[], enabled: boolean): void; /** * Update transform parameters for multiple lines at once. * @param lineIds Array of line IDs to update * @param scale Scale factors [scaleX, scaleY] * @param offset Offset values [offsetX, offsetY] */ updateMultipleLinesTransform(lineIds: number[], scale: [number, number], offset: [number, number]): void; /** * Set the global transformation matrix for the plot. * @param scale Global scale factors [scaleX, scaleY] * @param offset Global offset values [offsetX, offsetY] */ setGlobalTransform(scale: [number, number], offset: [number, number]): void; /** * Enable or disable logarithmic scaling for X and/or Y axes. * * When enabled, coordinates are transformed using log₁₀ on the GPU in real-time. * Negative and zero values are automatically filtered out (moved off-screen). * * **Important Notes:** * - Transformation happens on GPU for optimal performance * - No graph reinitialization required - changes apply immediately * - Auto-scaling will automatically account for log transformation * * **Example Usage:** * ```typescript * // Enable log Y-axis for exponential data * thinPlotter.setLogAxis(false, true); * * // Enable both axes for power-law data * thinPlotter.setLogAxis(true, true); * * // Disable all log scaling * thinPlotter.setLogAxis(false, false); * ``` * * @param x Enable logarithmic base-10 scaling for X-axis * @param y Enable logarithmic base-10 scaling for Y-axis */ setLogAxis(x: boolean, y: boolean): void; /** * Auto-scale the plotter to fit log-transformed data, using either actual data bounds * or converting existing transform-based viewport bounds to log space. * * This function intelligently handles the transition from linear to log space by * using actual data bounds when provided, or falling back to transforming the * current viewport bounds from linear to log space. * * **Use Cases:** * - After toggling log axes to maintain current view * - For smooth transitions between linear and log representations * - When you want to preserve user's current zoom/pan state * - For accurate scaling based on actual data bounds * * **Example Usage:** * ```typescript * // Preserve current coordinate space (recommended for maintaining zoom/pan) * const bounds = thinPlotter.getDataBounds(); * thinPlotter.transformToLogSpace(bounds); * * // Alternative: same result, preserves current coordinate space * thinPlotter.transformToLogSpace(); * ``` * * @param dataBounds Optional actual data bounds {minX, maxX, minY, maxY}. * If provided, uses actual data bounds instead of transform-based bounds. * @returns True if smart scaling was applied, false if transformation not feasible */ transformToLogSpace(dataBounds?: DataBounds | null): boolean; /** * Transform data bounds to linear space and apply appropriate scaling. * * **ENHANCED**: This method automatically handles coordinate space conversion. * It detects the coordinate space of input bounds and converts as needed. * * **Typical usage patterns:** * - **Switching to linear axes**: `getDataBounds()` → `transformToLinearSpace()` (preserves view) * - **Zoom/pan in linear space**: `getDataBounds()` → `transformToLinearSpace()` * - **Initial linear setup**: `getAllDataBounds()` → `transformToLinearSpace()` * * @param dataBounds Optional data bounds with coordinate space information. * If not provided, will attempt to get bounds from current transform. * @returns True if linear space transformation was applied successfully, * false if transformation not feasible * * @example * ```typescript * // Switching from log to linear axes while preserving view * const bounds = plotter.getDataBounds(); // Gets bounds with coordinate space info * plotter.setLogAxis(false, false); // Switch to linear axes * const success = plotter.transformToLinearSpace(bounds); // Preserves current view * * // Works seamlessly from any coordinate mode * const currentBounds = plotter.getDataBounds(); * plotter.transformToLinearSpace(currentBounds); // Always handles conversion correctly! * ``` */ transformToLinearSpace(dataBounds?: DataBounds | null): boolean; /** * Get the data bounds of all enabled lines (for autoscaling purposes). * This returns the complete extent of all data and should be used with autoScale(). * For preserving current coordinate space, use getDataBounds() instead. * @returns Object with minX, maxX, minY, maxY of all the data, or null if no valid data */ getAllDataBounds(): DataBounds | null; /** * Get the data bounds of the current coordinate space (viewport). * This preserves the current zoom/pan when transforming to log space. * Use this with transformToLogSpace() to maintain user's coordinate space. * @returns Object with minX, maxX, minY, maxY of the current view with coordinate space information, or null if invalid transform */ getDataBounds(): DataBounds | null; /** * Auto-scale to fit all enabled lines in the current coordinate space. * * **IMPORTANT**: This method operates within the current coordinate space (linear or log) * and does NOT change coordinate spaces. It calculates bounds appropriate for the current * axis configuration and applies the transform. * * **Use autoScale() when:** * - Want to fit all data in the current coordinate space * - Need simple auto-scaling without changing coordinate spaces * - Don't need to preserve current zoom/pan state * * **⚠️ WARNING: Do NOT combine autoScale() with coordinate transforms!** * - autoScale() already works in the current coordinate space * - Calling transformToLogSpace() after autoScale() causes double-conversion * * **For coordinate space changes, use:** * - `transformToLogSpace()` - Switch to or operate in log space * - `transformToLinearSpace()` - Switch to or operate in linear space * * @returns DataBounds object with calculated bounds in current coordinate space, or null if no valid data * * @example * ```typescript * // ✅ CORRECT: Simple auto-scaling in current coordinate space * plotter.setLogAxis(false, true); // Enable log Y * plotter.autoScale(); // Auto-scales in log Y space - NO conversion needed! * * // ❌ WRONG: Don't combine autoScale() with coordinate transforms * // const bounds = plotter.autoScale(); * // plotter.transformToLogSpace(bounds); // This causes double-conversion! * * // ✅ CORRECT: For coordinate space conversion, use getAllDataBounds(): * // plotter.setLogAxis(false, true); // Enable log Y * // const bounds = plotter.getAllDataBounds(); // Gets linear data bounds * // if (bounds) plotter.transformToLogSpace(bounds); // Converts to log space * ``` */ autoScale(): DataBounds | null; draw: () => void; /** * Gets the configuration for a specific line. * @param lineId The ID of the line. * @returns The LineConfig object or undefined if not found. */ getLineConfig(lineId: number): LineConfig | undefined; /** * Get the current global transform scale values. * @returns [scaleX, scaleY] array */ getGlobalScale(): [number, number]; /** * Get the current global transform offset values. * @returns [offsetX, offsetY] array */ getGlobalOffset(): [number, number]; } export declare class WebglLineRoll { private gl; private aPositionLocation; private vertexBuffer; program: WebGLProgram; rollBufferSize: number; private shift; private dataIndex; private dataX; private lastDataX; private lastDataY; numLines: number; private filled; private ext; private colorBuffer; private aColorLocation; private uShiftLocation; private uploadScratch; private bridgeScratch; private multiFirsts; private multiCounts; constructor(gl: WebGL2RenderingContext, rollBufferSize: number, numLines: number); addPoint(ys: number[]): void; addPoints(ys: ReadonlyArray>): void; private drawOld; private drawExt; draw(): void; setLineColor(colors: ColorRGBA, lineIndex: number): void; } export declare class WebglLineThick { private gl; prog: WebGLProgram | null; private maxLines; private pointsTexture; private vao; private vertexBuffer; private locations; private lineDataUBO; private lineDataUBObindingPoint; private lineDataStride; private lineDataArrayBuffer; private lineDataView; private reusableFloat32Array4; private reusableInt32Array1; private globalTransformDirty; private totalVertexCount; private numLines; private totalValidPoints; private pointsData; private texWidth; private texHeight; private lineOriginalNumPointsCache; private lineStartIndexCache; private lineEnabledStatus; private sharpTurnCache; private pointsHashCache; private globalScale; private globalOffset; logX: boolean; logY: boolean; /** * Creates an instance of WebglLineThick. * @param gl WebGL2 rendering context. * @param maxLines Maximum number of lines this instance can handle. */ constructor(gl: WebGL2RenderingContext, maxLines: number); /** * Initializes or updates line data, including points texture, VBO, UBO, * and potentially GPU reduction resources. * @param lines An array of line objects to draw. */ initLines(lines: LineConfig[]): void; /** * Sets the global scale and offset applied AFTER per-line transforms. * @param scale Tuple `[scaleX, scaleY]`. * @param offset Tuple `[offsetX, offsetY]`. */ setGlobalTransform(scale: [number, number], offset: [number, number]): void; /** * Get the data bounds of all enabled lines (for autoscaling purposes). * This returns the complete extent of all data and should be used with autoScale(). * For preserving current coordinate space, use getDataBounds() instead. * @returns Object with minX, maxX, minY, maxY of all the data, or null if no valid data */ getAllDataBounds(): DataBounds | null; /** * Get the data bounds of the current coordinate space (viewport). * This preserves the current zoom/pan when transforming to log space. * Use this with transformToLogSpace() to maintain user's coordinate space. * @returns Object with minX, maxX, minY, maxY of the current view with coordinate space information, or null if invalid transform */ getDataBounds(): DataBounds | null; /** * Computes the min/max bounds of enabled lines using CPU iteration. * Internal method. * @returns DataBounds object or null if no enabled lines with points found. */ private _computeBoundsCPU; /** * Auto-scale to fit all enabled lines in the current coordinate space. * * **IMPORTANT**: This method operates within the current coordinate space (linear or log) * and does NOT change coordinate spaces. It calculates bounds appropriate for the current * axis configuration and applies the transform. * * **Use autoScale() when:** * - Want to fit all data in the current coordinate space * - Need simple auto-scaling without changing coordinate spaces * - Don't need to preserve current zoom/pan state * * **⚠️ WARNING: Do NOT combine autoScale() with coordinate transforms!** * - autoScale() already works in the current coordinate space * - Calling transformToLogSpace() after autoScale() causes double-conversion * * **For coordinate space changes, use:** * - `transformToLogSpace()` - Switch to or operate in log space * - `transformToLinearSpace()` - Switch to or operate in linear space * * @returns DataBounds object with calculated bounds in current coordinate space, or null if no valid data * * @example * ```typescript * // ✅ CORRECT: Simple auto-scaling in current coordinate space * plotter.setLogAxis(false, true); // Enable log Y * plotter.autoScale(); // Auto-scales in log Y space - NO conversion needed! * * // ❌ WRONG: Don't combine autoScale() with coordinate transforms * // const bounds = plotter.autoScale(); * // plotter.transformToLogSpace(bounds); // This causes double-conversion! * * // ✅ CORRECT: For coordinate space conversion, use getAllDataBounds(): * // plotter.setLogAxis(false, true); // Enable log Y * // const bounds = plotter.getAllDataBounds(); // Gets linear data bounds * // if (bounds) plotter.transformToLogSpace(bounds); // Converts to log space * ``` */ autoScale(): DataBounds | null; /** * Computes sharp turn detection for a line with caching and optimizations. * @param lineId Line identifier * @param pointsArray Points array for the line * @param numPts Number of points in the line * @returns Boolean array indicating sharp turns for each point */ private computeSharpTurns; /** * Helper to setup vertex attributes with error handling. * @param attributes Array of attribute configurations * @param stride Vertex stride in bytes */ private setupVertexAttributes; /** * Generic helper to update UBO data and sync with GPU buffer. * @param byteOffsets Array of byte offsets to update * @param dataViews Array of typed array views containing the data */ private updateUBOData; /** * Updates the per-line transform (scale and offset) for multiple lines using UBO updates. */ updateLinesTransform(lineIds: number[], scale: [number, number], offset: [number, number]): void; /** * Updates the per-line transform for a specific line. */ updateLineTransform(lineId: number, scale: [number, number], offset: [number, number]): void; /** * Updates the color for a specific line. */ updateLineColor(lineId: number, color: [number, number, number, number]): void; /** * Updates the thickness for a specific line. */ updateLineThickness(lineId: number, newThickness: number): void; /** * Enables or disables rendering of specific lines. */ setLinesEnabled(lineIds: number[], enabled: boolean): void; /** * Enables or disables rendering of a single line. */ setLineEnabled(lineId: number, enabled: boolean): void; /** * Enable or disable logarithmic scaling for X and/or Y axes. * * When enabled, coordinates are transformed using log₁₀ on the GPU in real-time. * Negative and zero values are automatically filtered out (moved off-screen). * * **Important Notes:** * - Transformation happens on GPU for optimal performance * - No graph reinitialization required - changes apply immediately * - Auto-scaling will automatically account for log transformation * * **Example Usage:** * ```typescript * // Enable log Y-axis for exponential data * thickPlotter.setLogAxis(false, true); * * // Enable both axes for power-law data * thickPlotter.setLogAxis(true, true); * * // Disable all log scaling * thickPlotter.setLogAxis(false, false); * ``` * * @param x Enable logarithmic base-10 scaling for X-axis * @param y Enable logarithmic base-10 scaling for Y-axis */ setLogAxis(x: boolean, y: boolean): void; /** * Auto-scale the plotter to fit log-transformed data, using either actual data bounds * or converting existing transform-based viewport bounds to log space. * * This function intelligently handles the transition from linear to log space by * using actual data bounds when provided, or falling back to transforming the * current viewport bounds from linear to log space. * * **Use Cases:** * - After toggling log axes to maintain current view * - For smooth transitions between linear and log representations * - When you want to preserve user's current zoom/pan state * - For accurate scaling based on actual data bounds * * **Example Usage:** * ```typescript * // Preserve current coordinate space (recommended for maintaining zoom/pan) * const bounds = thickPlotter.getDataBounds(); * thickPlotter.transformToLogSpace(bounds); * * // Alternative: same result, preserves current coordinate space * thickPlotter.transformToLogSpace(); * ``` * * @param dataBounds Optional actual data bounds {minX, maxX, minY, maxY}. * If provided, uses actual data bounds instead of transform-based bounds. * @returns True if smart scaling was applied, false if transformation not feasible */ transformToLogSpace(dataBounds?: DataBounds | null): boolean; /** * Transform data bounds to linear space and apply appropriate scaling. * * **ENHANCED**: This method automatically handles coordinate space conversion. * It detects the coordinate space of input bounds and converts as needed. * * **Typical usage patterns:** * - **Switching to linear axes**: `getDataBounds()` → `transformToLinearSpace()` (preserves view) * - **Zoom/pan in linear space**: `getDataBounds()` → `transformToLinearSpace()` * - **Initial linear setup**: `getAllDataBounds()` → `transformToLinearSpace()` * * @param dataBounds Optional data bounds with coordinate space information. * If not provided, will attempt to get bounds from current transform. * @returns True if linear space transformation was applied successfully, * false if transformation not feasible * * @example * ```typescript * // Switching from log to linear axes while preserving view * const bounds = plotter.getDataBounds(); // Gets bounds with coordinate space info * plotter.setLogAxis(false, false); // Switch to linear axes * const success = plotter.transformToLinearSpace(bounds); // Preserves current view * * // Works seamlessly from any coordinate mode * const currentBounds = plotter.getDataBounds(); * plotter.transformToLinearSpace(currentBounds); // Always handles conversion correctly! * ``` */ transformToLinearSpace(dataBounds?: DataBounds | null): boolean; /** * Updates only the Y coordinates of the points for a given line. */ updateLineY(lineId: number, newY: Float32Array): void; /** * Helper method to update texture data row by row. * @param gl WebGL context * @param startIdx Starting global point index * @param numPts Number of points to update */ private updateTextureByRows; /** * Draws the lines managed by this instance. */ draw(): void; /** * Releases all WebGL resources allocated by this instance. */ cleanup(): void; /** * Gets the configuration for a specific line by reading from the UBO data view. * Note: This returns a partial LineConfig as not all original data might be stored or easily retrievable. * Specifically, 'points' are on the GPU texture and not returned here. * @param lineId The ID of the line. * @returns A Partial object or undefined if not found or UBO not ready. */ getLineConfig(lineId: number): Partial | undefined; /** * Get the current global transform scale values. * @returns [scaleX, scaleY] array */ getGlobalScale(): [number, number]; /** * Get the current global transform offset values. * @returns [offsetX, offsetY] array */ getGlobalOffset(): [number, number]; } export declare class WebglPlot { readonly gl: WebGL2RenderingContext; gScaleX: number; gScaleY: number; gOffsetX: number; gOffsetY: number; logX: boolean; logY: boolean; debug: boolean; constructor(canvas: HTMLCanvasElement, options?: { antialias?: boolean; powerPerformance?: "default" | "high-performance" | "low-power"; backgroundColor?: [number, number, number, number]; debug?: boolean; }); clear(): void; update(): void; newUnifiedLinePlotter(maxLines: number): UnifiedLinePlot; newThinLinePlotter(maxLines: number): WebglLinePlot; newThickLinePlotter(maxLines: number): WebglLineThick; } export declare class WebglPolygonPlot { private gl; private prog; private strokeProg; private fillVAO; private strokeVAO; private uniformLocations; private strokeUniformLocations; polygonsConfig: PolygonConfig[]; numPolygons: number; private vertexBuffer; private strokeVertexBuffer; private polygonStarts; private polygonLengths; private strokePolygonStarts; private strokePolygonLengths; private cachedState; private tempArrays; constructor(gl: WebGL2RenderingContext); initPolygons(polygonsConfig: PolygonConfig[]): void; cleanup(): void; updatePolygonPoints(polygonId: number, points: Float32Array): void; updatePolygonTransform(polygonId: number, scale: [number, number], offset: [number, number]): void; updatePolygonStyle(polygonId: number, style: Partial>): void; setPolygonEnabled(polygonId: number, enabled: boolean): void; setGlobalTransform(scale: [number, number], offset: [number, number]): void; draw(): void; private _getUniformLocations; private _setupViewportTracking; private _updateViewportIfChanged; private _normalizePolygonConfig; private _validatePolygonId; private _setupFillVAO; private _setupStrokeVAO; private _regeneratePolygonStroke; private _generateStrokeGeometry; private _createShaderProgram; private _compileShader; static createTriangle(config: { center: [number, number]; radius: number; rotation?: number; fillColor?: [number, number, number, number]; strokeColor?: [number, number, number, number]; strokeWeight?: number; isFilled?: boolean; isStroked?: boolean; scale?: [number, number]; offset?: [number, number]; enabled?: boolean; }): PolygonConfig; static createSquare(config: { center: [number, number]; size: number; rotation?: number; fillColor?: [number, number, number, number]; strokeColor?: [number, number, number, number]; strokeWeight?: number; isFilled?: boolean; isStroked?: boolean; scale?: [number, number]; offset?: [number, number]; enabled?: boolean; }): PolygonConfig; static createCircle(config: { center: [number, number]; radius: number; segments?: number; fillColor?: [number, number, number, number]; strokeColor?: [number, number, number, number]; strokeWeight?: number; isFilled?: boolean; isStroked?: boolean; scale?: [number, number]; offset?: [number, number]; enabled?: boolean; }): PolygonConfig; } /** * The standard Line class */ export declare class WebglScatterAcc { private headIndex; private color; private squareSize; private maxSquare; private gl; private squareIndices; private colorsBuffer; private positionBuffer; prog: WebGLProgram; private attrPosLocation; private attrColorLocation; constructor(gl: WebGL2RenderingContext, maxSquare: number); setColor(color: ColorRGBA): void; setSquareSize(squareSize: number): void; setScale(scaleX: number, scaleY: number): void; setOffset(offsetX: number, offsetY: number): void; addSquare(pos: Float32Array, color: Uint8Array): void; draw(): void; } export { }