xgi icon indicating copy to clipboard operation
xgi copied to clipboard

Add the ability to draw hypergraphs as a bipartite graph

Open nwlandry opened this issue 1 year ago • 14 comments

This PR does the following:

  • Removes draw_dihypergraph and moves its contents to draw_bipartite.
  • The draw_bipartite now handles Hypergraph and DiHypergraph objects.
  • Added the bipartite_spring_layout position function.

nwlandry avatar Nov 03 '23 16:11 nwlandry

Codecov Report

Attention: Patch coverage is 91.12426% with 15 lines in your changes are missing coverage. Please review.

Project coverage is 92.29%. Comparing base (0f9be8d) to head (730bd74).

Files Patch % Lines
xgi/drawing/draw.py 91.33% 13 Missing :warning:
xgi/drawing/layout.py 88.88% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #492      +/-   ##
==========================================
+ Coverage   92.16%   92.29%   +0.13%     
==========================================
  Files          60       60              
  Lines        4418     4493      +75     
==========================================
+ Hits         4072     4147      +75     
  Misses        346      346              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Nov 03 '23 17:11 codecov[bot]

Just a thought: conceptually, could this function just be the same as the draw_dihypergraph with the edge markers, except that the links are drawn without arrows and the layout would be different?

maximelucas avatar Nov 03 '23 17:11 maximelucas

Mmmmm. This is a great point. I think you're right. Would it make sense to group them together, call it draw_bipartite and have different handling for directed and undirected hypergraphs?

nwlandry avatar Nov 03 '23 17:11 nwlandry

I thought that could be a possibility. Worth thinking about. The current dihypergraph one only make sense as a bipartite if the edge markers are drawn though, I'd say.

Maybe directedness and "bipartite-ness" are two somewhat independent elements here. Could the arrow drawing be included as a directed option in draw_hyperedges? Not sure that would include the edge markers.

And then the draw_bipartite could just be about the layout really. Either the current layout we have in the dihypergraph one, or a more bipartitey layout, the user could choose. And draw directed or undirected edges.

maximelucas avatar Nov 03 '23 17:11 maximelucas

I thought that could be a possibility. Worth thinking about. The current dihypergraph one only make sense as a bipartite if the edge markers are drawn though, I'd say.

Maybe directedness and "bipartite-ness" are two somewhat independent elements here. Could the arrow drawing be included as a directed option in draw_hyperedges? Not sure that would include the edge markers.

And then the draw_bipartite could just be about the layout really. Either the current layout we have in the dihypergraph one, or a more bipartitey layout, the user could choose. And draw directed or undirected edges.

I have refactored the function so that it accepts both directed and undirected hypergraphs. Because of this, draw_dihypergraph is now unnecessary and so I removed it.

nwlandry avatar Feb 13 '24 17:02 nwlandry

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

I have now implemented all of your suggestions, @maximelucas. Should be ready to re-review.

nwlandry avatar Feb 27 '24 14:02 nwlandry

Thanks for the suggestions, @maximelucas! It looks like I need to take more time to address these concerns, and I'll let you know when I'm done!

nwlandry avatar Feb 29 '24 14:02 nwlandry

@maximelucas, I believe I addressed all of your comments! Thanks for such a thorough and helpful review! I did the following:

  • I standardized all of the function arguments in response to your review.
  • I made draw_undirected_dyads and draw_directed_dyads standalone functions and made them available to the user.
  • Added default values to the settings and made them match other functions.

nwlandry avatar Mar 08 '24 23:03 nwlandry

Thanks! Those are quick small comments for the last changes, I'll have a better look at the entire code soon.

maximelucas avatar Mar 11 '24 10:03 maximelucas

@maximelucas, are you still able to review this? Thanks so much!

nwlandry avatar Apr 02 '24 14:04 nwlandry

I'll do that next week!

maximelucas avatar Apr 05 '24 10:04 maximelucas

Great! Thanks so much!

nwlandry avatar Apr 09 '24 18:04 nwlandry

Some more minor comments.. we're almost there, it's a lot of code 😄 I'll check the rest of the code later today.

maximelucas avatar Apr 10 '24 14:04 maximelucas

@maximelucas thanks so much! Let me know when you're done and I'll start addressing your comments!

nwlandry avatar Apr 15 '24 11:04 nwlandry

I think I checked all of it 😛 I would just add an example somewhere of an undirected one, and raise an issue to create a new function with the "classic" graph bipartite layout, and maybe also with the barycenter layout. Thanks for all the work!

maximelucas avatar Apr 16 '24 20:04 maximelucas

@maximelucas, thanks for the review! A quick overview of my changes based on your comments:

  • changed all of the dyads to be colored by the edge size (with "crest_r") by default
  • Added error handling in a few places
  • Added a new function edge_positions_from_barycenters as a more general replacement of the old functionality.
  • Added an example of using draw_bipartite on an undirected hypergraph in Tutorial 5
  • Added a few examples of the new edge_positions_from_barycenters in Tutorial 5 and In Depth 3.

At this point, I believe that I've addressed all your comments. Let me know if there are other things you would like me to change.

nwlandry avatar Apr 18 '24 22:04 nwlandry

Looks good, thanks so much for the work!

maximelucas avatar Apr 22 '24 13:04 maximelucas