### Get All Graph Data with Graph.getData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves the complete graph data, including all nodes, edges, and combos. Use this to get a full snapshot of the graph's current state. ```javascript const graphData = graph.getData(); console.log('Node data:', graphData.nodes); console.log('Edge data:', graphData.edges); console.log('Combo data:', graphData.combos); ``` -------------------------------- ### Get Combo Data with Graph.getComboData() Source: https://g6.antv.antgroup.com/en/api/data Fetches combo data. You can retrieve all combos, a specific combo by its ID, or multiple combos using an array of IDs. Useful for managing hierarchical graph structures. ```javascript // Get all combos const combos = graph.getComboData(); ``` ```javascript // Get single combo const combo = graph.getComboData('combo1'); console.log('Nodes in combo:', combo.children); ``` ```javascript // Get multiple combos const [combo1, combo2] = graph.getComboData(['combo1', 'combo2']); ``` -------------------------------- ### Get Edge Data with Graph.getEdgeData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves edge data. This method allows fetching all edges, a single edge by its ID, or multiple edges using an array of IDs. Ideal for analyzing or modifying edge properties. ```javascript // Get all edges const edges = graph.getEdgeData(); ``` ```javascript // Get single edge const edge = graph.getEdgeData('edge1'); console.log('Edge source and target:', edge.source, edge.target); ``` ```javascript // Get multiple edges const [edge1, edge2] = graph.getEdgeData(['edge1', 'edge2']); ``` -------------------------------- ### Get Node Data with Graph.getNodeData() Source: https://g6.antv.antgroup.com/en/api/data Fetches node data. Supports retrieving all nodes, a single node by ID, or multiple nodes by an array of IDs. Useful for inspecting or manipulating specific nodes. ```javascript // Get all nodes const nodes = graph.getNodeData(); ``` ```javascript // Get single node const node = graph.getNodeData('node1'); console.log('Node position:', node.style.x, node.style.y); ``` ```javascript // Get multiple nodes const [node1, node2] = graph.getNodeData(['node1', 'node2']); ``` -------------------------------- ### Get Neighbor Nodes Data Source: https://g6.antv.antgroup.com/en/api/data Fetch the data for all nodes directly connected to a given node or combo. Requires the ID of the node or combo. ```typescript getNeighborNodesData(id: ID): NodeData[]; ``` ```javascript const neighbors = graph.getNeighborNodesData('node-1'); console.log('Neighbor nodes:', neighbors); ``` -------------------------------- ### Get Ancestor Data in Combo Graph Source: https://g6.antv.antgroup.com/en/api/data Retrieves all parent combos for a given node. Specify 'combo' for hierarchy type. ```javascript // Get all parent combos in a combo const comboAncestors = graph.getAncestorsData('node1', 'combo'); ``` -------------------------------- ### Get Descendant Data Source: https://g6.antv.antgroup.com/en/api/data Retrieves all descendant elements of a specified node or combo. Logs the number of descendants and iterates through them. ```javascript // Get all descendants of a node const descendants = graph.getDescendantsData('node1'); console.log('Number of descendants:', descendants.length); // Process all descendant elements descendants.forEach((descendant) => { console.log('Descendant element ID:', descendant.id); }); ``` -------------------------------- ### Get Ancestor Data in Tree Graph Source: https://g6.antv.antgroup.com/en/api/data Retrieves all ancestor nodes in a tree structure. Specify 'tree' for hierarchy type. ```javascript // Get all ancestor nodes in a tree graph const treeAncestors = graph.getAncestorsData('node1', 'tree'); console.log( 'Ancestor node path:', treeAncestors.map((node) => node.id), ); ``` -------------------------------- ### Get Element Data with Graph.getElementData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves data for a single element (node or edge) by its ID, or multiple elements using an array of IDs. This method is type-agnostic and directly accesses element data. ```javascript const element = graph.getElementData('node-1'); console.log('Element data:', element); ``` ```javascript const elements = graph.getElementData(['node-1', 'edge-1']); console.log('Multiple element data:', elements); ``` -------------------------------- ### Get Element Data by State Source: https://g6.antv.antgroup.com/en/api/data Retrieve node, edge, or combo data based on a specified state. Ensure the state is one of the built-in states like 'selected', 'highlight', 'active', 'inactive', or 'disabled'. ```typescript getElementDataByState(elementType: 'node', state: string): NodeData[]; getElementDataByState(elementType: 'edge', state: string): EdgeData[]; getElementDataByState(elementType: 'combo', state: string): ComboData[]; ``` ```javascript const selectedNodes = graph.getElementDataByState('node', 'selected'); console.log('Selected nodes:', selectedNodes); const selectedEdges = graph.getElementDataByState('edge', 'selected'); console.log('Selected edges:', selectedEdges); const selectedCombos = graph.getElementDataByState('combo', 'selected'); console.log('Selected combos:', selectedCombos); ``` -------------------------------- ### Get Child Elements Data Source: https://g6.antv.antgroup.com/en/api/data Fetch data for child elements of a node or combo. For combos, it returns all direct children. For nodes, it only returns children if the graph data is a tree structure and the node has a 'children' field. ```typescript getChildrenData(id: ID): (NodeData | ComboData)[]; ``` ```javascript // Get the child elements of a combo const children = graph.getChildrenData('combo1'); console.log('Number of child nodes:', children.length); // Process each child element children.forEach((child) => { console.log('Child element ID:', child.id); }); ``` -------------------------------- ### Get Related Edges Data Source: https://g6.antv.antgroup.com/en/api/data Retrieve data for edges connected to a specific node or combo. You can optionally filter by edge direction ('in', 'out', or 'both'). ```typescript getRelatedEdgesData(id: ID, direction?: EdgeDirection): EdgeData[]; ``` ```javascript const relatedEdges = graph.getRelatedEdgesData('node-1'); console.log('Related edges:', relatedEdges); ``` -------------------------------- ### Get Parent Element Data Source: https://g6.antv.antgroup.com/en/api/data Obtain the data of the direct parent element for a given node or combo. Specify the hierarchy type ('tree' or 'combo'). Returns undefined if no parent exists. ```typescript getParentData(id: ID, hierarchy: HierarchyKey): NodeLikeData | undefined; ``` ```javascript // Get the parent node in a tree graph const treeParent = graph.getParentData('node1', 'tree'); // Get the parent combo in a combo const comboParent = graph.getParentData('node1', 'combo'); ``` -------------------------------- ### Graph.getComboData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves combo data, supporting fetching all combos, a single combo by ID, or multiple combos by an array of IDs. ```APIDOC ## Graph.getComboData() ### Description Get combo data, supporting three calling methods. ### Method ```javascript // Get all combo data getComboData(): ComboData[]; // Get single combo data getComboData(id: ID): ComboData; // Get multiple combo data getComboData(ids: ID[]): ComboData[]; ``` ### Parameters #### Path Parameters - **id** (string) - Required - Combo ID - **ids** (string[]) - Required - Combo ID array ### Return Value * **Type** : ComboData | ComboData[] * **Description** : Returns the specified combo data or combo data array ### Example ```javascript // Get all combos const combos = graph.getComboData(); // Get single combo const combo = graph.getComboData('combo1'); console.log('Nodes in combo:', combo.children); // Get multiple combos const [combo1, combo2] = graph.getComboData(['combo1', 'combo2']); ``` ``` -------------------------------- ### CustomPluginOption Type Definition Source: https://g6.antv.antgroup.com/en/api/plugin Defines the interface for custom plugin configurations. It requires a 'type' and optionally accepts a 'key' for unique identification, along with other configuration properties. ```typescript type CustomPluginOption = { // Plugin type type: string; // Plugin key, i.e., unique identifier // Used to identify the plugin for further operations key?: string; // Other configuration items for different types of plugins [configKey: string]: any; }; ``` -------------------------------- ### Graph.getData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves the complete data of the graph, including all nodes, edges, and combo data. ```APIDOC ## Graph.getData() ### Description Get the complete data of the graph. ### Method ```javascript getData(): Required; ``` ### Return Value * **Type** : GraphData * **Description** : Returns the complete graph data containing all nodes, edges, and combo data ### Example ```javascript const graphData = graph.getData(); console.log('Node data:', graphData.nodes); console.log('Edge data:', graphData.edges); console.log('Combo data:', graphData.combos); ``` ``` -------------------------------- ### UpdatePluginOption Type Definition Source: https://g6.antv.antgroup.com/en/api/plugin Defines the interface for updating plugin configurations. It requires a 'key' to identify the plugin and allows for updating other configuration items. ```typescript type UpdatePluginOption = { // Unique identifier of the plugin to be updated key: string; // Other configuration items to be updated [configKey: string]: unknown; }; ``` -------------------------------- ### Graph.getEdgeData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves edge data, supporting fetching all edges, a single edge by ID, or multiple edges by an array of IDs. ```APIDOC ## Graph.getEdgeData() ### Description Get edge data, supporting three calling methods. ### Method ```javascript // Get all edge data getEdgeData(): EdgeData[]; // Get single edge data getEdgeData(id: ID): EdgeData; // Get multiple edge data getEdgeData(ids: ID[]): EdgeData[]; ``` ### Parameters #### Path Parameters - **id** (string) - Required - Edge ID - **ids** (string[]) - Required - Edge ID array ### Return Value * **Type** : EdgeData | EdgeData[] * **Description** : Returns the specified edge data or edge data array ### Example ```javascript // Get all edges const edges = graph.getEdgeData(); // Get single edge const edge = graph.getEdgeData('edge1'); console.log('Edge source and target:', edge.source, edge.target); // Get multiple edges const [edge1, edge2] = graph.getEdgeData(['edge1', 'edge2']); ``` ``` -------------------------------- ### Set Graph Data Directly Source: https://g6.antv.antgroup.com/en/api/data Replaces the entire graph data with new nodes and edges. Use this for a complete data reset. ```javascript // Directly set data graph.setData({ nodes: [ { id: 'node1', style: { x: 100, y: 100 } }, { id: 'node2', style: { x: 200, y: 200 } }, ], edges: [{ id: 'edge1', source: 'node1', target: 'node2' }], }); ``` -------------------------------- ### PluginOptions Type Definition Source: https://g6.antv.antgroup.com/en/api/plugin Defines the structure for an array of plugin configurations. It can include strings, custom plugin options, or functions that return custom plugin options. ```typescript type PluginOptions = (string | CustomPluginOption | ((this: Graph) => CustomPluginOption)[]; ``` -------------------------------- ### Graph.setData() Source: https://g6.antv.antgroup.com/en/api/data Sets the complete data for the graph. This can be a new data object or a function that takes the previous data and returns the new data. ```APIDOC ## Graph.setData() ### Description Set the complete data of the graph. ### Method Signature ```typescript setData(data: GraphData | ((prev: GraphData) => GraphData)): void; ``` ### Parameters #### Path Parameters - **data** (GraphData | ((prev: GraphData) => GraphData)) - Required - New graph data or a function returning new graph data. ### Example ```javascript // Directly set data graph.setData({ nodes: [ { id: 'node1', style: { x: 100, y: 100 } }, { id: 'node2', style: { x: 200, y: 200 } }, ], edges: [{ id: 'edge1', source: 'node1', target: 'node2' }], }); // Use functional incremental update: get current graph data and return new graph data graph.setData((prev) => ({ ...prev, nodes: [...prev.nodes, { id: 'node3', style: { x: 300, y: 300 } }], })); ``` ``` -------------------------------- ### Graph.hasCombo() Source: https://g6.antv.antgroup.com/en/api/data Determines if a combo with the specified ID exists in the graph. ```APIDOC ## Graph.hasCombo() ### Description Determine if combo exists. ### Method Signature ```typescript hasCombo(id: ID): boolean; ``` ### Parameters #### Path Parameters - **id** (ID) - Required - Combo ID to be judged. ### Return Value - **Type**: boolean ### Example ```javascript graph.hasCombo('combo-1'); ``` ``` -------------------------------- ### Graph.getNeighborNodesData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves the data of all neighbor nodes connected to a given node or combo. ```APIDOC ## Graph.getNeighborNodesData() ### Description Get the data of neighbor nodes of a node or combo. ### Method Signature ```typescript getNeighborNodesData(id: ID): NodeData[]; ``` ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the node or combo whose neighbors are to be retrieved. ### Return Value - **Type**: NodeData[] - **Description**: Returns an array of NodeData objects representing the neighbor nodes. ### Example ```javascript const neighbors = graph.getNeighborNodesData('node-1'); console.log('Neighbor nodes:', neighbors); ``` ``` -------------------------------- ### Graph.updateComboData Source: https://g6.antv.antgroup.com/en/api/data Updates combo data in the graph. Only the data that needs to be updated should be passed. Accepts partial combo data or a function returning partial combo data. ```APIDOC ## Graph.updateComboData ### Description Update combo data in the graph. Only the data that needs to be updated needs to be passed in, not the complete data. ### Method `updateComboData(data: (ComboData[] | ((prev: ComboData[]) => ComboData[]))): void` ### Parameters #### Path Parameters - **data** (ComboData[] | ((prev: ComboData[]) => ComboData[])) - Required - The combo data to update, or a function that returns the combo data to update. ### Request Example ```javascript graph.updateComboData([{ id: 'combo-1', style: { x: 100, y: 100 } }]); ``` ``` -------------------------------- ### Add Node Data (Single and Multiple) Source: https://g6.antv.antgroup.com/en/api/data Adds one or more nodes to the graph. Supports direct data input or a functional update. ```javascript // Add single node graph.addNodeData([ { id: 'node1', style: { x: 100, y: 100 }, data: { label: 'Node 1' }, }, ]); // Add multiple nodes graph.addNodeData([ { id: 'node2', style: { x: 200, y: 200 } }, { id: 'node3', style: { x: 300, y: 300 } }, ]); ``` -------------------------------- ### Graph.addComboData() Source: https://g6.antv.antgroup.com/en/api/data Adds new combo data to the graph. Accepts an array of combo data objects or a function that returns combo data. ```APIDOC ## Graph.addComboData() ### Description Add new combo data. ### Method Signature ```typescript addComboData(data: ComboData[] | ((prev: ComboData[]) => ComboData[])): void; ``` ### Parameters #### Path Parameters - **data** (ComboData[] | ((prev: ComboData[]) => ComboData[])) - Required - Combo data to add or a function returning combo data. ### Example ```javascript graph.addComboData([{ id: 'combo1', children: ['node1', 'node2'] }]); ``` ``` -------------------------------- ### Define Combo Data structure Source: https://g6.antv.antgroup.com/en/api/data The `ComboData` interface specifies properties for combo data, including ID, type, data, style, states, and parent combo. ```typescript interface ComboData { id: string; // Combo ID type?: string; // Combo type data?: Record; // Combo data style?: Record; // Combo style states?: string[]; // Initial combo states combo?: string; // Parent combo ID } ``` -------------------------------- ### Add Edge Data (Single and Multiple) Source: https://g6.antv.antgroup.com/en/api/data Adds one or more edges to the graph. Supports direct data input or a functional update. ```javascript // Add single edge graph.addEdgeData([ { id: 'edge1', source: 'node1', target: 'node2', data: { weight: 1, label: 'Relation', }, }, ]); // Add multiple edges graph.addEdgeData([ { id: 'edge2', source: 'node2', target: 'node3' }, { id: 'edge3', source: 'node3', target: 'node1' }, ]); ``` -------------------------------- ### Graph.getNodeData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves node data, supporting fetching all nodes, a single node by ID, or multiple nodes by an array of IDs. ```APIDOC ## Graph.getNodeData() ### Description Get node data, supporting three calling methods. ### Method ```javascript // Get all node data getNodeData(): NodeData[]; // Get single node data getNodeData(id: ID): NodeData; // Get multiple node data getNodeData(ids: ID[]): NodeData[]; ``` ### Parameters #### Path Parameters - **id** (string) - Required - Node ID - **ids** (string[]) - Required - Node ID array ### Return Value * **Type** : NodeData | NodeData[] * **Description** : Returns the specified node data or node data array ### Example ```javascript // Get all nodes const nodes = graph.getNodeData(); // Get single node const node = graph.getNodeData('node1'); console.log('Node position:', node.style.x, node.style.y); // Get multiple nodes const [node1, node2] = graph.getNodeData(['node1', 'node2']); ``` ``` -------------------------------- ### Add Combo Data Source: https://g6.antv.antgroup.com/en/api/data Adds a new combo to the graph. Accepts an array of combo data objects. ```javascript graph.addComboData([{ id: 'combo1', children: ['node1', 'node2'] }]); ``` -------------------------------- ### Graph.getChildrenData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves the data of child elements for a given node or combo. Behavior varies based on whether the element is a node or a combo, and graph structure. ```APIDOC ## Graph.getChildrenData() ### Description Get the data of child elements of a node or combo. ### Method Signature ```typescript getChildrenData(id: ID): (NodeData | ComboData)[]; ``` ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the node or combo. ### Return Value - **Type**: (NodeData | ComboData)[] - **Description**: Returns an array of child element data. ### Note - **Querying combo's child elements**: If the id corresponds to a combo element, you can directly use this API to get all its child elements. - **Querying node's child elements**: If the id corresponds to a node, only when the graph data is a tree structure (i.e., the node data maintains a `children` field, and `children` is an array of child node IDs for that node), can you use this API to get the child elements of that node. Otherwise, an empty array is returned. ### Example ```javascript // Get the child elements of a combo const children = graph.getChildrenData('combo1'); console.log('Number of child nodes:', children.length); // Process each child element children.forEach((child) => { console.log('Child element ID:', child.id); }); ``` ``` -------------------------------- ### Graph.getElementDataByState() Source: https://g6.antv.antgroup.com/en/api/data Retrieves element data (nodes, edges, or combos) that are in a specified state. This method supports overloaded calls for different element types. ```APIDOC ## Graph.getElementDataByState() ### Description Get element data in a specified state, supporting three calling methods. ### Method Signature ```typescript // Get node data in a specified state getElementDataByState(elementType: 'node', state: string): NodeData[]; // Get edge data in a specified state getElementDataByState(elementType: 'edge', state: string): EdgeData[]; // Get combo data in a specified state getElementDataByState(elementType: 'combo', state: string): ComboData[]; ``` ### Parameters #### Path Parameters - **elementType** (string) - Required - Element type ('node', 'edge', or 'combo'). - **state** (string) - Required - The state to filter elements by. ### Return Value - **Type**: NodeData[] | EdgeData[] | ComboData[] - **Description**: Returns an array of node data, edge data, or combo data matching the specified state. ### Example ```javascript // Get node data in a specified state const selectedNodes = graph.getElementDataByState('node', 'selected'); console.log('Selected nodes:', selectedNodes); // Get edge data in a specified state const selectedEdges = graph.getElementDataByState('edge', 'selected'); console.log('Selected edges:', selectedEdges); // Get combo data in a specified state const selectedCombos = graph.getElementDataByState('combo', 'selected'); console.log('Selected combos:', selectedCombos); ``` ### Built-in States - `'selected'` - `'highlight'` - `'active'` - `'inactive'` - `'disabled'` ``` -------------------------------- ### Define Node Data structure Source: https://g6.antv.antgroup.com/en/api/data The `NodeData` interface specifies properties for node data, including ID, type, data, style, states, combo, and children. ```typescript interface NodeData { id: string; // Node ID type?: string; // Node type data?: Record; // Node data style?: Record; // Node style states?: string[]; // Initial node states combo?: string; // Belonging combo children?: string[]; // Array of child node IDs } ``` -------------------------------- ### Define Edge Data structure Source: https://g6.antv.antgroup.com/en/api/data The `EdgeData` interface defines properties for edge data, including source, target, ID, type, data, style, and states. ```typescript interface EdgeData { source: string; // Source ID target: string; // Target ID id?: string; // Edge ID type?: string; // Edge type data?: Record; // Edge data style?: Record; // Edge style states?: string[]; // Initial edge states } ``` -------------------------------- ### Graph.addData() Source: https://g6.antv.antgroup.com/en/api/data Adds new element data to the graph. This can be a data object or a function that takes the previous data and returns the new data. ```APIDOC ## Graph.addData() ### Description Add new element data. ### Method Signature ```typescript addData(data: GraphData | ((prev: GraphData) => GraphData)): void; ``` ### Parameters #### Path Parameters - **data** (GraphData | ((prev: GraphData) => GraphData)) - Required - Graph data to add or a function returning new graph data. ### Example ```javascript graph.addData({ nodes: [{ id: 'node-1' }, { id: 'node-2' }], edges: [{ source: 'node-1', target: 'node-2' }], }); ``` ``` -------------------------------- ### Graph.updateData Source: https://g6.antv.antgroup.com/en/api/data Updates element data in the graph. Only the data that needs to be updated should be passed, not the complete data. Accepts partial data or a function returning partial data. ```APIDOC ## Graph.updateData ### Description Update element data in the graph. Only the data that needs to be updated needs to be passed in, not the complete data. ### Method `updateData(data: PartialGraphData | ((prev: GraphData) => PartialGraphData)): void` ### Parameters #### Path Parameters - **data** (PartialGraphData | ((prev: GraphData) => PartialGraphData)) - Required - The element data to update, or a function that returns the element data to update. ### Request Example ```javascript graph.updateData({ nodes: [{ id: 'node-1', style: { x: 100, y: 100 } }], edges: [{ id: 'edge-1', style: { lineWidth: 2 } }], }); ``` ``` -------------------------------- ### Graph.getAncestorsData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves the data for all ancestor elements (nodes or combos) of a specified node or combo. The results are ordered from parent to root. ```APIDOC ## Graph.getAncestorsData() ### Description Get the data of all ancestor elements of a node or combo. ### Method Signature ```typescript getAncestorsData(id: ID, hierarchy: HierarchyKey): NodeLikeData[]; ``` ### Parameters #### Path Parameters - **id** (string) - Required - Node or combo ID - **hierarchy** (string) - Required - Specify hierarchy type. Accepted values: 'tree', 'combo'. ### Return Value - **Type**: NodeData[] | ComboData[] - **Description**: Returns an array of ancestor element data, ordered from parent to root. ### Example ```javascript // Get all ancestor nodes in a tree graph const treeAncestors = graph.getAncestorsData('node1', 'tree'); console.log('Ancestor node path:', treeAncestors.map((node) => node.id)); // Get all parent combos in a combo const comboAncestors = graph.getAncestorsData('node1', 'combo'); ``` ``` -------------------------------- ### Graph.updateEdgeData Source: https://g6.antv.antgroup.com/en/api/data Updates edge data in the graph. Only the data that needs to be updated should be passed. Accepts partial edge data or a function returning partial edge data. ```APIDOC ## Graph.updateEdgeData ### Description Update edge data in the graph. Only the data that needs to be updated needs to be passed in, not the complete data. ### Method `updateEdgeData(data: (PartialEdgeData[] | ((prev: EdgeData[]) => PartialEdgeData[]))): void` ### Parameters #### Path Parameters - **data** (PartialEdgeData[] | ((prev: EdgeData[]) => PartialEdgeData[])) - Required - The edge data to update, or a function that returns the edge data to update. ### Request Example ```javascript graph.updateEdgeData([{ id: 'edge-1', style: { lineWidth: 2 } }]); ``` ``` -------------------------------- ### Graph.getElementData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves data for a single element or multiple elements by their IDs, without considering element type. ```APIDOC ## Graph.getElementData() ### Description Get single element data, supporting two calling methods. ⚠️ **Note** : This API directly gets the data of the element without considering the element type. ### Method ```javascript // Get single element data getElementData(id: ID): ElementDatum; // Get multiple element data getElementData(ids: ID[]): ElementDatum[]; ``` ### Parameters #### Path Parameters - **id** (string) - Required - Element ID - **ids** (string[]) - Required - Element ID array ### Return Value * **Type** : ElementDatum | ElementDatum[] * **Description** : Directly gets the data of the element without considering the element type ### Example ```javascript const element = graph.getElementData('node-1'); console.log('Element data:', element); const elements = graph.getElementData(['node-1', 'edge-1']); console.log('Multiple element data:', elements); ``` ``` -------------------------------- ### Check if a combo exists in the graph Source: https://g6.antv.antgroup.com/en/api/data Use `hasCombo` to determine if a combo with the specified ID exists in the graph. Requires the combo ID as a string. ```typescript hasCombo(id:ID): boolean; ``` ```typescript graph.hasCombo('combo-1'); ``` -------------------------------- ### Define Graph Data structure Source: https://g6.antv.antgroup.com/en/api/data The `GraphData` interface defines the structure for graph data, including nodes, edges, and combos. ```typescript interface GraphData { nodes?: NodeData[]; edges?: EdgeData[]; combos?: ComboData[]; } ``` -------------------------------- ### Graph.getParentData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves the data of the parent element for a given node or combo, specifying the hierarchy type. ```APIDOC ## Graph.getParentData() ### Description Get the data of the parent element of a node or combo. ### Method Signature ```typescript getParentData(id: ID, hierarchy: HierarchyKey): NodeLikeData | undefined; ``` ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the node or combo. - **hierarchy** (string) - Required - Specifies the hierarchy type. Can be 'tree' or 'combo'. ### Return Value - **Type**: NodeData | ComboData | undefined - **Description**: Returns the parent element data, or undefined if it does not exist. ### Example ```javascript // Get the parent node in a tree graph const treeParent = graph.getParentData('node1', 'tree'); // Get the parent combo in a combo const comboParent = graph.getParentData('node1', 'combo'); ``` ``` -------------------------------- ### Graph.hasNode Source: https://g6.antv.antgroup.com/en/api/data Determines if a node with the specified ID exists in the graph. ```APIDOC ## Graph.hasNode ### Description Determine if a node exists in the graph. ### Method `hasNode(id: ID): boolean` ### Parameters #### Path Parameters - **id** (ID) - Required - The ID of the node to check for existence. ### Return Value - **Type**: boolean ### Request Example ```javascript graph.hasNode('node-1'); ``` ``` -------------------------------- ### Add Child Nodes to a Tree Graph Source: https://g6.antv.antgroup.com/en/api/data Use this method to add child node data to a specific parent node in a tree graph. For adding children to combos, use addNodeData or addComboData. ```typescript graph.addChildrenData('node1', [{ id: 'node2' }]); ``` -------------------------------- ### Set Graph Data Functionally Source: https://g6.antv.antgroup.com/en/api/data Updates graph data by providing a function that receives previous data and returns new data. Useful for incremental updates. ```javascript // Use functional incremental update: get current graph data and return new graph data graph.setData((prev) => ({ ...prev, nodes: [...prev.nodes, { id: 'node3', style: { x: 300, y: 300 } }], })); ``` -------------------------------- ### Add Node Data (Functional) Source: https://g6.antv.antgroup.com/en/api/data Adds a new node to the graph using a functional approach, appending to the previous node data. ```javascript // Functional addition graph.addNodeData((prev) => [...prev, { id: 'node4', style: { x: 400, y: 400 } }]); ``` -------------------------------- ### Graph.hasEdge() Source: https://g6.antv.antgroup.com/en/api/data Determines if an edge with the specified ID exists in the graph. ```APIDOC ## Graph.hasEdge() ### Description Determine if an edge exists. ### Method Signature ```typescript hasEdge(id: ID): boolean; ``` ### Parameters #### Path Parameters - **id** (ID) - Required - Edge ID to be judged. ### Return Value - **Type**: boolean ### Example ```javascript graph.hasEdge('edge-1'); ``` ``` -------------------------------- ### Add Graph Data Source: https://g6.antv.antgroup.com/en/api/data Adds new nodes and edges to the existing graph data. Can accept a data object or a function for updates. ```javascript graph.addData({ nodes: [{ id: 'node-1' }, { id: 'node-2' }], edges: [{ source: 'node-1', target: 'node-2' }], }); ``` -------------------------------- ### Graph.getDescendantsData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves the data for all descendant elements (nodes or combos) of a specified node or combo. ```APIDOC ## Graph.getDescendantsData() ### Description Get the data of all descendant elements of a node or combo. ### Method Signature ```typescript getDescendantsData(id: ID): NodeLikeData[]; ``` ### Parameters #### Path Parameters - **id** (string) - Required - Node or combo ID ### Return Value - **Type**: NodeData[] | ComboData[] - **Description**: Returns an array of descendant element data. ### Example ```javascript // Get all descendants of a node const descendants = graph.getDescendantsData('node1'); console.log('Number of descendants:', descendants.length); // Process all descendant elements descendants.forEach((descendant) => { console.log('Descendant element ID:', descendant.id); }); ``` ``` -------------------------------- ### Graph.addEdgeData() Source: https://g6.antv.antgroup.com/en/api/data Adds new edge data to the graph. Accepts an array of edge data objects or a function that returns edge data. ```APIDOC ## Graph.addEdgeData() ### Description Add new edge data. ### Method Signature ```typescript addEdgeData(data: EdgeData[] | ((prev: EdgeData[]) => EdgeData[])): void; ``` ### Parameters #### Path Parameters - **data** (EdgeData[] | ((prev: EdgeData[]) => EdgeData[])) - Required - Edge data to add or a function returning edge data. ### Example ```javascript // Add single edge graph.addEdgeData([ { id: 'edge1', source: 'node1', target: 'node2', data: { weight: 1, label: 'Relation', }, }, ]); // Add multiple edges graph.addEdgeData([ { id: 'edge2', source: 'node2', target: 'node3' }, { id: 'edge3', source: 'node3', target: 'node1' }, ]); // Functional addition graph.addEdgeData((prev) => [...prev, { id: 'edge4', source: 'node1', target: 'node4' }]); ``` ``` -------------------------------- ### Update Graph Data Source: https://g6.antv.antgroup.com/en/api/data Updates existing graph elements. Pass only the data that needs to be updated, not the complete data. This method accepts partial data or a function returning partial data. ```typescript graph.updateData({ nodes: [{ id: 'node-1', style: { x: 100, y: 100 } }], edges: [{ id: 'edge-1', style: { lineWidth: 2 } }], }); ``` -------------------------------- ### Update Combo Data Source: https://g6.antv.antgroup.com/en/api/data Updates existing combo data. Only the data that needs to be updated should be passed. Accepts an array of combo data or a function returning combo data. ```typescript graph.updateComboData([{ id: 'combo-1', style: { x: 100, y: 100 } }]); ``` -------------------------------- ### Graph.addNodeData() Source: https://g6.antv.antgroup.com/en/api/data Adds new node data to the graph. Accepts an array of node data objects or a function that returns node data. ```APIDOC ## Graph.addNodeData() ### Description Add new node data. ### Method Signature ```typescript addNodeData(data: NodeData[] | ((prev: NodeData[]) => NodeData[])): void; ``` ### Parameters #### Path Parameters - **data** (NodeData[] | ((prev: NodeData[]) => NodeData[])) - Required - Node data to add or a function returning node data. ### Example ```javascript // Add single node graph.addNodeData([ { id: 'node1', style: { x: 100, y: 100 }, data: { label: 'Node 1' }, }, ]); // Add multiple nodes graph.addNodeData([ { id: 'node2', style: { x: 200, y: 200 } }, { id: 'node3', style: { x: 300, y: 300 } }, ]); // Functional addition graph.addNodeData((prev) => [...prev, { id: 'node4', style: { x: 400, y: 400 } }]); ``` ``` -------------------------------- ### Graph.addChildrenData Source: https://g6.antv.antgroup.com/en/api/data Adds child node data to a specified parent node in a tree graph. Note: For adding children to a combo, use addNodeData or addComboData. ```APIDOC ## Graph.addChildrenData ### Description Add child node data to a tree graph node. ### Method `addChildrenData(parentId: ID, childrenData: NodeData[]): void` ### Parameters #### Path Parameters - **parentId** (string) - Required - The ID of the parent node to which children will be added. - **childrenData** (NodeData[]) - Required - An array of node data objects representing the children to add. ### Request Example ```javascript graph.addChildrenData('node1', [{ id: 'node2' }]); ``` ``` -------------------------------- ### Add Edge Data (Functional) Source: https://g6.antv.antgroup.com/en/api/data Adds a new edge to the graph using a functional approach, appending to the previous edge data. ```javascript // Functional addition graph.addEdgeData((prev) => [...prev, { id: 'edge4', source: 'node1', target: 'node4' }]); ``` -------------------------------- ### Graph.updateNodeData Source: https://g6.antv.antgroup.com/en/api/data Updates node data in the graph. Only the data that needs to be updated should be passed. Accepts partial node data or a function returning partial node data. ```APIDOC ## Graph.updateNodeData ### Description Update node data in the graph. Only the data that needs to be updated needs to be passed in, not the complete data. ### Method `updateNodeData(data: NodeData[] | ((prev: NodeData[]) => NodeData[])): void` ### Parameters #### Path Parameters - **data** (NodeData[] | ((prev: NodeData[]) => NodeData[])) - Required - The node data to update, or a function that returns the node data to update. ### Request Example ```javascript graph.updateNodeData([{ id: 'node-1', style: { x: 100, y: 100 } }]); ``` ``` -------------------------------- ### Check if Node Exists Source: https://g6.antv.antgroup.com/en/api/data Determines if a node with the specified ID exists in the graph. ```typescript graph.hasNode('node-1'); ``` -------------------------------- ### Update Node Data Source: https://g6.antv.antgroup.com/en/api/data Updates existing node data. Only the data that needs to be updated should be passed. Accepts an array of node data or a function returning node data. ```typescript graph.updateNodeData([{ id: 'node-1', style: { x: 100, y: 100 } }]); ``` -------------------------------- ### Define Multiple Element ID type Source: https://g6.antv.antgroup.com/en/api/data The `DataID` interface allows specifying arrays of node, edge, or combo IDs. ```typescript interface DataID { nodes?: ID[]; edges?: ID[]; combos?: ID[]; } ``` -------------------------------- ### Update Edge Data Source: https://g6.antv.antgroup.com/en/api/data Updates existing edge data. Only the data that needs to be updated should be passed. Accepts an array of partial edge data or a function returning edge data. ```typescript graph.updateEdgeData([{ id: 'edge-1', style: { lineWidth: 2 } }]); ``` -------------------------------- ### Define Element ID type Source: https://g6.antv.antgroup.com/en/api/data The `ID` type is defined as a string, used for identifying graph elements. ```typescript type ID = string; ``` -------------------------------- ### Check if an edge exists in the graph Source: https://g6.antv.antgroup.com/en/api/data Use `hasEdge` to determine if an edge with the specified ID exists in the graph. Requires the edge ID as a string. ```typescript hasEdge(id:ID): boolean; ``` ```typescript graph.hasEdge('edge-1'); ``` -------------------------------- ### Graph.removeComboData Source: https://g6.antv.antgroup.com/en/api/data Removes combo data from the graph. Accepts either an array of combo IDs or a function that returns an array of combo IDs. ```APIDOC ## Graph.removeComboData ### Description Remove combo data from the graph. ### Method `removeComboData(ids: ID[] | ((data: ComboData[]) => ID[])): void` ### Parameters #### Path Parameters - **ids** (ID[] | ((data: ComboData[]) => ID[])) - Required - The IDs of the combos to remove, or a function that returns the combo IDs. ### Request Example ```javascript graph.removeComboData(['combo-1']); ``` ``` -------------------------------- ### Graph.getRelatedEdgesData() Source: https://g6.antv.antgroup.com/en/api/data Retrieves the data of edges that are related to a specified node or combo, with an option to filter by direction. ```APIDOC ## Graph.getRelatedEdgesData() ### Description Get the data of edges related to a node or combo. ### Method Signature ```typescript getRelatedEdgesData(id: ID, direction?: EdgeDirection): EdgeData[]; ``` ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the node or combo. - **direction** (string) - Optional - The direction of the edges to retrieve. Can be 'in', 'out', or 'both'. ### Return Value - **Type**: EdgeData[] - **Description**: Returns an array of EdgeData objects representing the related edges. ### Example ```javascript const relatedEdges = graph.getRelatedEdgesData('node-1'); console.log('Related edges:', relatedEdges); ``` ``` -------------------------------- ### Graph.removeEdgeData Source: https://g6.antv.antgroup.com/en/api/data Removes edge data from the graph. Accepts either an array of edge IDs or a function that returns an array of edge IDs. ```APIDOC ## Graph.removeEdgeData ### Description Remove edge data from the graph. ### Method `removeEdgeData(ids: ID[] | ((data: EdgeData[]) => ID[])): void` ### Parameters #### Path Parameters - **ids** (ID[] | ((data: EdgeData[]) => ID[])) - Required - The IDs of the edges to remove, or a function that returns the edge IDs. ### Request Example ```javascript graph.removeEdgeData(['edge-1']); ``` ``` -------------------------------- ### Remove Edge Data by IDs Source: https://g6.antv.antgroup.com/en/api/data Removes specified edges from the graph. Accepts an array of edge IDs or a function that returns an array of edge IDs to be removed. ```typescript graph.removeEdgeData(['edge-1']); ``` -------------------------------- ### Remove Combo Data by IDs Source: https://g6.antv.antgroup.com/en/api/data Removes specified combos from the graph. Accepts an array of combo IDs or a function that returns an array of combo IDs to be removed. ```typescript graph.removeComboData(['combo-1']); ``` -------------------------------- ### Remove Graph Data by IDs Source: https://g6.antv.antgroup.com/en/api/data Removes specified nodes and edges from the graph. You can provide a list of IDs or a function that returns a list of IDs to remove. ```typescript graph.removeData({ nodes: ['node-1', 'node-2'], edges: ['edge-1'], }); ``` -------------------------------- ### Remove Node Data by IDs Source: https://g6.antv.antgroup.com/en/api/data Removes specified nodes from the graph. Accepts an array of node IDs or a function that returns an array of node IDs to be removed. ```typescript graph.removeNodeData(['node-1', 'node-2']); ``` -------------------------------- ### Graph.removeNodeData Source: https://g6.antv.antgroup.com/en/api/data Removes node data from the graph. Accepts either an array of node IDs or a function that returns an array of node IDs. ```APIDOC ## Graph.removeNodeData ### Description Remove node data from the graph. ### Method `removeNodeData(ids: ID[] | ((data: NodeData[]) => ID[])): void` ### Parameters #### Path Parameters - **ids** (ID[] | ((data: NodeData[]) => ID[])) - Required - The IDs of the nodes to remove, or a function that returns the node IDs. ### Request Example ```javascript graph.removeNodeData(['node-1', 'node-2']); ``` ``` -------------------------------- ### Graph.removeData Source: https://g6.antv.antgroup.com/en/api/data Removes specified elements (nodes, edges, combos) from the graph based on their IDs or a function that returns IDs. ```APIDOC ## Graph.removeData ### Description Remove element data from the graph. ### Method `removeData(ids: DataID | ((data: GraphData) => DataID)): void` ### Parameters #### Path Parameters - **ids** (DataID | ((data: GraphData) => DataID)) - Required - The IDs of the elements to remove, or a function that returns the element IDs. ### Request Example ```javascript graph.removeData({ nodes: ['node-1', 'node-2'], edges: ['edge-1'], }); ``` ```