Recursively lists the node and nodes linked to it. Depth 0 returns a list with the node. Depth 1 returns a list with the node and all the directly linked nodes. Depth 2 includes the linked nodes' links, and so on.
(self, depth=1, traversable=lambda node, edge: True, _visited=None)
| 145 | betweenness = betweenness_centrality = centrality |
| 146 | |
| 147 | def flatten(self, depth=1, traversable=lambda node, edge: True, _visited=None): |
| 148 | """ Recursively lists the node and nodes linked to it. |
| 149 | Depth 0 returns a list with the node. |
| 150 | Depth 1 returns a list with the node and all the directly linked nodes. |
| 151 | Depth 2 includes the linked nodes' links, and so on. |
| 152 | """ |
| 153 | _visited = _visited or {} |
| 154 | _visited[self.id] = (self, depth) |
| 155 | if depth >= 1: |
| 156 | for n in self.links: |
| 157 | if n.id not in _visited or _visited[n.id][1] < depth-1: |
| 158 | if traversable(self, self.links.edges[n.id]): |
| 159 | n.flatten(depth-1, traversable, _visited) |
| 160 | return [n for n,d in _visited.values()] # Fast, but not order-preserving. |
| 161 | |
| 162 | def draw(self, weighted=False): |
| 163 | """ Draws the node as a circle with the given radius, fill, stroke and strokewidth. |