Class
Drawings
The drawings of a chart (FerroChart.drawings). Ids are numbers; changes
made here and by the user are undoable.
Properties
activeTool
readonly activeTool: string | undefined;The armed tool, undefined if none.
canRedo
readonly canRedo: boolean;Whether there is an undone change to redo.
canUndo
readonly canUndo: boolean;Whether there is a change to undo.
selected
readonly selected: number | undefined;The selected drawing, undefined if none.
Methods
add
add(data: DrawingData, pane?: number | null): number;Adds a drawing on pane (default: the main pane); returns its id.
bringToFront
bringToFront(id: number): void;Draws a drawing above the others.
cancelTool
cancelTool(): void;Cancels the armed tool or the drawing being created.
clearHistory
clearHistory(): void;Forgets the undo and redo history.
get
get(id: number): Required<DrawingData> | null;The saved form of a drawing, null for an unknown id.
ids
ids(): number[];Ids, bottom to top.
isLocked
isLocked(id: number): boolean | undefined;Whether a drawing is locked, undefined for an unknown id.
isVisible
isVisible(id: number): boolean | undefined;Whether a drawing is shown, undefined for an unknown id.
kinds
kinds(): string[];Kinds that add and startTool accept.
paneOf
paneOf(id: number): number | undefined;The pane of a drawing.
redo
redo(): boolean;Redoes the last undone change; false if there was none.
register
register(kind: string, tool: DrawingToolJs): void;Registers a drawing tool written in JS under kind, for this
chart (add, startTool, loadState). tool.anchorCount says how
it is created: a number (1–64) of clicks, { open: min } (a click per
anchor until a double click or Enter, at least min, 1–64) or
'freehand' (press, drag, release; no handles); tool.build(ctx) returns its
commands in CSS px (ctx.anchors have time, price, x, y;
ctx.style, ctx.params); the optional tool.hitTest(ctx, point)
returns true (the drawing), a handle number or false (default:
anything inside the drawn bounds). Built-in kinds cannot be replaced;
registering a JS kind again replaces it on every chart of the page.
remove
remove(id: number): void;Removes a drawing.
select
select(id?: number | null): void;Selects a drawing (null clears the selection).
sendToBack
sendToBack(id: number): void;Draws a drawing below the others.
setAnchors
setAnchors(id: number, anchors: Anchor[]): void;Moves the anchors (same number as the drawing has).
setLocked
setLocked(id: number, locked: boolean): void;Locks a drawing against editing (it can still be selected and removed).
setParam
setParam(id: number, key: string, value: DrawingParam): void;Sets a tool parameter, e.g. 'text' of a text drawing or 'levels'
of a Fibonacci retracement.
setStyle
setStyle(id: number, style: DrawingStyle): void;Changes some style keys.
setVisible
setVisible(id: number, visible: boolean): void;Shows or hides a drawing.
startTool
startTool(kind: string): void;Arms a tool: the next clicks on a plot create a drawing of kind.
undo
undo(): boolean;Undoes the last change; false if there was none.
Like every object of the API, a Drawings holds WebAssembly memory. Objects returned by the chart are freed with it; free() (or using) releases one earlier.