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

    Class OHLCVChart

    Index

    Constructors

    Methods

    • Add a price alert (C3). Returns the created Alert (with its generated a_<n> id and resolved condition). An active alert is drawn as a dashed amber price line; it fires once on the realtime close-price tick that satisfies its condition, invoking ChartConfig.onAlert and removing its line (one-shot — see removeAlert / re-add to re-arm). Alerts are included in saveLayoutState.

      Parameters

      Returns Alert

    • Attach a programmatic overlay primitive (watermark, price line, custom band) rendered at its z-tier. Primitives are runtime annotations — they are not included in saveLayoutState.

      Parameters

      Returns void

    • Remove every alert and its price line.

      Returns void

    • Remove every drawing from the auto-managed layer.

      Returns void

    • Remove the watermark, if one is set.

      Returns void

    • Create a horizontal price line at a fixed price, with a right-axis label pill, optionally draggable. Returns a handle to move/restyle/remove it. Correct under any price-scale mode (positions via the viewport). Price lines are runtime-only — not included in saveLayoutState.

      Parameters

      Returns PriceLineHandle

    • Delete the selected drawing, if any. Returns true if one was removed.

      Returns boolean

    • Clean up all resources. Idempotent — safe to call more than once.

      Returns void

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

      Parameters

      • id: string

      Returns boolean

    • Zoom out so the entire buffer is visible at once, from the start.

      Returns void

    • Reset zoom to the default candleWidth and go to live.

      Returns void

    • Access the chart's auto-managed DrawingLayer. Returns the same instance that startDrawing / getDrawings / loadDrawings operate on, unless the host replaced it via setDrawingLayer.

      Returns DrawingLayer

    • Read the indicator configs last passed through setIndicatorConfigs. Returns an empty array if the host used the legacy setIndicators(Indicator[]) path — in that case the chart has no way to reverse-engineer configs from arbitrary Indicator subclasses.

      Returns readonly IndicatorConfig[]

    • Id of the currently-selected drawing, or null.

      Returns string | null

    • Scroll to the live edge and resume following new candles.

      Returns void

    • True while replay mode is engaged (a virtual buffer cap is active).

      Returns boolean

    • Replace all drawings with a fresh snapshot list. Unknown drawing kinds are silently skipped (same semantics as DrawingLayer.fromSnapshot).

      Parameters

      Returns void

    • Restore chart state from a previously saved layout or full state. Accepts both LayoutState and FullState — when data is present it is loaded via setData, otherwise the current buffer is preserved and only the visual/interaction layer is updated.

      Throws ValidationError on unknown schema version.

      Restore order is critical — changing it can leave the viewport clamped, indicators stale, or a rogue paint frame rendered against the wrong chartType. See the M1 spec for the rationale.

      Parameters

      Returns void

    • Pause automatic replay playback.

      Returns void

    • Prepend older candles to the buffer without resetting the viewport. Call this from your onLoadMoreHistory handler when you've fetched more historical data. The user's current startIndex is shifted by the number of candles that were actually added, so visually the same candles stay under the cursor.

      Parameters

      Returns void

    • Redo the last undone drawing mutation. Returns true if applied.

      Returns boolean

    • Register a custom primary-series type as a first-class citizen — it participates in autoscale (via its priceRange), conflation, and the crosshair. Use setChartType(def.type) to activate it. Register before loadState if a saved chart references the custom type (otherwise the load falls back to candles at render time).

      Parameters

      Returns void

    • Remove an alert by id (and its price line). Returns true if removed.

      Parameters

      • id: string

      Returns boolean

    • Remove a marker by id. Returns true if one was removed.

      Parameters

      • id: string

      Returns boolean

    • Serialize the chart including the full data window. Use for workspace persistence or bug reproduction where the recipient should not need a transport to rehydrate. Typical size ranges from 100 KB to 1 MB depending on buffer length.

      Returns FullState

    • Serialize the chart's layout (without data) to a JSON-safe object. The result is small enough to round-trip through a URL query parameter after base64 encoding — typical size is a few hundred bytes. Use saveFullState when you also need the data window.

      getIndicatorConfigs() returns an empty array if the host used the legacy setIndicators(Indicator[]) path — save/load then round-trips visual state but not indicators. Prefer setIndicatorConfigs for framework wrappers.

      Returns LayoutState

    • Jump replay to a specific bar index (clamped into range).

      Parameters

      • index: number

      Returns void

    • Select a drawing by id, or clear the selection with null.

      Parameters

      • id: string | null

      Returns void

    • Hit-test the auto-managed drawings at a canvas point (in CSS pixels relative to the chart container) and select the topmost match — or clear the selection if nothing is hit. Returns the selected drawing's id, or null. Wire this to a click/pointerdown handler.

      Parameters

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

      Returns string | null

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

      Parameters

      Returns void

    • Switch crosshair mode at runtime: 'normal' (free Y) or 'magnet' (snap Y to the nearest OHLC level of the candle under the cursor).

      Parameters

      Returns void

    • Set data directly (without transport).

      By default, fully resets the buffer and scrolls the viewport to the live edge — the correct behavior when the user has just switched symbols or timeframes.

      Pass { preserveView: true } to keep the viewport's current startIndex, candleWidth, and autoFollow state. This is what framework wrappers (React/Vue) want when they re-dispatch the same data array as a prop change: the user's pan/zoom position should not jump to the right edge every time React re-renders.

      Parameters

      • candles: Candle[]
      • Optionalopts: { preserveView?: boolean }

      Returns void

    • Replace the horizontal-scale behavior, controlling how the X axis is labeled — time (default), price/strike (options charts), or custom. Note: the crosshair X-label still uses the time formatter for now.

      Parameters

      Returns void

    • Override the resting cursor on the top canvas. Drawing tools use this to give the user visual feedback that a tool is selected — e.g. 'cell' for "click to place a point", or 'copy' for a ray tool. Pass null to restore the default 'crosshair'.

      Parameters

      • cursor: string | null

      Returns void

    • Replace the indicator set using declarative configs. This is the recommended path for React/Vue wrappers: the chart remembers the configs so saveLayoutState() can round-trip them without the wrapper having to track indicators out-of-band.

      Parameters

      Returns void

    • Replace the indicator set on the chart with pre-constructed instances.

      Advanced use only — most hosts should call setIndicatorConfigs instead so the chart can serialize the indicators through saveLayoutState. Calling this method clears the internal IndicatorConfig[] mirror, so subsequent saveLayoutState calls will return indicators: [] even though the chart is still rendering them.

      Parameters

      Returns void

    • Switch localization at runtime (C6): rebuilds the i18n bundle from the given BCP-47 locale (or undefined for the locale-agnostic defaults) and optional messages overrides, updating the aria-label, axis number/date formatting, legend, and pills, then repaints. Pass no args to reset to the English, locale-agnostic baseline.

      Parameters

      • Optionallocale: string
      • Optionalmessages: Partial<Messages>

      Returns void

    • Replace all candle-anchored markers (buy/sell arrows, event flags). Markers are pinned by time, so they survive history loads and maxCandles eviction. Markers are runtime annotations — they are not included in saveLayoutState; persist them yourself if needed.

      Parameters

      Returns void

    • Install a double-click callback that fires with the HoverInfo for the cursor position (or null outside the plot). Additive — the chart's built-in double-click reset (fit-visible / reset price scale) still runs.

      Parameters

      • handler: ((info: HoverInfo | null) => void) | null

      Returns void

    • Install a hover callback that fires on every crosshair snap.

      Parameters

      • handler: ((info: HoverInfo | null) => void) | null

      Returns void

    • Switch the price-axis scale mode:

      • 'linear' — equal price deltas are equal pixel deltas (default)
      • 'log' — equal ratios are equal pixel deltas (BTC-over-years)
      • 'percentage' — axis reads % change vs. the first visible candle
      • 'indexedTo100' — first visible candle anchored at 100

      Clears any manual (dragged) price scale so the new mode auto-fits.

      Parameters

      Returns void

    • Set replay playback speed in bars per second.

      Parameters

      • bps: number

      Returns void

    • Set (or replace) a faint background watermark — text (symbol/timeframe) or an image (logo), painted behind the grid and series. Runtime-only; not included in saveLayoutState.

      Parameters

      Returns void

    • Begin an interactive drawing workflow. The next click event routed through the host's click handler should call drawingLayer.addPoint({ index, price }). When the drawing completes (enough anchors), it is finalized automatically.

      Supported tools (see DrawingTool):

      • trendline (2 points)
      • hline (1 point — horizontal price line)
      • vline (1 point — vertical index line)
      • rectangle (2 points — diagonal corners)
      • ray (2 points — semi-infinite line)
      • fib (2 points — Fibonacci retracement levels)
      • fibext (3 points — Fibonacci extension targets)
      • channel (3 points — equidistant channel)
      • arrow (2 points — arrow segment)
      • parallelchannel (3 points — bounded parallel channel)
      • regression (2 points — least-squares channel ±2σ over the span)
      • pitchfork (3 points — Andrews' pitchfork)
      • fibfan (2 points — Fibonacci fan rays)
      • measure (2 points — price/percent/bar ruler)

      Parameters

      Returns void

    • Enter bar-by-bar replay mode (C1), revealing history up to fromIndex (default 0 — start from the first bar). The chart then shows only the revealed prefix; advance with playReplay/stepReplay or jump with seekReplay. Leave replay with stopReplay.

      Parameters

      • OptionalfromIndex: number

      Returns void

    • Reveal/hide one replay bar (forward default true).

      Parameters

      • Optionalforward: boolean

      Returns void

    • Leave replay mode: clears the virtual buffer cap so the full buffer renders again, stops playback, and repaints. Safe to call when not in replay (no-ops the cap clear).

      Returns void

    • Switch to a different symbol/resolution

      Parameters

      • symbol: string
      • resolution: string

      Returns Promise<void>

    • Snapshot the chart as a PNG data URL. Returns null if the browser cannot provide a 2D context (sandboxed iframe).

      Returns string | null

    • Undo the last drawing add/remove/clear. Returns true if applied.

      Returns boolean

    • Zero-copy view over the candles currently in the visible window (excludes the +1 render-only bar). Returns null when there is no data or the window is empty. Primarily the data seam an optional, attach-only overlay (C4 Volume Profile via VolumeProfileController) reads through — delegates to ChartEngine.visibleCandleView.

      Returns CandleView | null