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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion manim/mobject/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"Graph",
]

import itertools as it
from copy import copy
from typing import Hashable, Iterable

Expand Down Expand Up @@ -874,6 +875,7 @@ def add_edges(
*edges: tuple[Hashable, Hashable],
edge_type: type[Mobject] = Line,
edge_config: dict | None = None,
**kwargs,
):
"""Add new edges to the graph.

Expand All @@ -892,6 +894,9 @@ def add_edges(
whose keys are the edge tuples, and whose values are dictionaries
containing keyword arguments to be passed for the construction
of 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
-------
Expand All @@ -909,6 +914,10 @@ def add_edges(
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(
Expand All @@ -918,7 +927,7 @@ def add_edges(
).submobjects
for edge in edges
),
[],
added_vertices,
)
return self.get_group_class()(*added_mobjects)

Expand Down