Skip to content

Commit 4283513

Browse files
committed
fix some bugs + change view
1 parent 1c8f2d5 commit 4283513

4 files changed

Lines changed: 40 additions & 9 deletions

File tree

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ Pass '-o' flag if you want only print dependencies in console and don't want gra
2222

2323
cg /path/to/your_python_code -o
2424

25+
If you want to change view and play with graph output - you can check 'vizualyzer.py'
26+
and play with matplotlib and networkX settings.
2527

28+
In default view - red line show dependencies between entities in different modules. Green - entities in module.
29+
30+
![Code Graph - Code there all modules linked together](/docs/img/graph_visualisation.png?raw=true "Graph visualisation")
2631

2732
![Code Graph - Code with not used module](/docs/img/code_with_trash_module.png?raw=true "Code with not used module")
2833
![Code Graph - Code there all modules linked together](/docs/img/normal_code.png?raw=true "Code with modules that linked together")
527 KB
Loading

codegraph/vizualyzer.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,42 @@
55

66

77
def draw_graph(modules_entities: Dict) -> None:
8-
gr = nx.Graph()
9-
module_edges = []
10-
sub_edges = []
8+
G = nx.DiGraph()
9+
module_edges_all = []
10+
sub_edges_all = []
1111
for module in modules_entities:
12+
_module = os.path.basename(module)
13+
module_edges = []
1214
for entity in modules_entities[module]:
13-
module_edges.append((os.path.basename(module), entity))
15+
sub_edges = []
16+
module_edges.append((_module, entity))
1417
for dep in modules_entities[module][entity]:
1518
if '.' in dep:
1619
dep = dep.split('.')[1].replace('.', '.py')
1720
sub_edges.append((entity, dep))
18-
gr.add_edges_from(module_edges)
19-
gr.add_edges_from(sub_edges)
20-
pos = nx.spring_layout(gr)
21-
nx.draw(gr, pos, font_size=12, with_labels=False)
21+
G.add_edges_from(sub_edges)
22+
sub_edges_all += sub_edges
23+
if not modules_entities[module]:
24+
G.add_node(_module)
25+
G.add_edges_from(module_edges)
26+
module_edges_all += module_edges
27+
pos = nx.spring_layout(G)
28+
module_list = [os.path.basename(module) for module in modules_entities]
29+
module_list_labels = {module_name: module_name for module_name in module_list}
30+
31+
entities_labels = {edge[1]: edge[1] for edge in module_edges_all}
32+
nx.draw_networkx_nodes(G, pos, nodelist=module_list,
33+
node_color='#009c2c', node_size=800, node_shape="s", alpha=0.8)
34+
nx.draw(G, pos, node_color='#009c2c', arrows=False, edge_color='#ffffff', node_shape="o", alpha=0.8)
35+
36+
nx.draw_networkx_labels(G, pos, labels=module_list_labels, font_weight='bold', font_size=11)
37+
nx.draw_networkx_labels(G, pos, labels=entities_labels, font_weight='bold', font_family='Arial', font_size=10)
38+
nx.draw_networkx_edges(G, pos, edgelist=module_edges_all,
39+
edge_color='#009c2c', width=2,
40+
arrows=False, style="dashed", node_size=50)
41+
nx.draw_networkx_edges(G, pos, edgelist=sub_edges_all,
42+
edge_color='r', width=2,
43+
arrows=False, style="dashed")
2244
for p in pos: # raise text positions
2345
pos[p][1] += 0.07
24-
nx.draw_networkx_labels(gr, pos)
2546
plt.show()

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ pytest = "^3.0"
2020
[tool.poetry.scripts]
2121
cg = 'codegraph.main:cli'
2222

23+
[tool.poetry-dynamic-versioning]
24+
enable = true
25+
vcs = "git"
26+
style = "pep440"
27+
2328
[build-system]
2429
requires = ["poetry>=0.12"]
2530
build-backend = "poetry.masonry.api"

0 commit comments

Comments
 (0)