@rekurt/openkline - v0.2.0
    Preparing search index...

    Class WebGLCandleRenderer

    OPTIONAL GPU-instanced renderer for the candle hot path. Draws ONLY the candle bodies + wicks via WebGL TRIANGLES; axes, grid, legend, crosshair, and everything else stay on Canvas2D. It is not wired into ChartEngine/OHLCVChart — a host opts in explicitly, layering a WebGL canvas under the existing 2D layers, so this whole module tree-shakes to zero in the base bundle.

    The expensive geometry step (buildCandleVertices) is a pure function with no GL/DOM dependency, so it is fully unit-testable; this class is the thin GL wrapper around it.

    Graceful degradation: if the browser can't give a webgl context (very old browser, blocked GPU) the constructor sets supported to false and never throws — a host checks the flag and falls back to the Canvas2D path.

    const gl = new WebGLCandleRenderer(glCanvas);
    if (gl.supported) {
    gl.resize(layout.width, layout.height);
    gl.render(view, viewport, layout, theme); // each frame
    } else {
    // fall back to the Canvas2D CandleRenderer
    }
    // on teardown
    gl.dispose();
    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    supported: boolean = false

    true when a WebGL context was acquired and the shader program linked. When false, render/resize/dispose are all safe no-ops and the host should use the Canvas2D candle path instead.

    Methods

    • Release every GL resource (buffers, program, shaders). Idempotent and safe when unsupported. After this the renderer must not be used again.

      Returns void

    • Build candle geometry for view and draw it. Uploads fresh positions/colors (DYNAMIC_DRAW — they change every frame), sets the viewport + resolution uniform, optionally clears, then issues one drawArrays(TRIANGLES, …) for the whole frame. No-op when unsupported or when there are zero visible vertices.

      Parameters

      Returns void

    • Update the cached drawable size (pixels). Call after the host resizes the GL canvas so the next render uses the right gl.viewport and pixel→clip resolution. No-op when unsupported.

      Parameters

      • width: number
      • height: number

      Returns void