mirror of
https://gitee.com/antv/g6.git
synced 2024-12-05 21:28:33 +08:00
4.5 KiB
4.5 KiB
title | order |
---|---|
Find Element | 5 |
graph.getNodes()
Get all the node items in the graph.
⚠️Attention: it returns the items but not data models.
Return
- Type of the return value: Array;
- Return the node items in the graph.
Usage
const nodes = graph.getNodes();
graph.getEdges()
Get all the edge items in the graph.
⚠️Attention: it returns the items but not data models.
Return
- Type of the return value: Array;
- Return the edge items in the graph.
Usage
const edges = graph.getEdges();
graph.getCombos()
Get all the combo items in the graph.
Return
- Type of the return value: Array;
- Return the combo items in the graph.
Usage
const combos = graph.getCombos();
graph.getComboChildren(combo)
Get the children of the combo
.
Parameters
Name | Type | Required | Description |
---|---|---|---|
combo | string / ICombo | true | The ID or of the combo or the combo item |
Return
- Type of the return value: Object. Formated as:
{
nodes: INode[],
edges: ICombo[]
}
- Return the children (sub nodes and combos) of the
combo
.
Usage
const elements: {
nodes: INode[],
combos: ICombo[]
} = graph.getComboChildren('combo1')
graph.getNeighbors(node, type)
Parameters
Name | Type | Required | Description |
---|---|---|---|
node | string / INode | true | node ID or the node instance |
type | 'source' / 'target' / undefined | false | The type of the neighbors, 'source': only return the source nodes; 'target': only return the target nodes, undefined: return all of the neighbors |
Return
- Type of the return value: Array;
- Return a list of node items.
Usage
const neighbors = graph.getNeighbors('node1', 'source');
graph.find(type, fn)
Find single item according to a rule.
Parameters
Name | Type | Required | Description |
---|---|---|---|
type | string | true | Type of the item. Options: 'node' , 'edge' . |
fn | Function | true | Rule for searching. |
Return
- Type of the return value: Object;
- If there are items that match the rule, return the first one. Return
undefined
otherwise.
Usage
const findNode = graph.find('node', (node) => {
return node.get('model').x === 100;
});
graph.findById(id)
Find an item by id.
Parameters
Name | Type | Required | Description |
---|---|---|---|
id | string | true | 元素 ID |
Return
- Type of the return value: Object;
- If there are items that match the rule, return the first one. Return
undefined
otherwise.
Usage
const node = graph.findById('node');
graph.findAll(type, fn)
Find all the items that match the rule.
Parameters
Name | Type | Required | Description |
---|---|---|---|
type | string | true | The type of the item. Options: 'node' , 'edge' . |
fn | Function | true | Rule for searching. |
Return
- Type of the return value: Array;
- If there are items that match the rule, return all of them. Return
undefined
otherwise.
Usage
const nodes = graph.findAll('node', (node) => {
return node.get('model').x;
});
graph.findAllByState(type, state)
Find all the items whose value of state is true.
Parameters
Name | Type | Required | Description |
---|---|---|---|
type | string | true | The type of the item. Options: 'node' , 'edge' . |
state | string | true | State for searching. |
Return
- Type of the return value: Array;
- Return all the items that match the state.
Usage
// Find all the items whose 'selected' state is true
const nodes = graph.findAllByState('node', 'selected');