Skip to main content

Drawing tools

Drawing tools overlay annotations on K-lines — support/resistance horizontals, trend rays, Fibonacci retracements. Shapes live on a chart pane (main pane paneId is "main"), anchors are draggable; the library handles hit-testing, redraw, and mutual exclusion with the crosshair.

Two ways to use them:

ModeHow
Tool drawingsetOverlay(tool id) enters place mode; click the required points on the chart
Code drawingaddDrawing({ tool, paneId, points, style }) writes directly — good for scripts / backtest marks

Entry: useDrawOverlay() from @keisen-charts/react/toolkit or @keisen-charts/vue/toolkit. Must be called inside the KeisenChart subtree (e.g. header).

Built-in tools

idPointsDescription
horizontal1Horizontal line (fixed price)
vertical1Vertical line (fixed time / bar)
priceChannel1Price channel (horizontal ray to the right)
ray2Ray (two points set direction)
fibRetracement2Fibonacci retracement
parallelLines3Parallel lines

API

useDrawOverlay(options?)

optionsTypeDescription
stickyToolboolean?Keep current tool after drawing; default false (return to browse)
ReturnTypeDescription
activeToolDrawingToolId | null (Ref in Vue)Current place tool; null = browse (crosshair)
setOverlay(tool: DrawingToolId | null) => voidSwitch tool; null exits place mode
drawingsDrawing[]All current shapes
selectedIdsstring[]Selected shape ids
stickyTool / setStickyToolboolean / setterSticky tool after draw
addDrawingsee belowProgrammatic create; returns id
updateDrawing(id, patch) => voidPatch style / points / visible etc.
removeDrawing(id) => voidRemove one
clearDrawings(paneId?) => voidClear; optional pane filter
serialize() => stringExport JSON
hydrate(json) => voidRestore from JSON
toolbarPropsDrawToolsToolbarPropsFeed a custom toolbar

addDrawing(drawing)

FieldTypeDescription
toolDrawingToolIdTool type
paneIdstringMain pane uses "main"
points{ barIndex, value, time? }[]Anchors; library fills time from current kline when omitted
style{ stroke, lineWidth, lineDash? }?Stroke; default blue
idstring?Optional; auto-generated if omitted
editable / locked / visibleboolean?Default: draggable, unlocked, visible

toolbarProps / DrawToolsToolbarProps

FieldDescription
toolsDRAWING_TOOL_METAS (id + en/zh labels)
activeToolCurrent tool
setOverlaySame as hook
clearDrawingsSame as hook

Copy the docs toolbar example and adapt; no finished toolbar ships with the library.

type DrawingPoint = { barIndex: number; time: number; value: number };
type DrawingStyle = { stroke: string; lineWidth: number; lineDash?: number[] };
type Drawing = {
id: string;
tool: DrawingToolId;
paneId: string;
points: DrawingPoint[];
style: DrawingStyle;
editable?: boolean;
locked?: boolean;
visible?: boolean;
};

Example: draw by code

Buttons call addDrawing — horizontal at last price, ray from mid to last:

Loading interactive example…

Example: draw with tools

Select a tool, then click on the chart (horizontal: 1 click, ray: 2, parallel: 3):

Loading interactive example…