interface DrawingTool {
    angleLock?: boolean;
    defaultStyle?: DrawingStyle;
    defaultText?: DrawingText;
    freehand?: boolean;
    id: string;
    name: string;
    points: number;
    settings?: SettingsSchema;
    shortcut?: string;
    viewport?: boolean;
    alertLevels(drawing: Drawing): readonly AlertDrawingLevel[];
    alertValue(
        context: DrawingValueContext,
        level?: string,
    ): undefined | Omit<AlertDrawingValue, "paneIndex">;
    bounds(
        pts: readonly ScreenPoint[],
        drawing: Drawing,
    ): { x0: number; x1: number; y0: number; y1: number };
    constrain(
        points: readonly DrawingPoint[],
        handle: null | number,
    ): DrawingPoint[];
    distance(x: number, y: number, c: HitContext): null | number;
    draw(c: DrawContext): void;
    expand(
        clicked: readonly DrawingPoint[],
        ctx: ExpandContext,
    ): DrawingPoint[];
}

Properties

angleLock?: boolean

Hold Shift to snap the free end of a two-anchor tool to 45 degree steps on screen, while placing and while dragging a handle. The line family sets it; a tool whose second anchor is not the far end of a line (a rectangle's opposite corner) leaves it off, since a locked diagonal is not what Shift means there.

defaultStyle?: DrawingStyle

Merged under the caller's style when a drawing is created.

defaultText?: DrawingText

Merged under the caller's text when a drawing is created. The text tool uses it for its placeholder content and default size; a shape leaves it unset so it carries no label until the user gives it one.

freehand?: boolean

Sample the cursor continuously while the pointer is held, and finish on release: one press-drag-release gesture is one stroke. Brushes want this; without it a points: 0 tool collects a vertex per click, which is polyline behaviour and never terminates on its own.

id: string
name: string
points: number

Anchors the tool needs before it is complete. 0 means free-form: the drawing finishes on double-click.

settings?: SettingsSchema

The fields a settings panel offers for this tool. Every built-in declares one; a custom tool without it gets the plain line fields.

shortcut?: string

Keyboard shortcut that arms this tool, as 'Alt+T' / 'Shift+Alt+F': modifiers in Ctrl, Alt, Shift order, then a single key. Hosts render it beside the tool's name in a palette and bind it with matchDrawingShortcut; the library itself installs no listener, since only the host knows whether the chart has focus or a dialog is open.

viewport?: boolean

The tool can be anchored to the viewport (Drawing.space). Declare it only when draw and distance read the screen anchors (pts) and never drawing.points, which is empty in that space, and when nothing the tool prints is a price or a time: a label that reads the axis under a pinned shape would change every time the chart panned. expand, constrain and alertValue apply to data space only.

Methods

  • The box the drawing covers at pts, its anchors in media px (the space of HitContext). A drawing anchored to the viewport is always painted, hit-tested and moved with this box inside its pane's plot, so it can be seen and grabbed at every edge and after the chart resizes, and no drag, nudge or handle can take it out. Declare it on a viewport tool that paints beyond its anchors, as the text note and the table do from their one corner, and the rectangle and the ellipse do for a label above them or wider than they are; without it the box is the anchors' own bounds. A handle dragged toward an edge the box reaches first stops short of it, so the other anchors stay where they are.

    Parameters

    Returns { x0: number; x1: number; y0: number; y1: number }

  • Keep the anchors consistent after one of them moves: a handle drag (handle is its index) or a patch to points (handle is null). Returns the anchors to store. The position tools use it to keep the stop and the target on opposite sides of the entry, so dragging the stop up through the entry of a long turns the trade into a short instead of piling both levels on one side. Pure: the same input always yields the same output.

    Parameters

    Returns DrawingPoint[]

  • Distance in media px from the cursor to the shape, or null for a miss. Return 0 for "inside" so a filled region is grabbable anywhere.

    Parameters

    Returns null | number

  • Turn the anchors actually clicked into the full anchor set. Lets a tool drop a complete, immediately editable default from fewer clicks: the position tools place a 1:1 box off a single click, which the user then drags, rather than demanding entry/target/stop be clicked in turn.

    The returned points become the drawing's anchors, so each one stays a draggable handle.

    Parameters

    Returns DrawingPoint[]