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

    Class ChartEngine

    Index

    Constructors

    Properties

    goToLiveRenderer: GoToLiveRenderer = ...
    viewport: Viewport

    Accessors

    • get themeBackground(): string

      The active theme's background color. Exposed so the off-screen SVG export (chartEngineToSVG) can paint a guaranteed full-bleed backdrop matching the on-screen chart. Read-only — set the theme via setTheme.

      Returns string

    Methods

    • Called by PanZoomController on mousedown/mouseup so the engine knows whether to honor setIdleCursor writes or defer them. Internal API, not exported.

      Parameters

      • dragging: boolean

      Returns void

    • Detach a primitive by id. Returns true if one was removed.

      Parameters

      • id: string

      Returns boolean

    • The current replay cap (virtual buffer end), or null when not replaying.

      Returns number | null

    • Topmost primitive whose hitTest passes at (x, y) in CSS pixels, searched in reverse paint order (last attached wins). Used to route drags to draggable price lines.

      Parameters

      • x: number
      • y: number
      • Optionaltolerance: number

      Returns Primitive | null

    • Highest buffer index currently visible to the user — effectiveLength - 1 (or -1 on an empty buffer). Equals the last buffer index when no replay cap is active. Consumers that resolve a pointer / visible-range index into a candle (click, range callbacks, markers, crosshair) must clamp to this so replay never leaks a not-yet-revealed (future) bar.

      Returns number

    • Render the chart layer into a caller-supplied 2D-context-like sink — the seam the vector SVG export (chartEngineToSVG) renders through.

      Runs the exact same per-frame geometry pipeline as a real render (visible window, non-uniform coordinate mapping, autoscale, left-scale extent, conflation) and then paints the chart layer via _paintChartLayer, so the SVG matches what's on screen. It does NOT touch the live canvases, dirty flags, or the UI/crosshair layers — it's a pure read of current state into the passed ctx.

      Kept dependency-free (no SVG-shim import here) so it adds nothing to the base bundle; the shim lives in the separately-imported export module. No-ops when no buffer is set.

      Parameters

      • ctx: CanvasRenderingContext2D

      Returns void

    • Drop the resting-legend index. The index is absolute, so after a buffer eviction shifts every index the chart must re-derive it on the next hover rather than show the (now wrong) candle for a frame.

      Returns void

    • Switch the primary price-series rendering style (built-in or custom).

      Parameters

      • chartType: string

      Returns void

    • Update crosshair position

      Parameters

      • x: number
      • y: number
      • snapIndex: number
      • candle: Candle | null
      • timeLabel: string

      Returns void

    • Attach a DrawingLayer whose drawings will be rendered on top of the price area. Pass null to detach. The chart takes no input events for the drawing layer — consumers listen on topCanvas and drive creation via layer.addPoint(...) themselves.

      Parameters

      Returns void

    • Install the localization bundle (C6). Updates the canvas aria-label immediately and requests a render so legend labels / the go-to-live pill pick up the new strings. Passing the result of a no-locale createI18n() restores the default English, locale-agnostic behavior.

      Host-supplied priceFormat / volumeFormat still take priority over the bundle's locale-aware number formatters (see _legendPriceFormat etc.) — i18n only fills in where the host hasn't overridden formatting.

      Parameters

      Returns void

    • Override the resting cursor on the top canvas. Used by drawing tools in consumer code to signal "click to place a point" — e.g. 'crosshair' for selection, 'cell' or 'copy' while a trend line is being drawn.

      PanZoomController still temporarily switches to 'grabbing' during an active drag and back to the idle cursor on release, so mouse-up after a drag does not clobber the tool's cursor choice.

      Pass null to restore the default 'crosshair'.

      Parameters

      • cursor: string | null

      Returns void

    • Replace the indicator set. Indicators with placement: 'overlay' are drawn on top of the price series in deterministic palette order. Indicators with placement: 'pane' are not yet rendered (pane layout integration is a future phase) — they still compute their values, which is useful for code paths that want to read getIndicatorSeries(id) without rendering.

      Parameters

      Returns void

    • Parameters

      • Optionalfn: (price: number) => string

      Returns void

    • Set the replay-mode virtual buffer end (C1), or null to disable replay and render the full buffer again. A non-null cap is clamped into [1, buffer.length] so the renderer always has at least one — and never more than the real number of — candles to show. Passing null is the default-equivalent state; the next render is bit-for-bit identical to a chart that never entered replay.

      Does not itself request a render — the caller (ReplayController) decides when to repaint so a seek+render is a single frame.

      Parameters

      • cap: number | null

      Returns void

    • Parameters

      • Optionalfn: (price: number) => string

      Returns void

    • Snapshot the current chart state as a flat PNG data URL. Composites all three canvas layers onto a single offscreen canvas so the result is independent of DOM state.

      Synchronous. Returns a data:image/png;base64,... string suitable for <img src>, download links, or uploading to a backend. Returns null if the browser refuses to provide a 2D context on the offscreen canvas (should never happen outside of sandboxed iframes).

      Returns string | null

    • Zero-copy slice of the candles currently inside the visible window [startIndex, startIndex + visibleCount), clamped to the effective (replay-capped) buffer end and EXCLUDING the +1 render-only bar — so it matches the bars the user actually sees. Returns null when no buffer is set or the window is empty.

      This is the seam an optional, attach-only overlay (C4 Volume Profile) reads its source data through without ever importing the buffer: the controller holds a () => engine.visibleCandleView() closure and the primitive folds the returned typed arrays into price bins. Tiny + buffer-delegating, so it adds nothing meaningful to the base bundle (the profile module itself is never statically imported here, so it tree-shakes out).

      Returns CandleView | null