Skip to content

Commit

Permalink
Implemented and added an example of size-aware layout for Euler diagr…
Browse files Browse the repository at this point in the history
…ams.
  • Loading branch information
dlarendt committed Feb 24, 2025
1 parent 391a95b commit 2b78b47
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 75 deletions.
38 changes: 38 additions & 0 deletions hypernetx/drawing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,41 @@ def get_set_layering(H, collapse=True):
levels[v] = max(parent_levels) + 1 if len(parent_levels) else 0

return levels

def layout_with_radius(B, node_and_edge_radius=1, **kwargs):
"""
Convenience function allowing the user to specify ideal radii for nodes and edges in the drawing
The Kamada-Kawai (networkx.kamada_kawai_layout) algorithm is used. The algorithm is passed
a all pairs shorteset path matrix that is calculated from the bipartite graph input. The
shortest path is determined
Parameters
----------
B: nx.Graph
a bipartite graph representing the hypergraph
node_and_edge_radius: float, int, dict, list, or function
encoding of the radii of nodes in B, which are hyper-edges or hyper-nodes (0 by default)
kwargs: dict
Keyword arguments are passed through to the networkx.kamada_kawai_layout function
Returns
-------
dict
mapping of node and edge positions to R^2
"""

# get radii encodings and convert to dictionary
radius_dict = dict(zip(B, inflate(B, node_and_edge_radius)))

# edges weights are the sum of the radii of the edge endpoints
for u, v, d in B.edges(data=True):
d['weight'] = radius_dict.get(u, 0) + radius_dict.get(v, 0)

# compute all pairs shortest path (APSP)
dist = dict(nx.all_pairs_dijkstra_path_length(B))

# compute and return layout using above APSP; pass through arguments
return nx.kamada_kawai_layout(B, dist=dist, **kwargs)

203 changes: 128 additions & 75 deletions tutorials/visualization/Advanced Visualization for Euler.ipynb

Large diffs are not rendered by default.

0 comments on commit 2b78b47

Please sign in to comment.