-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Basic implementation of undirected graphs #861
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
Conversation
I should also mention (sorry for forgetting about it, initially): this is based on prior work by @XorUnison, I basically expanded and refined the interface that #210 implemented. |
The examples https://manimce--861.org.readthedocs.build/en/861/reference/manim.mobject.graph.Graph.html#movingvertices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest you type your code, either using python typing, or atleast in the doc strings. That would save a lot of time for users, and typing it later would be super hard, rather than the person who created it typing it.
Sure, I was planning to add type hints anyways -- just not for the initial, possibly still very unstable first version. I'd like to get some general feedback on the interface first. |
Yeah. Back when I made the according PR I settled for calling it The examples look decent, but there's this strange jerking motion after |
As graph theory is a very niche topic and most people won't deal with it when using manim, I am also in favour of calling it |
While sure, graph theory might not be something that is usually taught in schools, I strongly disagree with graph theory being a niche topic. Regarding names: I'd like to keep the name as
I don't see the big potential for confusion, but I'm open for discussing potential user scenarios. |
See the additional comments in the PR description above; in an ideal world we would be able to make the vertices render first, and have the edges be added behind them. I could not find a way to do so yet; I think |
Right, but that's not what I was talking about. I did figure it out in the meantime however. See... there's a bit of a strange issue happening with your updater. While in principle a great idea, something strange, and frankly very unexpected happens when the updater grabs the centers of the vertices here: So now the quesion is what we're gonna do about it? Fixing this is technically speaking a breaking change, but any sort of introduction animation shouldn't affect the supposed center of the object. |
No, we are talking about the same issue: I know that Changing the order of appearance (vertices first, edges after) does not only create a better looking animation, it also fixes the jerking motion because the edges are only drawn after the center of the vertices has stabilized, so to say. But we can only do that properly if there is a way to set the position (i.e., vertices in the foreground, edges in the background) separate from the order of drawing. Otherwise, labeled (or otherwise colored) graphs will have visible edges reaching into the vertices. For Dots, this could also be fixed by setting the Another option would be to get the point on the boundary of the vertex that the line between two vertices passes through -- I haven't investigated that yet, though. |
I've managed to get it working: But the only way I could find now uses
However, |
Thanks for giving these arguments, then I am fine with calling ith "Graph". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
🎉 Great news! Looks like all the dependencies have been resolved: 💡 To add or remove a dependency please update this issue/PR description. Brought to you by Dependent Issues (:robot: ). Happy coding! |
I've added type hints via 45e52ba. I am working on extending this basic interface (as a first step, methods for modifying the graph like |
I just tested it, and it works nicely on my machine! |
Doing something like Graph(vertices, edges, edge_config={'stroke_width': 5}) or so does what you want. In case of a situation that is like the example above, where some edges get a custom styling, the parameter has to be added to each of the custom style dictionaries as well. Feedback on the interface is very welcome! I'd like to get this basic version in for the release, and then we can iterate on the interface and further custom methods, so that the graph class becomes more useful. :-) |
Tests pass and documentation renders correctly, let's ship it! :-) |
Motivation
I feel it is a missed opportunity that Manim currently does not offer (easy) access to Graphs, and I don't want to hack together Dot-and-Line-constructs any more.
Overview / Explanation for Changes
This PR introduces a new module,
manim.mobject.graph
containing (for now) one class,Graph
, which serves as an interface for rendering graphs. For now, there (sadly) are no useful utility functions for graph manipulation -- however, I've tried to keep everything as customizable as possible. In particular, I find it useful to have the edges actually attached to the vertices (in the sense that moving a vertex should also move the corresponding edge); this is done here by adding appropriate updaters.Furthermore, this PR adds
networkx
as a dependency: I feel strongly that if we are going to include Graphs in Manim, we should utilize existing code as much as possible. With this PR, this interface tonetworkx
might not be fully exploited yet -- but it is not unused; it currently gives us access to several algorithms for graph layouting (which I, personally, see as a strong requirement for a useableGraph
class. I don't even want to think about positioning vertices manually (but of course, it is possible with this PR)).See some simple examples for this graph in the documentation: https://manimce--861.org.readthedocs.build/en/861/reference/manim.mobject.graph.Graph.html#manim.mobject.graph.Graph
Oneline Summary of Changes
Testing Status
Docs and corresponding examples build locally and almost* look as intended.
Further Comments
Depends on #872 (for fixing the
ShowCreation
animation: first vertices are drawn, then edges -- but the edges are still behind the vertices).Acknowledgements
Reviewer Checklist