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;
    isDestroyed?: boolean;
    timeScale?: {
        indexToX(index: number): number;
        xToIndex(x: number): number;
    };
    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;
    getDataContext(): | undefined
    | { exchange?: string; interval?: string; symbol?: string };
    getVisibleLogicalRange(): null | { from: number; to: number };
    indicators(): readonly IndicatorApi[];
    on(event: string, handler: (payload: unknown) => void): () => void;
    panes(): readonly unknown[];
    plotRect(paneIndex: number): null | PlotRect;
    priceToCoordinate(price: number, paneIndex?: number): null | number;
    primaryBars(): readonly Bar[];
    primaryPaneIndex(): number;
    removePrimitive(primitive: IPrimitive): void;
    seriesStack(paneIndex: number): readonly string[];
    seriesStyle(
        series: SeriesApi,
    ): null | { color?: string; visible?: boolean };
    setDrawingState(state: unknown): void;
    setPlacementMode(active: boolean): void;
    setPrimitiveStackAbove(
        primitive: IPrimitive,
        above: null | string,
    ): boolean;
    timeToCoordinate(time: number): number;
}

Properties

dataLayer: DataLayer
isDestroyed?: boolean
timeScale?: { indexToX(index: number): number; xToIndex(x: number): number }

Optional, for drawings anchored to the viewport (space: 'viewport'): the time axis, which turns a data anchor's time into a place on the plot and back when a drawing is pinned or unpinned.

Methods

  • Parameters

    • y: number
    • OptionalpaneIndex: number

    Returns null | number

  • Optional: the host's data context, whose interval decides which drawings with an interval range are shown (Drawing.intervals). Read when the controller is built and on every data:context, whose payload is the context itself; a host without it that emits data:context is followed through the payload alone. With no interval every drawing shows. The instrument is declared too, as the chart's context carries it, so one host object also satisfies DrawingLinkChart.

    Returns undefined | { exchange?: string; interval?: string; symbol?: string }

  • The event bus, with the names and payloads of ChartEventMap. The controller listens for click, crosshair:move, drag, drag:end, drag:cancel, dblclick and 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. It also follows data:context, drawings:restore, pick:start, pick:end, paneRemoved, paneMoved, objects:change and indicatorRemoved; a host that moves or removes panes without paneRemoved and paneMoved leaves drawings on the old slots. It emits the draw:* and drawing:* names this tier adds to ChartEventMap.

    Parameters

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

    Returns () => void

  • Optional. It keeps 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. An entry with priceToY and yToPrice, as a chart pane has, also lets an alert read a drawing on a pane the chart maps no price for, one collapsed to its header strip.

    Returns readonly unknown[]

  • Optional, for drawings anchored to the viewport: a pane's plot in container px, as Chart.plotRect reports it, which is what a viewport anchor is a fraction of. A host without it still paints them, since the layer reads the plot size from its render context, but cannot place, move or convert them.

    Parameters

    • paneIndex: number

    Returns null | PlotRect

  • 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, all three, for the magnet: the price series' bars, the studies and a series' style. The chart reports no bar while a drawing is in hand, so a handle or a shape snaps against primaryBars; a study pane snaps to the values of the studies plotted on it, skipping a hidden plot. A host without them snaps placements on the price pane only.

    Returns readonly Bar[]

  • Optional. Slot of the price pane, the one pane whose drawings the magnet snaps to candle prices and a drawing link shares. It moves when a host puts the price pane below its studies; without it the price pane is slot 0.

    Returns number

  • Optional, both: a pane's series band, back to front, and the call that paints a layer directly above one of its entries. Without them no drawing can be placed in the series band, and one saved there paints by its zIndex.

    Parameters

    • paneIndex: number

    Returns readonly string[]

  • 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