manim
manim copied to clipboard
Fix graph animation when adding vertex and edge together
Overview: What does this pull request change?
Vertex and edges when added using .animate results in error.
Motivation and Explanation: Why and how do your changes improve the library?
When vertex and edges are added using .animate to a graph simulatenously, the vertex doesn't update the graph till its animation is finished. In the meantime, edge animation will place new edges on its own, overriding the vertex positioning, and an error shows when the vertex animation finally finishes and calls on_finish to update the graph.
Instead, we can update the graph before playing the vertex animation and everything works as expected
self.play(
LaggedStart(
g.animate.add_vertices(
3, 4, positions={3: UP, 4: DOWN},
),
g.animate.add_edges((1, 3), (3, 2), (1, 4), (4, 2)),
lag_ratio=0.2,
)
)
Before:
ValueError: Vertex identifier '3' is already used for a vertex in this graph.
After:
https://user-images.githubusercontent.com/43041139/179371632-65017dff-42c4-45ab-90c2-4ada717c8684.mp4
Links to added or changed documentation pages
Further Information and Comments
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