Skip to content

Added :class:.DiGraph, a mobject representing directed graphs #2974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Apr 6, 2023

Conversation

fcrozatier
Copy link
Contributor

@fcrozatier fcrozatier commented Oct 2, 2022

Overview: What does this pull request change?

Graph Mobject can be directed and we can configure the tip globally or per edge
Closes #2935
Closes #2843
Supersedes #2850 in a non breaking way

Motivation and Explanation: Why and how do your changes improve the library?

At the moment directed graph are not supported

Links to added or changed documentation pages

https://manimce--2974.org.readthedocs.build/en/2974/reference/manim.mobject.graph.GenericGraph.html#manim.mobject.graph.GenericGraph
https://manimce--2974.org.readthedocs.build/en/2974/reference/manim.mobject.graph.Graph.html
https://manimce--2974.org.readthedocs.build/en/2974/reference/manim.mobject.graph.DiGraph.html

Further Information and Comments

Reviewer Checklist

  • [x ] The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • [x ] If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • [x ] If applicable: newly added functions and classes are tested

@behackl behackl self-requested a review November 15, 2022 16:14
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First things first: thanks for your efforts, and sorry for the long wait! One problem I currently see with this approach is that it intertwines what is needed to construct a graph and what is needed to construct a digraph a fair amount -- something that would perhaps be better if it were separated a bit more cleanly.

What do you think about this:

  • The current implementation of Graph is moved to GenericGraph (which is not exposed to users), and new classes Graph and DiGraph are implemented.
  • GenericGraph.__init__ could be slightly refactored to move code specific to one implementation in a separate method, the corresponding code is moved to the respective special class, and implemented as a raise NotImplementedError in the generic class.
  • Otherwise there won't be a lot of code required for Graph and DiGraph; the main thing would still be that the default argument to the proposed constructor / graph_type is fixed to the undirected and directed version, respectively.

Regardless of this suggestion for refactoring: the documentation build currently fails, something is wrong with the proposed example -- and the tests are failing due to the change with passing vertex centers vs. the vertex objects to the edge mobjectsm, and/or the change in the updater function. This has to be fixed before the PR can be merged.

@fcrozatier fcrozatier requested a review from behackl November 20, 2022 11:04
@MrDiver MrDiver added the pr:bugfix Bug fix for use in PRs solving a specific issue:bug label Mar 31, 2023
@behackl
Copy link
Member

behackl commented Apr 1, 2023

Somehow this PR has passed under my radar several releases in a row, sorry. I've just skimmed over the current implementation, it looks good to me!

I'd like to do some more tests tomorrow, and there are some details I'd like to change about the docstring of Graph -- but I'll take care of that. If there are no major issues, this will be included in the upcoming release. 👍

@behackl behackl added new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) and removed pr:bugfix Bug fix for use in PRs solving a specific issue:bug labels Apr 3, 2023
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much again for your contribution! I sat down and improved a bunch of things:

  • Graph, Digraph, GenericGraph now all have docstrings with documented parameters,
  • Examples have been moved from the (practically abstract) GenericGraph base class to Graph,
  • I've removed the proposed graph_type keyword argument and instead introduced a bunch of graph class specific methods (nothing too exciting; one method for populating the .edges attribute, and another one for determining the empty networkx graph class)
  • While doing so, I've also simplified the logic for the tip_shape settings; everything should still work as expected,
  • and one last, technically breaking change: I've cleaned up the weird design decision regarding edges in undirected graphs; now the tuple representing the edge in edge_config etc. has to be in the same order as it is specified in the edges list -- further unifying the code between directed and undirected graphs.

Tests should pass (and otherwise I'll fix remaining issues); I'll leave this open for a few more hours in case anyone declares interest in taking a closer look at this -- and otherwise this PR will finally get merged. :-)

@behackl behackl changed the title Directed graphs Added :class:.DiGraph, a mobject representing directed graphs Apr 5, 2023
@behackl behackl merged commit c98f3c7 into ManimCommunity:main Apr 6, 2023
@fcrozatier
Copy link
Contributor Author

Great! Thank you for accepting this PR. Any ideas when the new Manim version will be released? 😊

@behackl
Copy link
Member

behackl commented Apr 6, 2023

Great! Thank you for accepting this PR. Any ideas when the new Manim version will be released? blush

In a few hours, see #3198 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Enhancement specifically adding a new feature (feature request should be used for issues instead)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Directed Graphs in Manim self.play(Create(G)) connects edges to the centre of vertices unlike self.add(G) for Graphs
3 participants