Skip to content
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

Allowed passing vertex configuration keyword arguments to :meth:.Graph.add_edges #2565

Merged
merged 3 commits into from Feb 23, 2022

Conversation

behackl
Copy link
Member

@behackl behackl commented Feb 22, 2022

Overview: What does this pull request change?

See title.

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

Adding vertices and edges within the same play call causes problems. Creating edges whose vertices have not been added yet is somewhat unflexible as there is no way to influence the created vertices. With these changes, keyword arguments for vertex creation can be passed to add_edges as well. One example that did not work before, but does with this PR:

class GraphExample(Scene):
    def construct(self):
        g = Graph([], [])
        self.play(g.animate.add_edges((1,2))  # fails because vertices for 1 and 2 are both created in the center and no edge can be constructed between them
        self.play(g.animate.add_edges((1,2), positions={1: LEFT, 2: RIGHT})  # with this PR, keyword arguments like vertex position can be passed, this renders.

Reviewer Checklist

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

@behackl behackl added the enhancement Additions and improvements in general label Feb 22, 2022
@behackl
Copy link
Member Author

behackl commented Feb 22, 2022

If there are no objections, I'll merge this in a few hours: #2478 depends on it.

@Darylgolden
Copy link
Member

Isn't having all kwargs passed to add_vertices a little unclean? How about asking the user to pass these arguments in a dictionary?

@behackl
Copy link
Member Author

behackl commented Feb 23, 2022

Isn't having all kwargs passed to add_vertices a little unclean? How about asking the user to pass these arguments in a dictionary?

Two reasons why I think plain keyword arguments are fine / better:

  • The input is less convoluted. The parameter most relevant here is the position, and I'd prefer passing positions={1: LEFT} over vertex_kwargs={'positions': {1: LEFT}}. And as add_vertices processes its keyword arguments cleanly, misspelled or wrong arguments would be noticed.
  • I don't have a good idea for how the dictionary in the other case should be named. I dislike vertex_kwargs, but it is more or less my best suggestion. It should not be vertex_config because that's already an argument that can be passed -- maybe new_vertex_config as it is only used for the new vertices... but I also don't like that too much.

That's why I prefer to keep this as-is.

@behackl behackl added this to the 0.15.0 milestone Feb 23, 2022
@behackl behackl merged commit 0071d98 into ManimCommunity:main Feb 23, 2022
@behackl behackl deleted the improve-add-edges branch May 16, 2022 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Additions and improvements in general
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants