-
Notifications
You must be signed in to change notification settings - Fork 1
/
view_graph.py
69 lines (51 loc) · 1.71 KB
/
view_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python
#
# Simple script to show igraph-supported graph files
#
# Author: Javier Canovas ([email protected])
#
import getopt
import sys
from igraph import Graph, plot
"""
Usage of this script
Main options:
-i - The path of the igraph file (gml, graphml, etc...)
"""
USAGE = 'graph_viewer.py -i GRAPH_PATH'
def show_graph(input_graph_path):
"""
Shows a graph using the PyCairo library. Some default viewing options are currently applied
TODO: Support the configuration of viewing options
:param input_graph_path: The path to the graph to show
"""
g = Graph.Load(input_graph_path)
node_colors = {"COMMIT": "black", "COMMENT": "pink", "ISSUE": "orange", "USERLIKE": "red", "PULL": "blue",
"REPO": "pink"}
commit_nodes = [node.index for node in g.vs if node['type'] == 'COMMIT']
g.delete_vertices(commit_nodes)
graph_style = {"vertex_size": 20,
"vertex_color": [node_colors[node_type] for node_type in g.vs["type"]],
"vertex_label": g.vs["label"],
"edge_width": [1 * edge_flow for edge_flow in g.es['forwardFlow']],
"layout": g.layout("fr"),
"bbox": (1000, 1000),
"margin": 100}
plot(g, **graph_style)
def main(argv):
if len(argv) == 0:
sys.exit(0)
try:
opts, args = getopt.getopt(argv, "hi:", [])
except getopt.GetoptError:
print(USAGE)
sys.exit(2)
for opt, arg in opts:
if opt in ('-h', '--help'):
print(USAGE)
sys.exit()
elif opt in '-i':
input_graph_path = arg
show_graph(input_graph_path)
if __name__ == "__main__":
main(sys.argv[1:])