From 830e9b4ccfebd496d6df6fa511e4c39060a2e63b Mon Sep 17 00:00:00 2001 From: aadi-novice Date: Sun, 24 May 2026 14:38:59 +0530 Subject: [PATCH] Fix: remap hyperedges in community-aggregated meta-graph view When a graph exceeds the viz node limit, to_html() builds a community-aggregated meta-graph and recursively calls itself. The recursive call never carried hyperedges onto the meta-graph, so graph.html always emitted const hyperedges = [] even when graph.json contained plenty. This fix remaps hyperedge node references from semantic node IDs to community IDs before the recursive call, so hyperedge regions render correctly in the aggregated view. Hyperedges that collapse to fewer than 2 distinct communities are dropped (they wouldn't render as a polygon anyway). Fixes #1005 --- graphify/export.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/graphify/export.py b/graphify/export.py index 4c9a44778..51daee13f 100644 --- a/graphify/export.py +++ b/graphify/export.py @@ -656,6 +656,30 @@ def to_html( return meta_communities = {cid: [str(cid)] for cid in communities} mc = {cid: len(members) for cid, members in communities.items()} + # Remap hyperedges from semantic node IDs to community IDs + raw_hyperedges = G.graph.get("hyperedges", []) + if raw_hyperedges: + remapped = [] + for he in raw_hyperedges: + he_members = he.get("nodes") or he.get("members") or [] + comm_ids, seen = [], set() + for nid in he_members: + c = node_to_community.get(nid) + if c is None: + continue + s = str(c) + if s in seen: + continue + seen.add(s) + comm_ids.append(s) + if len(comm_ids) < 2: + continue + remapped.append({ + "id": he.get("id", ""), + "label": he.get("label") or he.get("relation", "").replace("_", " "), + "nodes": comm_ids, + }) + meta.graph["hyperedges"] = remapped to_html(meta, meta_communities, output_path, community_labels=community_labels, member_counts=mc) print(f"graph.html written (aggregated: {meta.number_of_nodes()} community nodes, {meta.number_of_edges()} cross-community edges)")