Skip to content

Commit

Permalink
docs: add docs for getNeighbors
Browse files Browse the repository at this point in the history
  • Loading branch information
chenluli authored and Yanyan-Wang committed Jul 28, 2020
1 parent 4f654f7 commit 9629ec9
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 6 deletions.
25 changes: 21 additions & 4 deletions docs/api/Graph.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,23 @@ const elements: {
} = graph.getComboChildren('combo1')
```

### 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**
``` javascript
const neighbors = graph.getNeighbors('node1', 'source')
```

## Coordinate Transformation

Expand Down Expand Up @@ -1689,12 +1706,12 @@ Get the in-degree, out-degree, degree, or all of the three kinds of degree.
graph.getNodeDegree('node1', 'in');
```

### getShortestPathMatrix
### getShortestPathMatrix(cache, directed)
Get all-pairs shortest-path matrix of the graph.

**Parameters**

| 名称 | 类型 | 是否必选 | 描述 |
| Name | Type | Required | Description |
| -------| ------ | -------- | ------- |
| cache | boolean | false | Whether to use the cached matrix, 'true' by default. |
| directed | boolean | false | Whether the graph is directed, use the value of `graph.get('directed')` by default. |
Expand All @@ -1704,12 +1721,12 @@ Get all-pairs shortest-path matrix of the graph.
const matrix = graph.getShortestPathMatrix();
```

### getAdjMatrix
### getAdjMatrix(cache, directed)
Get the adjacency matrix of the graph.

**Parameters**

| 名称 | 类型 | 是否必选 | 描述 |
| Name | Type | Required | Description |
| -------| ------ | -------- | ------- |
| cache | boolean | false | Whether to use the cached matrix, 'true' by default. |
| directed | boolean | false | Whether the graph is directed, use the value of `graph.get('directed')` by default. |
Expand Down
24 changes: 22 additions & 2 deletions docs/api/Graph.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,26 @@ const elements: {
} = graph.getComboChildren('combo1')
```

### getNeighbors(node, type)

**参数**

| 名称 | 类型 | 是否必选 | 描述 |
| ------- | ------ | -------- | ----------- |
| node | string / INode | true | 节点 ID 或节点实例 |
| type | 'source' / 'target' / undefined | false | 邻居类型, 'source' 只获取当前节点的源节点,'target' 只获取当前节点指向的目标节点, 若不指定则返回所有类型的邻居 |

**返回值**

- 返回值类型:Array;
- 返回值符合要求的节点数组。

**用法**

``` javascript
const neighbors = graph.getNeighbors('node1', 'source')
```

## 坐标转换

这部分主要是说明视口坐标、Canvas 坐标和页面坐标之前的相互转换。其中视口坐标和 Canvas 坐标的示意图如下所示。
Expand Down Expand Up @@ -1677,7 +1697,7 @@ graph.stopAnimate();
graph.getNodeDegree('node1', 'in');
```

### getShortestPathMatrix
### getShortestPathMatrix(cache, directed)
获取图中两两节点之间的最短路径矩阵。

**参数**
Expand All @@ -1696,7 +1716,7 @@ graph.getNodeDegree('node1', 'in');
const matrix = graph.getShortestPathMatrix();
```

### getAdjMatrix
### getAdjMatrix(cache, directed)
获取邻接矩阵。

**参数**
Expand Down
17 changes: 17 additions & 0 deletions docs/api/nodeEdge/Node.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ const node = graph.findById('node');
const hasLocked = node.hasLocked();
```

### getNeighbors(type)

**Parameters**

| Name | Type | Required | Description |
| ------- | ------ | -------- | ----------- |
| 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**
``` javascript
const neighbors = node.getNeighbors('source')
```

## getEdges()

Get the related edges (the node is the source or the target of the edge) of the node.
Expand Down
19 changes: 19 additions & 0 deletions docs/api/nodeEdge/Node.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ const node = graph.findById('node');
const hasLocked = node.hasLocked();
```

## getNeighbors(type)

**参数**

| 名称 | 类型 | 是否必选 | 描述 |
| ------- | ------ | -------- | ----------- |
| type | 'source' / 'target' / undefined | false | 邻居类型, 'source' 只获取当前节点的源节点,'target' 只获取当前节点指向的目标节点, 若不指定则返回所有类型的邻居 |

**返回值**

- 返回值类型:Array;
- 返回值符合要求的节点实例数组。

**用法**

``` javascript
const neighbors = node.getNeighbors('source')
```

## getEdges()

获取与当前节点有关联的所有边。
Expand Down

0 comments on commit 9629ec9

Please sign in to comment.