Skip to content
EliteChart

DrawingTool\<State\>

Documentation


Documentation / @elitechart/core / DrawingTool

Defined in: drawing/types.ts:130

A drawing tool. Implementations are pure — no hidden state, no DOM access. The chart owns the instance lifecycle; the tool only defines the state shape and how to render / hit-test it.

Example

code
import { trendLineTool } from '@elitechart/drawings';
chart.setToolMode(trendLineTool); // user clicks two anchors to draw

Type Parameters

State

State = unknown

Properties

anchorCount

code
readonly anchorCount: number;

Defined in: drawing/types.ts:138

Number of anchors the click-to-place flow collects before finalizing.


id

code
readonly id: string;

Defined in: drawing/types.ts:132

Unique id (reverse-DNS or scope-prefixed).


kind

code
readonly kind: string;

Defined in: drawing/types.ts:134

Short kind tag — used by the renderer / UI to pick icons etc.


name

code
readonly name: string;

Defined in: drawing/types.ts:136

Human-readable display name.


streaming?

code
readonly optional streaming?: boolean;

Defined in: drawing/types.ts:163

When true, the tool is a streaming tool: creation is a continuous pointer drag (brush, highlighter, freehand) rather than a fixed sequence of anchor clicks. The chart seeds the state from one initial anchor then calls appendPoint on every pointermove until release.

If streaming is true, appendPoint MUST be defined.

Methods

anchors()

code
anchors(state): readonly DataPoint[];

Defined in: drawing/types.ts:142

Expose the anchor points of a state (for selection-handle rendering).

Parameters

state

State

Returns

readonly DataPoint[]


appendPoint()?

code
optional appendPoint(state, point): State;

Defined in: drawing/types.ts:165

Append a new point to a streaming-tool state.

Parameters

state

State

point

DataPoint

Returns

State


deserialize()

code
deserialize(raw): State;

Defined in: drawing/types.ts:185

Reconstruct a state from its serialized form.

Parameters

raw

unknown

Returns

State


fromAnchors()

code
fromAnchors(anchors): State;

Defined in: drawing/types.ts:140

Build initial state from anchorCount anchor points.

Parameters

anchors

readonly DataPoint[]

Returns

State


hitTest()

code
hitTest(
   state, 
   screen, 
   viewport): HitResult;

Defined in: drawing/types.ts:181

Hit-test the drawing at a screen pixel position.

Parameters

state

State

screen

ScreenPoint

viewport

Viewport

Returns

HitResult


render()

code
render(
   paint, 
   viewport, 
   state, 
   style, 
   bars?): void;

Defined in: drawing/types.ts:173

Render state onto paint using viewport transforms.

Parameters

paint

Paint

viewport

Viewport

state

State

style

DrawingStyle

bars?

readonly Bar[]

Optional current chart bars. Volume-aware tools (Anchored VWAP, Fixed-Range Volume Profile) consume this; most tools ignore it. Always supplied by the chart at render time.

Returns

void


serialize()

code
serialize(state): unknown;

Defined in: drawing/types.ts:183

JSON-safe projection of the state. Round-trippable through deserialize.

Parameters

state

State

Returns

unknown


setAnchor()

code
setAnchor(
   state, 
   index, 
   point): State;

Defined in: drawing/types.ts:149

Replace the anchor at index with point. Returns a new state; the caller guarantees index < anchors(state).length for drawings with discrete handles. For plot-wide tools (horizontal/vertical line) the implementation may accept any index as a body-drag.

Parameters

state

State

index

number

point

DataPoint

Returns

State


translate()

code
translate(
   state, 
   deltaTime, 
   deltaPrice): State;

Defined in: drawing/types.ts:154

Translate every anchor in state by deltaTime (ms) and deltaPrice. Used for body-drag where the whole drawing moves as a unit.

Parameters

state

State

deltaTime

number

deltaPrice

number

Returns

State