From c09fbef401f22901722cd7148217236c8bf93884 Mon Sep 17 00:00:00 2001 From: Aadi <145907948+aadi-novice@users.noreply.github.com> Date: Thu, 28 May 2026 03:09:01 +0530 Subject: [PATCH] fix: remap hyperedges in community-aggregated meta-graph view (#1006) 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 dd64b6c80..f685e4c9c 100644 --- a/graphify/export.py +++ b/graphify/export.py @@ -663,6 +663,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)")