-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request #231: Release/2.4 visualization
Merge in HYP/hypernetx from release/2.4_visualization to master * commit '7e915833cb189db49f86ef4654ce19f2331f0216': (78 commits) bump: version 2.3.13 → 2.4.0 fix pre-commit add widget Implemented and added an example of size-aware layout for Euler diagrams. Replaced hnx.drawing.draw with hnx.draw updated tutorials to match on new HNX methods updated Basic Tutorials to new version of HNX precommit updated linting removing h2vec images and json files from develop until approved by sponsor removed docs for hedge2vec from develop until approved by sponsor post linting changes removed hedge2vec until approved by sponsor changed image sizes added images to .rst updated hedge2vec rst with images added doc file, moved json file for tutorial added hedge2vec files Added description of fill_edge_alpha to comment block. Reran to update figures. ...
- Loading branch information
Showing
28 changed files
with
84,455 additions
and
122,046 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
from hypernetx.utils import * | ||
from hypernetx.utils.toys import * | ||
|
||
__version__ = "2.3.13" | ||
__version__ = "2.4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from hypernetx.drawing.rubber_band import draw | ||
from hypernetx.drawing.two_column import draw as draw_two_column | ||
from .rubber_band import draw | ||
from .draw_incidence import draw_incidence_upset | ||
from .draw_bipartite import draw_bipartite_using_euler | ||
|
||
__all__ = ["draw", "draw_two_column"] | ||
__all__ = ["draw", "draw_incidence_upset", "draw_bipartite_using_euler"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import numpy as np | ||
import networkx as nx | ||
|
||
import hypernetx as hnx | ||
|
||
|
||
def rebalance(B, pos, side): | ||
new_pos = {} | ||
|
||
y = -1 | ||
for u in side: | ||
x = pos[u][0] | ||
y = max(y + 1, min([pos[v][1] for v in B[u]])) | ||
new_pos[u] = (x, y) | ||
|
||
return {**pos, **new_pos} | ||
|
||
|
||
def sort_left_by_right(B, left, right): | ||
pos = {v: i for i, v in enumerate(right)} | ||
print(left, right) | ||
|
||
return sorted(left, key=lambda u: np.mean([pos[v] for v in B[u]])) | ||
|
||
|
||
def bipartite_layout(B, left_side, right_side, width=1): | ||
|
||
pos = {} | ||
|
||
for i, v in enumerate(left_side): | ||
pos[v] = (0, i) | ||
|
||
for i, v in enumerate(right_side): | ||
pos[v] = (width, i) | ||
|
||
if len(left_side) < len(right_side): | ||
pos = rebalance(B, pos, left_side) | ||
pos = rebalance(B, pos, right_side) | ||
elif len(left_side) > len(right_side): | ||
pos = rebalance(B, pos, right_side) | ||
pos = rebalance(B, pos, left_side) | ||
|
||
return pos | ||
|
||
|
||
def draw_bipartite_using_euler( | ||
H, pos=None, node_order=None, edge_order=None, edge_labels_kwargs={}, **kwargs | ||
): | ||
""" | ||
Draw a hypergraph as a two column bipartite graph using hypernetx.draw. | ||
This function calculates the x- and y-coordinates of nodes and edges by placing | ||
edges in the left column and nodes in the right column. The ordering of edges | ||
and nodes is determined by default using the networkx.spectral_order method | ||
on the bipartite representation of the hypergraph. Node and edge order can | ||
also be specified by the user. If one or the other is specified, then the | ||
unspecified column (nodes or edges) are sorted using the barycenter method. | ||
Additional minor adjustment of node and edge height is performed to improve | ||
readability. | ||
Additional encoding kwargs are passed through to the hypernetx.draw method. | ||
Parameters | ||
---------- | ||
H: hnx.Hypergraph | ||
the entity to be drawn | ||
pos: dict | ||
the positioning of the hypergraph | ||
node_order: list | ||
specify to override the order of the nodes in the drawing | ||
edge_order: list | ||
specify to override the order of the edges in the drawing | ||
""" | ||
|
||
B = H.bipartite().to_undirected() | ||
if pos is None: | ||
if node_order is None and edge_order is not None: | ||
node_order = sort_left_by_right(B, H.nodes, edge_order) | ||
elif node_order is not None and edge_order is None: | ||
edge_order = sort_left_by_right(B, H.edges, node_order) | ||
elif node_order is None and edge_order is None: | ||
order = nx.spectral_ordering(B, seed=1234567890) | ||
node_order = list(filter(H.nodes.__contains__, order)) | ||
edge_order = list(filter(H.edges.__contains__, order)) | ||
|
||
pos = bipartite_layout( | ||
B, edge_order, node_order, width=0.5 * max(len(H.nodes), len(H.edges)) | ||
) | ||
|
||
return hnx.drawing.draw( | ||
H, | ||
pos=pos, | ||
with_additional_edges=B, | ||
contain_hyper_edges=True, | ||
edge_labels_on_edge=False, | ||
edge_labels_kwargs={ | ||
"xytext": (-10, 0), | ||
"textcoords": "offset points", | ||
**edge_labels_kwargs, | ||
}, | ||
**kwargs | ||
) |
Oops, something went wrong.