plt.determine(figsize=(13, 9))
pos = nx.spring_layout(UG, ok=0.7, seed=42)
nx.draw_networkx_edges(UG, pos, alpha=0.25)
nx.draw_networkx_nodes(
UG, pos,
node_color=(node_comm.get(n, 0) for n in UG.nodes),
node_size=(300 + 4000 * deg.get(n, 0) for n in UG.nodes),
cmap=plt.cm.tab20, alpha=0.9,
)
high = {n for n, _ in sorted(deg.objects(), key=lambda x: -x(1))(:14)}
nx.draw_networkx_labels(UG, pos, {n: label(n) for n in high}, font_size=8)
plt.title("Graphify information graph — dimension=centrality, shade=neighborhood")
plt.axis("off"); plt.tight_layout()
plt.savefig("graph_static.png", dpi=130); plt.present()
attempt:
from pyvis.community import Community
web = Community(top="650px", width="100%", bgcolor="#111", font_color="white",
pocket book=True, cdn_resources="in_line", directed=G.is_directed())
palette = ("#e6194B","#3cb44b","#4363d8","#f58231","#911eb4",
"#42d4f4","#f032e6","#bfef45","#fabed4","#469990")
for n, d in G.nodes(knowledge=True):
c = node_comm.get(n, 0)
web.add_node(n, label=label(n), title=f"{d.get('file_type','?')} · {d.get('source_file','')}",
shade=palette(c % len(palette)), dimension=12 + 60 * deg.get(n, 0))
for s, t, d in G.edges(knowledge=True):
web.add_edge(s, t, title=d.get("relation", ""))
web.save_graph("graph_interactive.html")
print("nSaved interactive graph -> graph_interactive.html")
from IPython.show import HTML, show
show(HTML(open("graph_interactive.html").learn()))
besides Exception as e:
print("Interactive viz skipped:", e)
for cmd in (
("question", "what connects auth to the database?", "--graph", GRAPH_JSON),
("path", "AuthService", "DatabasePool", "--graph", GRAPH_JSON),
("clarify", "RateLimiter", "--graph", GRAPH_JSON),
):
print("n$ graphify " + " ".be part of(cmd))
r = subprocess.run((sys.executable, "-m", "graphify", *cmd),
capture_output=True, textual content=True)
print((r.stdout or r.stderr)(:1200))
print("nDone. Artifacts: graph_static.png, graph_interactive.html,",
"and graphify-out/ (graph.json, GRAPH_REPORT.md).")
