interface DrawingTool {
    angleLock?: boolean;
    defaultStyle?: DrawingStyle;
    defaultText?: DrawingText;
    freehand?: boolean;
    id: string;
    name: string;
    points: number;
    settings?: SettingsSchema;
    shortcut?: string;
    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.

Methods

  • 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[]