feat: add get stack function

This commit is contained in:
baizn 2020-06-18 11:15:09 +08:00 committed by Yanyan Wang
parent 714a955a48
commit c62483b19b
3 changed files with 35 additions and 6 deletions

View File

@ -831,6 +831,7 @@ export default class Graph extends EventEmitter implements IGraph {
/**
*
* @param {Item} item
* @param {boolean} stack true
*/
public showItem(item: Item | string, stack: boolean = true): void {
const itemController: ItemController = this.get('itemController');
@ -847,6 +848,7 @@ export default class Graph extends EventEmitter implements IGraph {
/**
*
* @param {Item} item
* @param {boolean} stack true
*/
public hideItem(item: Item | string, stack: boolean = true): void {
const itemController: ItemController = this.get('itemController');
@ -883,6 +885,7 @@ export default class Graph extends EventEmitter implements IGraph {
/**
*
* @param {Item} item id或元素实例
* @param {boolean} stack true
*/
public remove(item: Item | string, stack: boolean = true): void {
this.removeItem(item, stack);
@ -891,6 +894,7 @@ export default class Graph extends EventEmitter implements IGraph {
/**
*
* @param {Item} item id或元素实例
* @param {boolean} stack true
*/
public removeItem(item: Item | string, stack: boolean = true): void {
// 如果item是字符串且查询的节点实例不存在则认为是删除group
@ -924,8 +928,9 @@ export default class Graph extends EventEmitter implements IGraph {
/**
*
* @param {string} type (node | edge | group)
* @param {ITEM_TYPE} type (node | edge | group)
* @param {ModelConfig} model
* @param {boolean} stack true
* @return {Item}
*/
public addItem(type: ITEM_TYPE, model: ModelConfig, stack: boolean = true) {
@ -1057,6 +1062,13 @@ export default class Graph extends EventEmitter implements IGraph {
return item;
}
/**
*
* @param {ITEM_TYPE} type (node | edge | group)
* @param {ModelConfig} model
* @param {boolean} stack true
* @return {Item}
*/
public add(type: ITEM_TYPE, model: ModelConfig, stack: boolean = true): Item {
return this.addItem(type, model, stack);
}
@ -1096,6 +1108,7 @@ export default class Graph extends EventEmitter implements IGraph {
*
* @param {Item} item id或元素实例
* @param {Partial<NodeConfig> | EdgeConfig} cfg
* @param {boolean} stack true
*/
public update(item: Item | string, cfg: Partial<NodeConfig> | EdgeConfig, stack: boolean = true): void {
this.updateItem(item, cfg, stack);
@ -1264,7 +1277,8 @@ export default class Graph extends EventEmitter implements IGraph {
/**
*
* @param {object} data
* @param {GraphData | TreeGraphData} data
* @param {boolean} true
* @return {object} this
*/
public changeData(data?: GraphData | TreeGraphData, stack: boolean = true): Graph {

View File

@ -318,10 +318,11 @@ export interface IGraph extends EventEmitter {
/**
*
* @param {GraphData} data
* @param {GraphData | TreeGraphData} data
* @param {boolean} true
* @return {object} this
*/
changeData(data?: GraphData | TreeGraphData): Graph;
changeData(data?: GraphData | TreeGraphData, stack?: boolean): Graph;
/**
*
@ -479,6 +480,16 @@ export interface IGraph extends EventEmitter {
*/
updateCombos(): void;
/**
* undo stack
*/
getUndoStack(): Stack;
/**
* redo stack
*/
getRedoStack(): Stack;
/**
* undo redo
*/

View File

@ -1563,13 +1563,18 @@ describe('node Neighbors', () => {
})
})
describe('redo & undo', () => {
describe('redo stack & undo stack', () => {
const graph = new Graph({
container: 'global-spec',
width: 500,
height: 500
})
it('undo & redo stack is null', () => {
expect(graph.getUndoStack()).not.toBe(null)
expect(graph.getRedoStack()).not.toBe(null)
})
const data = {
nodes: [
{
@ -1591,7 +1596,6 @@ describe('redo & undo', () => {
graph.render()
it('fill undo stack', () => {
// redo 后undo stack 有一条数据
let stackData = graph.getStackData()
let undoStack = stackData.undoStack