diff --git a/docs/api/Graph.en.md b/docs/api/Graph.en.md index 0a5996fe191..a0cb3c95141 100644 --- a/docs/api/Graph.en.md +++ b/docs/api/Graph.en.md @@ -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 @@ -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. | @@ -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. | diff --git a/docs/api/Graph.zh.md b/docs/api/Graph.zh.md index e81f4035151..a85428fd519 100644 --- a/docs/api/Graph.zh.md +++ b/docs/api/Graph.zh.md @@ -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 坐标的示意图如下所示。 @@ -1677,7 +1697,7 @@ graph.stopAnimate(); graph.getNodeDegree('node1', 'in'); ``` -### getShortestPathMatrix +### getShortestPathMatrix(cache, directed) 获取图中两两节点之间的最短路径矩阵。 **参数** @@ -1696,7 +1716,7 @@ graph.getNodeDegree('node1', 'in'); const matrix = graph.getShortestPathMatrix(); ``` -### getAdjMatrix +### getAdjMatrix(cache, directed) 获取邻接矩阵。 **参数** diff --git a/docs/api/nodeEdge/Node.en.md b/docs/api/nodeEdge/Node.en.md index 6ffd51fce97..9ca40f551c2 100644 --- a/docs/api/nodeEdge/Node.en.md +++ b/docs/api/nodeEdge/Node.en.md @@ -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. diff --git a/docs/api/nodeEdge/Node.zh.md b/docs/api/nodeEdge/Node.zh.md index fe848df6099..c3283ffa1f0 100644 --- a/docs/api/nodeEdge/Node.zh.md +++ b/docs/api/nodeEdge/Node.zh.md @@ -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() 获取与当前节点有关联的所有边。