DrawingTool\<State\>
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
Type Parameters
State
State = unknown
Properties
anchorCount
Defined in: drawing/types.ts:138
Number of anchors the click-to-place flow collects before finalizing.
id
Defined in: drawing/types.ts:132
Unique id (reverse-DNS or scope-prefixed).
kind
Defined in: drawing/types.ts:134
Short kind tag — used by the renderer / UI to pick icons etc.
name
Defined in: drawing/types.ts:136
Human-readable display name.
streaming?
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()
Defined in: drawing/types.ts:142
Expose the anchor points of a state (for selection-handle rendering).
Parameters
state
State
Returns
readonly DataPoint[]
appendPoint()?
Defined in: drawing/types.ts:165
Append a new point to a streaming-tool state.
Parameters
state
State
point
Returns
State
deserialize()
Defined in: drawing/types.ts:185
Reconstruct a state from its serialized form.
Parameters
raw
unknown
Returns
State
fromAnchors()
Defined in: drawing/types.ts:140
Build initial state from anchorCount anchor points.
Parameters
anchors
readonly DataPoint[]
Returns
State
hitTest()
Defined in: drawing/types.ts:181
Hit-test the drawing at a screen pixel position.
Parameters
state
State
screen
viewport
Returns
render()
Defined in: drawing/types.ts:173
Render state onto paint using viewport transforms.
Parameters
paint
viewport
state
State
style
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()
Defined in: drawing/types.ts:183
JSON-safe projection of the state. Round-trippable through deserialize.
Parameters
state
State
Returns
unknown
setAnchor()
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
Returns
State
translate()
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