diff --git a/cutt/analysis.py b/cutt/analysis.py index 4d4876d..30da656 100644 --- a/cutt/analysis.py +++ b/cutt/analysis.py @@ -58,6 +58,7 @@ def graph_json( request: Annotated[ TeamScopedRequest, Security(verify_team_scope, scopes=["analysis"]) ], + networkx_graph: bool = False, ): nodes = [] edges = [] @@ -124,11 +125,22 @@ def graph_json( ) G = nx.DiGraph() G.add_nodes_from([n["id"] for n in nodes]) - G.add_weighted_edges_from([(e["source"], e["target"], e["size"]) for e in edges]) + G.add_weighted_edges_from( + [ + ( + e["source"], + e["target"], + e["size"] if e["data"]["relation"] == 2 else -e["size"], + ) + for e in edges + ] + ) in_degrees = G.in_degree(weight="weight") nodes = [ dict(node, **{"data": {"inDegree": in_degrees[node["id"]]}}) for node in nodes ] + if networkx_graph: + return G return JSONResponse({"nodes": nodes, "edges": edges})