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; /** * 最近一次删除的 combo 的 id * * The ids of the last deleted combos * @remarks * 当删除 combo 后,会将其 id 从 comboIds 中移除,此时根据 Graphlib 的 changes 事件获取到的 NodeRemoved 无法区分是 combo 还是 node。 * 因此需要记录最近一次删除的 combo 的 id,并用于 isCombo 的判断 * * 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; protected comboIds: Set; /** * 获取详细数据变更 * * Get detailed data changes */ private changes; /** * 批处理计数器 * * Batch processing counter */ private batchCount; /** * 是否处于无痕模式 * * Whether it is in traceless mode */ private isTraceless; constructor(); private pushChange; getChanges(): DataChange[]; clearChanges(): void; batch(callback: () => void): void; protected isBatching(): boolean; /** * 执行操作而不会留下记录 * * Perform operations without leaving records * @param callback - 回调函数 | callback function * @remarks * 通常用于运行时调整元素并同步数据,避免触发数据变更导致重绘 * * 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[]; /** * 获取指定类型元素的数据 * * Get the data of the specified type of element * @param elementType - 元素类型 | element type * @returns 元素数据 | element data */ getElementsDataByType(elementType: ElementType): NodeData[] | EdgeData[] | ComboData[]; /** * 根据 ID 获取元素的数据,不用关心元素的类型 * * Get the data of the element by ID, no need to care about the type of the element * @param id - 元素 ID 数组 | element ID array * @returns 元素数据 | data of the element */ getElementDataById(id: ID): ElementDatum; /** * 获取节点的数据 * * Get node data * @param id - 节点 ID | node ID * @returns 节点数据 | node data */ getNodeLikeDatum(id: ID): NodeLikeData; /** * 获取所有节点和 combo 的数据 * * Get all node and combo data * @param ids - 节点和 combo ID 数组 | node and combo ID array * @returns 节点和 combo 的数据 | 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; /** * 计算 zIndex * * Calculate zIndex * @param data - 新增的数据 | newly added data * @param type - 操作类型 | operation type * @param force - 忽略批处理 | ignore batch processing * @remarks * 调用该函数的情况: * - 新增元素 * - 更新节点/组合的 combo * - 更新节点的 children * * 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; /** * 计算元素置顶后的 zIndex * * Calculate the zIndex after the element is placed on top * @param id - 元素 ID | ID of the element * @returns zIndex | zIndex */ getFrontZIndex(id: ID): number; protected updateNodeLikeHierarchy(data: NodeLikeData[]): void; private enableUpdateNodeLikeHierarchy; /** * 执行变更时不要更新节点层次结构 * * Do not update the node hierarchy when executing changes * @param callback - 变更函数 | change function */ preventUpdateNodeLikeHierarchy(callback: () => void): void; updateData(data: PartialGraphData): void; updateNodeData(nodes?: PartialNodeLikeData[]): void; /** * 将所有数据提交到变更记录中以进行重绘 * * Submit all data to the change record for redrawing */ refreshData(): void; syncNodeLikeDatum(datum: PartialNodeLikeData): void; syncEdgeDatum(datum: PartialEdgeData): void; updateEdgeData(edges?: PartialEdgeData[]): void; updateComboData(combos?: PartialNodeLikeData[]): void; /** * 设置节点的父节点 * * Set the parent node of the node * @param id - 节点 ID | node ID * @param parent - 父节点 ID | parent node ID * @param hierarchyKey - 层次结构类型 | hierarchy type * @param update - 添加新/旧父节点数据更新记录 | add new/old parent node data update record */ setParent(id: ID, parent: ID | undefined | null, hierarchyKey: HierarchyKey, update?: boolean): void; /** * 刷新 combo 数据 * * Refresh combo data * @param id - combo ID | combo ID * @remarks * 不会更改数据,但会触发数据变更事件 * * 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; /** * 移除节点层次结构,将其子节点移动到父节点的 children 列表中 * * Remove the node hierarchy and move its child nodes to the parent node's children list * @param id - 待处理的节点 | node to be processed */ protected removeNodeLikeHierarchy(id: ID): void; /** * 获取元素的类型 * * Get the type of the element * @param id - 元素 ID | ID of the element * @returns 元素类型 | type of the element */ getElementType(id: ID): ElementType; destroy(): void; }