A community-maintained Python framework for creating mathematical animations.
Allowed passing vertex configuration keyword arguments to :meth:`.Graph.add_edges` (#2565)
Benjamin Hackl0071d982dfc7
diff --git a/manim/mobject/graph.py b/manim/mobject/graph.pyindex c08bed9db..c58f974cb 100644--- a/manim/mobject/graph.py+++ b/manim/mobject/graph.py@@ -6,6 +6,7 @@ __all__ = ["Graph",]+import itertools as itfrom copy import copyfrom typing import Hashable, Iterable@@ -874,6 +875,7 @@ class Graph(VMobject, metaclass=ConvertToOpenGL):*edges: tuple[Hashable, Hashable],edge_type: type[Mobject] = Line,edge_config: dict | None = None,+ **kwargs,):"""Add new edges to the graph.@@ -892,6 +894,9 @@ class Graph(VMobject, metaclass=ConvertToOpenGL):whose keys are the edge tuples, and whose values are dictionariescontaining keyword arguments to be passed for the constructionof the corresponding edge.+ kwargs+ Any further keyword arguments are passed to :meth:`.add_vertices`+ which is used to create new vertices in the passed edges.Returns-------@@ -909,6 +914,10 @@ class Graph(VMobject, metaclass=ConvertToOpenGL):base_edge_config[e].update(edge_config.get(e, {}))edge_config = base_edge_config+ edge_vertices = set(it.chain(*edges))+ new_vertices = [v for v in edge_vertices if v not in self.vertices]+ added_vertices = self.add_vertices(*new_vertices, **kwargs)+added_mobjects = sum((self._add_edge(@@ -918,7 +927,7 @@ class Graph(VMobject, metaclass=ConvertToOpenGL):).submobjectsfor edge in edges),- [],+ added_vertices,)return self.get_group_class()(*added_mobjects)