Skip to content
EliteChart

HistoryStack

Documentation


Documentation / @elitechart/core / HistoryStack

Defined in: history/history-stack.ts:90

Command-pattern undo/redo stack used internally by the chart and exported for advanced embedders that want to extend undo into their own UI actions.

Example

code
const stack = new HistoryStack();
stack.push({
  label: 'Add drawing',
  redo: () => chart.addDrawing(tool, state),
  undo: () => chart.removeDrawing(id),
});
stack.undo(); // reverses

Constructors

Constructor

code
new HistoryStack(opts?): HistoryStack;

Defined in: history/history-stack.ts:96

Parameters

opts?

HistoryStackOptions = {}

Returns

HistoryStack

Accessors

canRedo

Get Signature

code
get canRedo(): boolean;

Defined in: history/history-stack.ts:147

Returns

boolean


canUndo

Get Signature

code
get canUndo(): boolean;

Defined in: history/history-stack.ts:143

Returns

boolean


redoLabel

Get Signature

code
get redoLabel(): string | null;

Defined in: history/history-stack.ts:167

Returns

string | null


size

Get Signature

code
get size(): number;

Defined in: history/history-stack.ts:151

Returns

number


undoLabel

Get Signature

code
get undoLabel(): string | null;

Defined in: history/history-stack.ts:162

Label of the top-of-stack command, for UI hints ("Undo: move drawing").

Returns

string | null

Methods

clear()

code
clear(): void;

Defined in: history/history-stack.ts:155

Returns

void


push()

code
push(cmd, opts?): void;

Defined in: history/history-stack.ts:106

Record a command. By default the command's redo() is invoked immediately — pass { execute: false } when the action has already been performed and you only want to record the reversal.

Parameters

cmd

HistoryCommand

opts?
execute?

boolean

Returns

void


redo()

code
redo(): HistoryCommand | null;

Defined in: history/history-stack.ts:134

Returns

HistoryCommand | null


undo()

code
undo(): HistoryCommand | null;

Defined in: history/history-stack.ts:125

Returns

HistoryCommand | null