You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
8.6 KiB

4 months ago
import { Graph as GraphLib } from '@antv/graphlib';
import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
import type { DataChange, DataID, ElementDatum, HierarchyKey, ID, NodeLikeData, PartialEdgeData, PartialGraphData, PartialNodeLikeData, Point, State } from '../types';
import type { EdgeDirection } from '../types/edge';
import type { ElementType } from '../types/element';
export declare class DataController {
model: GraphLib<NodeLikeData, EdgeData>;
/**
* <zh/> combo id
*
* <en/> The ids of the last deleted combos
* @remarks
* <zh/> combo id comboIds Graphlib changes NodeRemoved combo node
* combo id isCombo
*
* <en/> When the combo is deleted, its id will be removed from comboIds. At this time, the NodeRemoved obtained according to the changes event of Graphlib cannot distinguish whether it is a combo or a node.
* Therefore, it is necessary to record the id of the last deleted combo and use it to judge isCombo
*/
protected latestRemovedComboIds: Set<string>;
protected comboIds: Set<string>;
/**
* <zh/>
*
* <en/> Get detailed data changes
*/
private changes;
/**
* <zh/>
*
* <en/> Batch processing counter
*/
private batchCount;
/**
* <zh/>
*
* <en/> Whether it is in traceless mode
*/
private isTraceless;
constructor();
private pushChange;
getChanges(): DataChange[];
clearChanges(): void;
batch(callback: () => void): void;
protected isBatching(): boolean;
/**
* <zh/>
*
* <en/> Perform operations without leaving records
* @param callback - <zh/> | <en/> callback function
* @remarks
* <zh/>
*
* <en/> Usually used to adjust elements at runtime and synchronize data to avoid triggering data changes and causing redraws
*/
silence(callback: () => void): void;
isCombo(id: ID): boolean;
getData(): {
nodes: NodeData[];
edges: EdgeData[];
combos: ComboData[];
};
getNodeData(ids?: ID[]): NodeData[];
getEdgeDatum(id: ID): EdgeData;
getEdgeData(ids?: ID[]): EdgeData[];
getComboData(ids?: ID[]): ComboData[];
getRootsData(hierarchyKey?: HierarchyKey): NodeLikeData[];
getAncestorsData(id: ID, hierarchyKey: HierarchyKey): NodeLikeData[];
getDescendantsData(id: ID): NodeLikeData[];
getParentData(id: ID, hierarchyKey: HierarchyKey): NodeLikeData | undefined;
getChildrenData(id: ID): NodeLikeData[];
/**
* <zh/>
*
* <en/> Get the data of the specified type of element
* @param elementType - <zh/> | <en/> element type
* @returns <zh/> | <en/> element data
*/
getElementsDataByType(elementType: ElementType): NodeData[] | EdgeData[] | ComboData[];
/**
* <zh/> ID
*
* <en/> Get the data of the element by ID, no need to care about the type of the element
* @param id - <zh/> ID | <en/> element ID array
* @returns <zh/> | <en/> data of the element
*/
getElementDataById(id: ID): ElementDatum;
/**
* <zh/>
*
* <en/> Get node data
* @param id - <zh/> ID | <en/> node ID
* @returns <zh/> | <en/> node data
*/
getNodeLikeDatum(id: ID): NodeLikeData;
/**
* <zh/> combo
*
* <en/> Get all node and combo data
* @param ids - <zh/> combo ID | <en/> node and combo ID array
* @returns <zh/> combo | <en/> node and combo data
*/
getNodeLikeData(ids?: ID[]): NodeLikeData[];
getElementDataByState(elementType: ElementType, state: string): (NodeData | EdgeData | ComboData)[];
getElementState(id: ID): State[];
hasNode(id: ID): boolean;
hasEdge(id: ID): boolean;
hasCombo(id: ID): boolean;
getRelatedEdgesData(id: ID, direction?: EdgeDirection): EdgeData[];
getNeighborNodesData(id: ID): NodeLikeData[];
setData(data: GraphData): void;
addData(data: GraphData): void;
addNodeData(nodes?: NodeData[]): void;
addEdgeData(edges?: EdgeData[]): void;
addComboData(combos?: ComboData[]): void;
addChildrenData(parentId: ID, childrenData: NodeData[]): void;
/**
* <zh/> zIndex
*
* <en/> Calculate zIndex
* @param data - <zh/> | <en/> newly added data
* @param type - <zh/> | <en/> operation type
* @param force - <zh/> | <en/> ignore batch processing
* @remarks
* <zh/>
* -
* - / combo
* - children
*
* <en/> The situation of calling this function:
* - Add element
* - Update the combo of the node/combo
* - Update the children of the node
*/
protected computeZIndex(data: PartialGraphData, type: 'add' | 'update', force?: boolean): void;
/**
* <zh/> zIndex
*
* <en/> Calculate the zIndex after the element is placed on top
* @param id - <zh/> ID | <en/> ID of the element
* @returns <zh/> zIndex | <en/> zIndex
*/
getFrontZIndex(id: ID): number;
protected updateNodeLikeHierarchy(data: NodeLikeData[]): void;
private enableUpdateNodeLikeHierarchy;
/**
* <zh/>
*
* <en/> Do not update the node hierarchy when executing changes
* @param callback - <zh/> | <en/> change function
*/
preventUpdateNodeLikeHierarchy(callback: () => void): void;
updateData(data: PartialGraphData): void;
updateNodeData(nodes?: PartialNodeLikeData<NodeData>[]): void;
/**
* <zh/>
*
* <en/> Submit all data to the change record for redrawing
*/
refreshData(): void;
syncNodeLikeDatum(datum: PartialNodeLikeData<NodeData>): void;
syncEdgeDatum(datum: PartialEdgeData<EdgeData>): void;
updateEdgeData(edges?: PartialEdgeData<EdgeData>[]): void;
updateComboData(combos?: PartialNodeLikeData<ComboData>[]): void;
/**
* <zh/>
*
* <en/> Set the parent node of the node
* @param id - <zh/> ID | <en/> node ID
* @param parent - <zh/> ID | <en/> parent node ID
* @param hierarchyKey - <zh/> | <en/> hierarchy type
* @param update - <zh/> / | <en/> add new/old parent node data update record
*/
setParent(id: ID, parent: ID | undefined | null, hierarchyKey: HierarchyKey, update?: boolean): void;
/**
* <zh/> combo
*
* <en/> Refresh combo data
* @param id - <zh/> combo ID | <en/> combo ID
* @remarks
* <zh/>
*
* <en/> Will not change the data, but will trigger data change events
*/
refreshComboData(id: ID): void;
getElementPosition(id: ID): Point;
translateNodeLikeBy(id: ID, offset: Point): void;
translateNodeLikeTo(id: ID, position: Point): void;
translateNodeBy(id: ID, offset: Point): void;
translateNodeTo(id: ID, position: Point): void;
translateComboBy(id: ID, offset: Point): void;
translateComboTo(id: ID, position: Point): void;
removeData(data: DataID): void;
removeNodeData(ids?: ID[]): void;
removeEdgeData(ids?: ID[]): void;
removeComboData(ids?: ID[]): void;
/**
* <zh/> children
*
* <en/> Remove the node hierarchy and move its child nodes to the parent node's children list
* @param id - <zh/> | <en/> node to be processed
*/
protected removeNodeLikeHierarchy(id: ID): void;
/**
* <zh/>
*
* <en/> Get the type of the element
* @param id - <zh/> ID | <en/> ID of the element
* @returns <zh/> | <en/> type of the element
*/
getElementType(id: ID): ElementType;
destroy(): void;
}