Add child node data to the tree node
addChildrenData(parentId: ID, childrenData: NodeData[]): void;
Use addNodeData / addComboData method to add child nodes to the combo
Parameter | Type | Description |
---|---|---|
parentId | string | 父节点 ID |
childrenData | NodeData | 子节点数据 |
Returns:
Add combo data
addComboData(data: ComboData[] | ((prev: ComboData[]) => ComboData[])): void;
Example
graph.addComboData([{ id: 'combo-1' }]);
Parameter | Type | Description |
---|---|---|
data | ComboData | 组合数据 |
Returns:
Add element data
addData(data: GraphData | ((prev: GraphData) => GraphData)): void;
Example
graph.addData({nodes: [{ id: 'node-1' }, { id: 'node-2' }],edges: [{ source: 'node-1', target: 'node-2' }],});
Parameter | Type | Description |
---|---|---|
data | 元素数据 |
Returns:
Add edge data
addEdgeData(data: EdgeData[] | ((prev: EdgeData[]) => EdgeData[])): void;
Example
graph.addEdgeData([{ source: 'node-1', target: 'node-2' }]);
Parameter | Type | Description |
---|---|---|
data | 边数据 |
Returns:
Add node data
addNodeData(data: NodeData[] | ((prev: NodeData[]) => NodeData[])): void;
Example
graph.addNodeData([{ id: 'node-1' }, { id: 'node-2' }]);
Parameter | Type | Description |
---|---|---|
data | NodeData | 节点数据 |
Returns:
Get the ancestor element data of the node or combo
getAncestorsData(id: ID, hierarchy: HierarchyKey): NodeLikeData[];
The order in the array is from the parent node to the ancestor node
Parameter | Type | Description |
---|---|---|
id | string | 节点或组合ID |
hierarchy | 'tree' | 'combo' | 指定树图层级关系还是组合层级关系 |
Returns:
Type: NodeData | ComboData[]
Description: 祖先元素数据
Get the child element data of the node or combo
getChildrenData(id: ID): NodeLikeData[];
Parameter | Type | Description |
---|---|---|
id | string | 节点或组合ID |
Returns:
Type: NodeData | ComboData[]
Description: 子元素数据
Get all combo data
getComboData(): ComboData[];
Returns:
Type: []
Description: 组合数据
Get single combo data
getComboData(id: ID): ComboData;
Example
const combo1 = graph.getComboData('combo-1');
Parameter | Type | Description |
---|---|---|
id | string | 组合ID |
Returns:
Type:
Description: 组合数据
Get multiple combo data in batch
getComboData(ids: ID[]): ComboData[];
Example
const [combo1, combo2] = graph.getComboData(['combo-1', 'combo-2']);
Parameter | Type | Description |
---|---|---|
ids | string[] | 组合ID 数组 |
Returns:
Get graph data
getData(): Required<GraphData>;
Returns:
Type: Required<>
Description: 图数据
Get the descendant element data of the node or combo
getDescendantsData(id: ID): NodeLikeData[];
Parameter | Type | Description |
---|---|---|
id | string | 节点或组合ID |
Returns:
Type: NodeData | ComboData[]
Description: 后代元素数据
Get all edge data
getEdgeData(): EdgeData[];
Get single edge data
getEdgeData(id: ID): EdgeData;
Example
const edge1 = graph.getEdgeData('edge-1');
Get multiple edge data in batch
getEdgeData(ids: ID[]): EdgeData[];
Example
const [edge1, edge2] = graph.getEdgeData(['edge-1', 'edge-2']);
Get element data by ID
getElementData(id: ID): ElementDatum;
Get element data directly without considering the element type
Parameter | Type | Description |
---|---|---|
id | string | 元素 ID |
Returns:
Type: NodeData | EdgeData | ComboData
Description: 元素数据
Get multiple element data in batch
getElementData(ids: ID[]): ElementDatum[];
Get element data directly without considering the element type
Parameter | Type | Description |
---|---|---|
ids | string[] | 元素 ID 数组 |
Returns:
Get node data in a specific state
getElementDataByState(elementType: 'node', state: State): NodeData[];
Example
const nodes = graph.getElementDataByState('node', 'selected');
Parameter | Type | Description |
---|---|---|
elementType | 'node' | |
state | string | 状态 |
Returns:
Type: NodeData[]
Description: 节点数据
Get edge data in a specific state
getElementDataByState(elementType: 'edge', state: State): EdgeData[];
Example
const nodes = graph.getElementDataByState('edge', 'selected');
Parameter | Type | Description |
---|---|---|
elementType | 'edge' | |
state | string | 状态 |
Returns:
Type: EdgeData[]
Description: 边数据
Get combo data in a specific state
getElementDataByState(elementType: 'combo', state: State): ComboData[];
Example
const nodes = graph.getElementDataByState('node', 'selected');
Parameter | Type | Description |
---|---|---|
elementType | 'combo' | |
state | string | 状态 |
Returns:
Type: []
Description: 组合数据
Get the one-hop neighbor node data of the node or combo
getNeighborNodesData(id: ID): NodeData[];
Parameter | Type | Description |
---|---|---|
id | string | 节点或组合ID |
Returns:
Type: []
Description: 邻居节点数据
Get all node data
getNodeData(): NodeData[];
Returns:
Type: []
Description: 节点数据
Get single node data
getNodeData(id: ID): NodeData;
Example
const node1 = graph.getNodeData('node-1');
Parameter | Type | Description |
---|---|---|
id | string | 节点 ID |
Returns:
Type:
Description: 节点数据
Get multiple node data in batch
getNodeData(ids: ID[]): NodeData[];
Example
const [node1, node2] = graph.getNodeData(['node-1', 'node-2']);
Parameter | Type | Description |
---|---|---|
ids | string[] | 节点 ID 数组 |
Returns:
Type: NodeData[]
Description: 节点数据
Get the parent element data of the node or combo
getParentData(id: ID, hierarchy: HierarchyKey): NodeLikeData | undefined;
Parameter | Type | Description |
---|---|---|
id | string | 节点或组合ID |
hierarchy | 'tree' | 'combo' | 指定树图层级关系还是组合层级关系 |
Returns:
Type: NodeData | ComboData | undefined
Description: 父元素数据
Get edge data related to the node or combo
getRelatedEdgesData(id: ID, direction?: EdgeDirection): EdgeData[];
Parameter | Type | Description |
---|---|---|
id | string | 节点或组合ID |
direction | 'in' | 'out' | 'both' | 边的方向 |
Returns:
Type: EdgeData[]
Description: 边数据
Remove combo data
removeComboData(ids: ID[] | ((data: ComboData[]) => ID[])): void;
Example
graph.removeComboData(['combo-1']);
Parameter | Type | Description |
---|---|---|
ids | string[] | ((data: []) => string[]) | 组合 ID 数组 |
Returns:
Remove element data
removeData(ids: DataID | ((data: GraphData) => DataID)): void;
Example
graph.removeData({nodes: ['node-1', 'node-2'],edges: ['edge-1'],});
Parameter | Type | Description |
---|---|---|
ids | DataID | ((data: ) => DataID) | 元素 ID 数组 |
Returns:
Remove edge data
removeEdgeData(ids: ID[] | ((data: EdgeData[]) => ID[])): void;
If only the source and target are provided when passing in the edge data, you need to get the actual ID of the edge through the idOf
method
Example
graph.removeEdgeData(['edge-1']);
Parameter | Type | Description |
---|---|---|
ids | string[] | ((data: EdgeData[]) => string[]) | 边 ID 数组 |
Returns:
Remove node data
removeNodeData(ids: ID[] | ((data: NodeData[]) => ID[])): void;
Example
graph.removeNodeData(['node-1', 'node-2']);
Parameter | Type | Description |
---|---|---|
ids | string[] | ((data: []) => string[]) | 节点 ID 数组 |
Returns:
Set full data
setData(data: GraphData | ((prev: GraphData) => GraphData)): void;
Setting full data will replace all data in the current graph, and G6 will automatically calculate the data difference
Parameter | Type | Description |
---|---|---|
data | | ((prev: ) => ) | 数据 |
Returns:
Update combo data
updateComboData(data: PartialNodeLikeData<ComboData>[] | ((prev: ComboData[]) => PartialNodeLikeData<ComboData>[])): void;
Just pass in the data that needs to be updated, no need to pass in the complete data
Example
graph.updateComboData([{ id: 'combo-1', style: { x: 100, y: 100 } }]);
Parameter | Type | Description |
---|---|---|
data | PartialNodeLikeData<>[] | ((prev: []) => PartialNodeLikeData<>[]) | 组合数据 |
Returns:
Update element data
updateData(data: PartialGraphData | ((prev: GraphData) => PartialGraphData)): void;
Just pass in the data that needs to be updated, no need to pass in the complete data
Example
graph.updateData({nodes: [{ id: 'node-1', style: { x: 100, y: 100 } }],edges: [{ id: 'edge-1', style: { lineWidth: 2 } }],});
Parameter | Type | Description |
---|---|---|
data | PartialGraphData | ((prev: ) => PartialGraphData) | 元素数据 |
Returns:
Update edge data
updateEdgeData(data: PartialEdgeData<EdgeData>[] | ((prev: EdgeData[]) => PartialEdgeData<EdgeData>[])): void;
Just pass in the data that needs to be updated, no need to pass in the complete data
Example
graph.updateEdgeData([{ id: 'edge-1', style: { lineWidth: 2 } }]);
Returns:
Update node data
updateNodeData(data: PartialNodeLikeData<NodeData>[] | ((prev: NodeData[]) => PartialNodeLikeData<NodeData>[])): void;
Just pass in the data that needs to be updated, no need to pass in the complete data
Example
graph.updateNodeData([{ id: 'node-1', style: { x: 100, y: 100 } }]);
Parameter | Type | Description |
---|---|---|
data | NodeData | 节点数据 |
Returns: