Interface DrawingChartHost

The slice of the chart this controller needs.

Declared structurally rather than as Chart on purpose. Each tier ships its own bundled .d.ts, so naming the class here made the draw tier re-declare Chart, and because Chart has private members, TypeScript treats the two declarations as different types. A TS consumer passing the chart from createChart() got "separate declarations of a private property", which made the tier unusable from TypeScript at all. An interface with no private members is structural, so the real Chart satisfies it with nothing to cast.

interface DrawingChartHost {
    dataLayer: DataLayer;
    addPrimitive(primitive: IPrimitive, paneIndex?: number): void;
    coordinateToPrice(y: number, paneIndex?: number): null | number;
    coordinateToTime(x: number): number;
    drawingState(): unknown;
    emit(event: string, payload: unknown): void;
    getVisibleLogicalRange(): null | { from: number; to: number };
    on(event: string, handler: (payload: unknown) => void): () => void;
    panes(): readonly unknown[];
    priceToCoordinate(price: number, paneIndex?: number): null | number;
    removePrimitive(primitive: IPrimitive): void;
    setDrawingState(state: unknown): void;
    setPlacementMode(active: boolean): void;
    timeToCoordinate(time: number): number;
}

Properties

dataLayer: DataLayer

Methods

  • Parameters

    • y: number
    • OptionalpaneIndex: number

    Returns null | number

  • Parameters

    • event: string
    • payload: unknown

    Returns void

  • Returns null | { from: number; to: number }

  • The event bus. The controller listens for click, crosshair:move, drag, drag:end and dblclick, and for hover ({ id }, the hit id under the pointer whenever it changes), which is what drives the hover state: the chart has already hit-tested the move, so the controller reads its answer rather than testing a second time. A host that never emits hover has drawings that select and drag but do not light up.

    Parameters

    • event: string
    • handler: (payload: unknown) => void

    Returns () => void

  • Optional, and used only to keep a paste from a chart with more panes than this one landing on a pane the user cannot see. Adding a primitive creates the pane it names, so without this a drawing copied out of an indicator pane would conjure an empty pane in a single-pane chart.

    Returns readonly unknown[]

  • Optional, and used only to move a drawing by a fixed screen distance (a paste offset, an arrow-key nudge, a multi-drag across panes). Going through pixels rather than adding a price delta keeps the offset the same visible nudge on a log scale as on a linear one, and the same on an RSI pane as on the price pane. A host without them still gets the time half.

    Parameters

    • price: number
    • OptionalpaneIndex: number

    Returns null | number

  • Optional, the time-axis half of the same conversion. coordinateToTime also keeps previews and freehand strokes active in empty space beyond the bars. Without these methods a horizontal nudge assumes the default bar spacing.

    Parameters

    • time: number

    Returns number