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

    Class Viewport

    Index

    Constructors

    Properties

    autoFollow: boolean = true

    When true, new data appended to the buffer auto-scrolls the viewport to keep the newest candle in view. Set to false automatically when the user pans away from the right edge, and back to true when they pan back or explicitly call goToLive().

    candleWidth: number = DEFAULT_CANDLE_WIDTH
    layout: ChartLayout
    manualPriceScale: boolean = false

    When true, autoScale() is skipped — priceMin/priceMax stay frozen at the user-chosen range. Set by scalePriceRangeBy() when the user drags the price axis. Cleared by resetPriceScale().

    priceMax: number = 0
    priceMin: number = 0
    rightPaddingCandles: number = 5

    Number of empty-candle slots kept between the last candle and the right edge of the chart area. Leaves breathing room for the forming live candle.

    scaleMode: PriceScaleMode = 'linear'

    Active price-axis transform. 'linear' keeps the original render path byte-for-byte; 'log'/'percentage'/'indexedTo100' route through priceToTransformed. Set via setScaleMode.

    startIndex: number = 0
    visibleCount: number = 0
    volumeMax: number = 0

    Accessors

    Methods

    • Auto-scale price/volume from the visible buffer data.

      accel (optional) is a coarse range index used only when the visible window is huge (sub-pixel fitAll) and the mode isn't log — it turns a per-frame O(window) scan into ≈ O(window / block). Omit it and the original linear scan runs, preserving all four guards (manual-mode volume rescan, empty window, NaN-skip, flat-range).

      maxLength (optional) caps the upper index the scan/clamp may reach. Defaults to buffer.length, so omitting it is bit-for-bit identical to the pre-replay behavior. Replay mode (C1) passes the effective (capped) length so autoscale never peeks at not-yet-revealed candles even if the viewport's visible window nominally extends past the cap.

      Parameters

      • buffer: CandleBuffer
      • Optionalaccel: RangeSource
      • OptionalmaxLength: number

      Returns void

    • Auto-scale from a pre-built (possibly transformed) view rather than the raw buffer — used by series with a transformView (Heikin-Ashi) or a custom priceRange. Scans the view linearly (no range pyramid). Honors the same manual / empty / NaN / log / flat-range guards as autoScale.

      Parameters

      Returns void

    • Fit all candles from the buffer into the visible chart area by adjusting candleWidth. Useful for "show me everything" action. Scrolls to the start.

      Parameters

      • bufferLength: number

      Returns void

    • Reset candleWidth to the default value and scroll to the live edge. Useful for "back to normal" action after deep zoom. Also resets the manual price scale so the next auto-scale runs from scratch.

      Parameters

      • bufferLength: number

      Returns void

    • Format a price value as a Y-axis label in the active scale mode. Returns a pre-formatted string for percentage/indexedTo100 modes (e.g. "+10.00%") so all axis pills — grid ticks, current-price pill, and crosshair pill — show consistent transformed units. Returns null for linear and log so the caller applies its own price formatter.

      Parameters

      • price: number

      Returns string | null

    • Scroll to the live edge without changing candleWidth. Re-enables autoFollow.

      Parameters

      • bufferLength: number

      Returns void

    • Price-axis grid ticks for the current scale mode. Shared by the grid renderer and the price-axis renderer so they never diverge. For linear/log, label is null (caller formats the price); for percentage/indexed, label is the pre-formatted axis string.

      Parameters

      • maxTicks: number = 6

      Returns GridTick[]

    • Convert buffer index to X pixel coordinate

      Parameters

      • index: number

      Returns number

    • True only when the viewport is resting exactly at the live anchor position (last candle sits at chartRight - rightPaddingCandles).

      The tolerance is < 0.5 candle so that fractional pan deltas from panPixels() still snap cleanly. Panning even one full candle past the anchor into the empty future zone counts as "user exploring the future" and returns false — which prevents live updates from jerking the view back to the anchor on every tick.

      Returns boolean

    • Pan by a pixel delta (as reported by wheel or touch events). Positive dx means the content moves right (show older candles); negative dx means the content moves left (show newer candles).

      Parameters

      • dx: number

      Returns void

    • Convert price to Y pixel coordinate.

      side selects the price scale: 'right' (default) is the primary scale and runs the original arithmetic untouched — every existing caller omits the argument, so the default path is bit-for-bit unchanged. 'left' projects through the independent secondary scale (see setLeftRange).

      Parameters

      Returns number

    • Exit manual price-scale mode; the next autoScale() call will recompute priceMin/priceMax from the visible candles again.

      Returns void

    • Scale the price range by factor around an anchor Y coordinate (the pixel under the user's cursor at drag-start). factor > 1 expands the visible range (zoom out vertically — shorter candles), factor < 1 contracts it (zoom in vertically — taller candles).

      Switches the viewport to manual price-scale mode — subsequent autoScale() calls are skipped until resetPriceScale() is called.

      Parameters

      • factor: number
      • anchorY: number

      Returns void

    • Scroll to the end of data, leaving rightPaddingCandles of empty space.

      Parameters

      • bufferLength: number

      Returns void

    • Install a non-uniform index→0..1 horizontal mapping (value-based scales), or pass null to restore uniform index spacing. The default is null, so the standard time chart's geometry is untouched.

      Parameters

      • fn: ((index: number) => number) | null

      Returns void

    • Set the secondary (left) price scale's raw extrema, applying the same flat-range protection + linear padding as the right axis's _applyPriceRange. Called by the engine after collecting the min/max of every indicator bound to 'left'. No-op-safe: a degenerate or non-finite pair leaves the previous range intact.

      Parameters

      • min: number
      • max: number

      Returns void

    • Install a time → (fractional) buffer-index resolver, or pass null to clear it. The engine sets this every frame from the main buffer so overlays that own their own time-keyed series (timeToX) align to the price axis. The default is null, so a chart with no buffer (or no overlay consumer) pays nothing and timeToX returns NaN.

      Parameters

      • fn: ((t: number) => number) | null

      Returns void

    • Project a timestamp onto the chart's X axis, aligned with the main price series. Resolves the timestamp to a (possibly fractional) buffer index via the engine-installed resolver, then through the same indexToX the candles use — so a value-based horizontal scale, zoom, and pan all carry over for free. Returns NaN when no resolver is installed (no buffer) or the resolver itself can't place the time, letting a caller skip that point instead of drawing at a bogus X.

      Parameters

      • t: number

      Returns number

    • Convert volume to Y pixel coordinate

      Parameters

      • volume: number

      Returns number

    • Convert X pixel to nearest buffer index

      Parameters

      • x: number

      Returns number

    • Convert Y pixel to price. side selects the scale; 'right' (default) is the primary scale and is unchanged for every existing caller.

      Parameters

      Returns number

    • Zoom around a center X coordinate

      Parameters

      • factor: number
      • centerX: number

      Returns void