Returns the graph as a dictionary in a format that can be serialized.
(self)
| 108 | return graph |
| 109 | |
| 110 | def node_link_data(self): |
| 111 | ''' |
| 112 | Returns the graph as a dictionary in a format that can be |
| 113 | serialized. |
| 114 | ''' |
| 115 | data = { |
| 116 | 'directed': True, |
| 117 | 'multigraph': False, |
| 118 | 'graph': {}, |
| 119 | 'links': [], |
| 120 | 'nodes': [], |
| 121 | } |
| 122 | |
| 123 | # Do one pass to build a map of node -> position in nodes |
| 124 | node_to_number = {} |
| 125 | for node in self.adjacency_map.keys(): |
| 126 | node_to_number[node] = len(data['nodes']) |
| 127 | data['nodes'].append({'id': node}) |
| 128 | |
| 129 | # Do another pass to build the link information |
| 130 | for node, neighbors in self.adjacency_map.items(): |
| 131 | for neighbor in neighbors: |
| 132 | link = self.attributes_map[(node, neighbor)].copy() |
| 133 | link['source'] = node_to_number[node] |
| 134 | link['target'] = node_to_number[neighbor] |
| 135 | data['links'].append(link) |
| 136 | return data |
| 137 | |
| 138 | |
| 139 | def strongly_connected_components(G): |