g6/packages/site/examples/tool/history/index.en.md

3.1 KiB

title
History

History is a built-in components in G6, but not reigstered by default. It needs to be imported into the code and registered with the extend method, and then you could configured it to the graph instance.

Usage

API

isHistoryEnabled

Determine if history (redo/undo) is enabled.

isHistoryEnabled: () => void;

pushStack

Push the operation(s) onto the specified stack.

pushStack: (cmd: Command[], stackType: StackType) => void;

Parameters:

cmd: An array of commands to be pushed onto the stack. stackType: The type of stack (undo/redo) to push the commands onto.

pauseStack

Pause stacking operation.

pauseStack: () => void;

resumeStack

Resume stacking operation.

resumeStack: () => void;

executeWithNoStack

Execute a callback without allowing any stacking operations.

executeWithNoStack: (callback: () => void) => void;

Parameters: callback: The callback function to be executed without stacking operations.

getUndoStack

Retrieve the current undo stack which consists of operations that could be undone.

getUndoStack: () => void;

getRedoStack

Retrieve the current redo stack which consists of operations that were undone.

getRedoStack: () => void;

getStack

Retrieve the complete history stack.

getStack: () => void;

undo

Revert the last n operation(s) on the graph.

undo: () => void;

redo

Restore the operation that was last n reverted on the graph.

redo: () => void;

canUndo

Indicate whether there are any actions available in the undo stack.

canUndo: () => void;

canRedo

Indicate whether there are any actions available in the redo stack.

canRedo: () => void;

startHistoryBatch

Begin a historyBatch operation. Any operations performed between startHistoryBatch and stopHistoryBatch are grouped together and treated as a single operation when undoing or redoing.

startHistoryBatch: () => void;

stopHistoryBatch

End a historyBatch operation. Any operations performed between startHistoryBatch and stopHistoryBatch are grouped together and treated as a single operation when undoing or redoing.

stopHistoryBatch: () => void;

historyBatch

Execute a provided function within a batched context. All operations performed inside the callback will be treated as a composite operation, providing a more convenient way without manually invoking startHistoryBatch and stopHistoryBatch.

historyBatch: (callback: () => void) => void;

Parameters: callback: The function containing operations to be batched together.

cleanHistory

Execute a provided function within a batched context. All operations performed inside the callback will be treated as a composite operation, providing a more convenient way without manually invoking startHistoryBatch and stopHistoryBatch.

cleanHistory: (stackType?: StackType) => void;

Parameters: stackType (optional): The type of stack (undo/redo) to be cleaned. If not provided, all stacks will be cleaned.