Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix: Allow Graph Mobject to be initialised with an empty list of vertices (#4946)

Christopher Hampson531494047861
diff --git a/manim/mobject/graph.py b/manim/mobject/graph.py
index 9d064aaec..92774117f 100644
--- a/manim/mobject/graph.py
+++ b/manim/mobject/graph.py
@@ -454,6 +454,10 @@ def _determine_graph_layout(
return layout
elif layout in _layouts:
auto_layout = _layouts[layout](nx_graph, scale=layout_scale, **layout_config)
+
+ if not auto_layout:
+ return {}
+
# NetworkX returns a dictionary of 3D points if the dimension
# is specified to be 3. Otherwise, it returns a dictionary of
# 2D points, so adjusting is required.
diff --git a/tests/module/mobject/test_graph.py b/tests/module/mobject/test_graph.py
index fb052119d..7c36de93d 100644
--- a/tests/module/mobject/test_graph.py
+++ b/tests/module/mobject/test_graph.py
@@ -18,6 +18,14 @@ def test_graph_creation():
assert str(G_directed) == "Directed graph on 4 vertices and 4 edges"
[email protected]("graph_class", [Graph, DiGraph])
+def test_empty_graph_creation(graph_class):
+ graph = graph_class([], [])
+
+ assert graph.vertices == {}
+ assert graph.edges == {}
+
+
def test_graph_add_vertices():
G = Graph([1, 2, 3], [(1, 2), (2, 3)])
G.add_vertices(4)