-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add weighted edges and self loop edges to graphs #3945
Open
ZynoXelek
wants to merge
40
commits into
ManimCommunity:main
Choose a base branch
from
ZynoXelek:Weighted-Edges-Graphs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
…instead of given value.
…l_units/test_threed.py::test_MovingVertices`
…iGraph and Graph classes
…to Weighted-Edges-Graphs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview: What does this pull request change?
This pull request addresses issue #3153. It makes it possible to create self-loop edges that are correctly rendered using curved lines (by default) as edges. It also adds the possibility to set weights (or any other label) to the edges.
Motivation and Explanation: Why and how do your changes improve the library?
As it is explained in the linked issue, these changes make graphs ready for representation of state-machines.
Links to added or changed documentation pages
Further Information and Comments
How it looks like:
For a regular
Graph
:For a
DiGraph
:Comments:
The three added private methods (in the
GenericGraph
class) may be moved to another location. Though the objective here was to make it as general as possible without creating new classes that would support these new features. This way, it can be used in all future graphs.A label can be added to a specific graph edge individually by passing a
weights
dictionary when creating the graph. It supportsSingleStringMathTex
,Text
andTex
objects as well as any other object that can be casted tostr
.Additional configuration is possible, globally or locally, by passing a "weight_config" dictionary in the
edge_config
dictionary.The labels have the same color as their respective edges, with their background color being set to
config["background_color"]
by default. This behavior is customizable by passing atext_color
orbackground_color
parameter in theweight_config
dictionary. The user can also use a custom label type instead of the defaultLabelledDot
class as aweight_type
parameter in the theweight_config
dictionary. To achieve this, the custom class must be initializable with thelabel
andcolor
keywords (If the class inherits from MObject, thecolor
keyword is already supported).Self-loops edges are easily created by defining a
(v, v)
edge in theedges
dictionary. Just as with other edges, self-loop edges use theedge_type
parameter during initialization. Analogously, this class has to support thepath_arc
keyword.They also support additional configuration by passing a "loop_config" dictionary in the
edge_config
. It can either be a local or global configuration. It supports "path_arc" and "angle_between_points" keywords. They are respectively used to determine the angle spanned by the drawn arc, and the angle between the two end points of the arc (relative to the center of the vertex).Possible future features:
It could be interesting to add a simpler way of displaying two-sided edges in
DiGraph
which could have different weights. It is possible to do it with the current implementation, but weights are hard to read, and if the two edges are created with different colors, the result is aesthetically unappealing.Reviewer Checklist