import type { ID, State } from '../types'; import type { ComboStyle } from './element/combo'; import type { EdgeStyle } from './element/edge'; import type { NodeStyle } from './element/node'; /** * 图数据 * * Graph data * @remarks * 图数据(GraphData)是 Graph 接收的数据类型之一,包含节点、边、组合的集合。 * * 一个图数据的示例如下: * * Graph data is one of the data types received by Graph, which contains a collection of nodes, edges, and combos. * * An example of a graph data is as follows: * * ```json * { * "nodes": [ * { "id": "node1", "combo": "combo-1", "style": { "x": 100, "y": 100 } }, * { "id": "node2", "style": { "x": 200, "y": 200 } } * ], * "edges": [{ "source": "node1", "target": "node2" }], * "combos": [{ "id": "combo-1", "style": { "x": 100, "y": 100 } }] * } * ``` */ export interface GraphData { /** * 节点数据 * * node data */ nodes?: NodeData[]; /** * 边数据 * * edge data */ edges?: EdgeData[]; /** * Combo 数据 * * combo data */ combos?: ComboData[]; } /** * 节点数据 * * Node data */ export interface NodeData { /** * 节点 ID * * Node ID */ id: ID; /** * 节点类型 * * Node type */ type?: string; /** * 节点数据 * * Node data * @remarks * 用于存储节点的自定义数据,可以在样式映射中通过回调函数获取 * * Used to store custom data of the node, which can be obtained through callback functions in the style mapping */ data?: Record; /** * 节点样式 * * Node style */ style?: NodeStyle; /** * 节点初始状态 * * Initial state of the node */ states?: State[]; /** * 所属组合 ID * * ID of the combo to which the node belongs */ combo?: ID | null; /** * 子节点 ID * * Child node ID * @remarks * 适用于树图结构 * * Suitable for tree graph structure */ children?: ID[]; /** * 节点深度 * * Node depth * @remarks * 适用于树图结构 * * Suitable for tree graph structure */ depth?: number; [key: string]: unknown; } /** * 组合数据 * * Combo data */ export interface ComboData { /** * Combo ID * * Combo ID */ id: ID; /** * Combo 类型 * * Combo type */ type?: string; /** * Combo 数据 * * Combo data * @remarks * 用于存储 Combo 的自定义数据,可以在样式映射中通过回调函数获取 * * Used to store custom data of the Combo, which can be obtained through callback functions in the style mapping */ data?: Record; /** * Combo 样式 * * Combo style */ style?: ComboStyle; /** * 组合初始状态 * * Initial state of the combo */ states?: State[]; /** * 所属组合 ID * * ID of the combo to which the combo belongs */ combo?: ID | null; [key: string]: unknown; } /** * 边数据 * * Edge data */ export interface EdgeData { /** * 边 ID * * Edge ID */ id?: ID; /** * 边起始节点 ID * * Source node ID */ source: ID; /** * 边目标节点 ID * * Target node ID */ target: ID; /** * 边类型 * * Edge type */ type?: string; /** * 边数据 * * Edge data * @remarks * 用于存储边的自定义数据,可以在样式映射中通过回调函数获取 * * Used to store custom data of the edge, which can be obtained through callback functions in the style mapping */ data?: Record; /** * 边样式 * * Edge style */ style?: EdgeStyle; /** * 边初始状态 * * Initial state of the edge */ states?: State[]; [key: string]: unknown; }