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

    Interface Primitive

    A programmatic, host-driven overlay drawn at an explicit z-tier.

    Distinct from Drawing: drawings are user-created interactive tools with undo/redo, snapshot persistence, selection handles, and a creation FSM, anchored in buffer space. Primitives are imperative overlays the host attaches/detaches directly (watermark, price lines, custom bands) — no undo, no persistence, just a draw at a chosen tier. The two deliberately share the draw/hitTest shape so rendering helpers can be reused.

    draw receives the same coordinate transforms as everything else (viewport.priceToY/indexToX), so primitives inherit price-scale-mode correctness (F1) for free.

    interface Primitive {
        id: string;
        zOrder: PrimitiveZOrder;
        draw(
            ctx: CanvasRenderingContext2D,
            layout: ChartLayout,
            viewport: Viewport,
            theme: ThemeColors,
            priceFormat?: (price: number) => string,
        ): void;
        hitTest?(
            x: number,
            y: number,
            layout: ChartLayout,
            viewport: Viewport,
            tolerance?: number,
        ): boolean;
    }

    Implemented by

    Index

    Properties

    Methods

    Properties

    id: string

    Stable id used for detach and hit-test routing.

    Paint tier.

    Methods

    • Paint the primitive. Should self-clip if it must stay inside the chart. priceFormat is the chart's host-supplied price formatter (from ChartConfig.priceFormat), so primitives that render a price label (e.g. price lines) match the axis/crosshair formatting instead of falling back to the library default.

      Parameters

      Returns void

    • Optional pointer hit-test in CSS pixels. Used to route drags (e.g. a draggable price line). Return true if (x, y) lands on the primitive.

      Parameters

      Returns boolean