mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
Support edge lookup via tuple in GenericGraph.__getitem__() (#3799)
* feat: add tuple key support in GenericGraph.__getitem__() * feat: add an error message for missing vertice or edge Co-authored-by: adeshpande <110117391+JasonGrace2282@users.noreply.github.com> * docs: add an example * fix: tuple vertex return edge --------- Co-authored-by: adeshpande <110117391+JasonGrace2282@users.noreply.github.com> Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
This commit is contained in:
parent
852ebd1c60
commit
2ece488b2c
1 changed files with 12 additions and 2 deletions
|
|
@ -669,8 +669,13 @@ class GenericGraph(VMobject, metaclass=ConvertToOpenGL):
|
|||
"""Helper method for populating the edges of the graph."""
|
||||
raise NotImplementedError("To be implemented in concrete subclasses")
|
||||
|
||||
def __getitem__(self: Graph, v: Hashable) -> Mobject:
|
||||
return self.vertices[v]
|
||||
def __getitem__(self: Graph, k: Hashable | tuple[Hashable, Hashable]) -> Mobject:
|
||||
if k in self.vertices:
|
||||
return self.vertices[k]
|
||||
elif k in self.edges:
|
||||
return self.edges[k]
|
||||
else:
|
||||
raise ValueError(f"Could not find {k} in vertices or edges")
|
||||
|
||||
def _create_vertex(
|
||||
self,
|
||||
|
|
@ -1342,6 +1347,11 @@ class Graph(GenericGraph):
|
|||
g[2].animate.move_to([-1, 1, 0]),
|
||||
g[3].animate.move_to([1, -1, 0]),
|
||||
g[4].animate.move_to([-1, -1, 0]))
|
||||
self.play(LaggedStart(Wiggle(g[(1, 2)]),
|
||||
Wiggle(g[(2, 3)]),
|
||||
Wiggle(g[(3, 4)]),
|
||||
Wiggle(g[(1, 3)]),
|
||||
Wiggle(g[(1, 4)])))
|
||||
self.wait()
|
||||
|
||||
There are several automatic positioning algorithms to choose from:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue