A community-maintained Python framework for creating mathematical animations.
Basic implementation of undirected graphs (#861)
Benjamin Hackle16f9a6cc4da
diff --git a/docs/source/reference.rst b/docs/source/reference.rstindex d4e8d77b6..a4cfab6ec 100644--- a/docs/source/reference.rst+++ b/docs/source/reference.rst@@ -22,6 +22,7 @@ Mobjects~mobject.frame~mobject.functions~mobject.geometry+ ~mobject.graph~mobject.logo~mobject.matrix~mobject.mobjectdiff --git a/manim/__init__.py b/manim/__init__.pyindex fd34b97db..727a5aa41 100644--- a/manim/__init__.py+++ b/manim/__init__.py@@ -33,6 +33,7 @@ from .mobject.changing import *from .mobject.frame import *from .mobject.functions import *from .mobject.geometry import *+from .mobject.graph import *from .mobject.logo import *from .mobject.matrix import *from .mobject.mobject import *diff --git a/manim/mobject/graph.py b/manim/mobject/graph.pynew file mode 100644index 000000000..8f705426e--- /dev/null+++ b/manim/mobject/graph.py@@ -0,0 +1,305 @@+"""Mobjects used to represent mathematical graphs (think graph theory, not plotting)."""++__all__ = [+ "Graph",+]++from ..constants import UP+from ..utils.color import BLACK+from .types.vectorized_mobject import VMobject+from .geometry import Dot, Line, LabeledDot+from .svg.tex_mobject import MathTex++from typing import Hashable, Union, List, Tuple++from copy import copy+import networkx as nx+import numpy as np+++class Graph(VMobject):+ """An undirected graph (that is, a collection of vertices connected with edges).++ Graphs can be instantiated by passing both a list of (distinct, hashable)+ vertex names, together with list of edges (as tuples of vertex names). See+ the examples below for details.++ .. note::++ This implementation uses updaters to make the edges move with+ the vertices.++ Parameters+ ----------++ vertices+ A list of vertices. Must be hashable elements.+ edges+ A list of edges, specified as tuples ``(u, v)`` where both ``u``+ and ``v`` are vertices.+ labels+ Controls whether or not vertices are labeled. If ``False`` (the default),+ the vertices are not labeled; if ``True`` they are labeled using their+ names (as specified in ``vertices``) via :class:`~.MathTex`. Alternatively,+ custom labels can be specified by passing a dictionary whose keys are+ the vertices, and whose values are the corresponding vertex labels+ (rendered via, e.g., :class:`~.Text` or :class:`~.Tex`).+ label_fill_color+ Sets the fill color of the default labels generated when ``labels``+ is set to ``True``. Has no effect for other values of ``labels``.+ layout+ Either one of ``"spring"`` (the default), ``"circular"``, ``"kamada_kawai"``,+ ``"planar"``, ``"random"``, ``"shell"``, ``"spectral"``, and ``"spiral"``+ for automatic vertex positioning using ``networkx``+ (see `their documentation <https://networkx.org/documentation/stable/reference/drawing.html#module-networkx.drawing.layout>`_+ for more details), or a dictionary specifying a coordinate (value)+ for each vertex (key) for manual positioning.+ layout_scale+ The scale of automatically generated layouts: the vertices will+ be arranged such that the coordinates are located within the+ interval ``[-scale, scale]``. Default: 2.+ layout_config+ Only for automatically generated layouts. A dictionary whose entries+ are passed as keyword arguments to the automatic layout algorithm+ specified via ``layout`` of``networkx``.+ vertex_type+ The mobject class used for displaying vertices in the scene.+ vertex_config+ Either a dictionary containing keyword arguments to be passed to+ the class specified via ``vertex_type``, or a dictionary whose keys+ are the vertices, and whose values are dictionaries containing keyword+ arguments for the mobject related to the corresponding vertex.+ edge_type+ The mobject class used for displaying edges in the scene.+ edge_config+ Either a dictionary containing keyword arguments to be passed+ to the class specified via ``edge_type``, or a dictionary whose+ keys are the edges, and whose values are dictionaries containing+ keyword arguments for the mobject related to the corresponding edge.++ Examples+ --------++ First, we create a small graph and demonstrate that the edges move+ together with the vertices.++ .. manim:: MovingVertices++ class MovingVertices(Scene):+ def construct(self):+ vertices = [1, 2, 3, 4]+ edges = [(1, 2), (2, 3), (3, 4), (1, 3), (1, 4)]+ g = Graph(vertices, edges)+ self.play(ShowCreation(g))+ self.wait()+ self.play(g[1].animate.move_to([1, 1, 0]),+ 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.wait()++ There are several automatic positioning algorithms to choose from:++ .. manim:: GraphAutoPosition+ :save_last_frame:++ class GraphAutoPosition(Scene):+ def construct(self):+ vertices = [1, 2, 3, 4, 5, 6, 7, 8]+ edges = [(1, 7), (1, 8), (2, 3), (2, 4), (2, 5),+ (2, 8), (3, 4), (6, 1), (6, 2),+ (6, 3), (7, 2), (7, 4)]+ autolayouts = ["spring", "circular", "kamada_kawai",+ "planar", "random", "shell",+ "spectral", "spiral"]+ graphs = [Graph(vertices, edges, layout=lt).scale(0.5)+ for lt in autolayouts]+ r1 = VGroup(*graphs[:3]).arrange()+ r2 = VGroup(*graphs[3:6]).arrange()+ r3 = VGroup(*graphs[6:]).arrange()+ self.add(VGroup(r1, r2, r3).arrange(direction=DOWN))++ Vertices can also be positioned manually:++ .. manim:: GraphManualPosition+ :save_last_frame:++ class GraphManualPosition(Scene):+ def construct(self):+ vertices = [1, 2, 3, 4]+ edges = [(1, 2), (2, 3), (3, 4), (4, 1)]+ lt = {1: [0, 0, 0], 2: [1, 1, 0], 3: [1, -1, 0], 4: [-1, 0, 0]}+ G = Graph(vertices, edges, layout=lt)+ self.add(G)++ The vertices in graphs can be labeled, and configurations for vertices+ and edges can be modified both by default and for specific vertices and+ edges.++ .. note::++ In ``edge_config``, edges can be passed in both directions: if+ ``(u, v)`` is an edge in the graph, both ``(u, v)`` as well+ as ``(v, u)`` can be used as keys in the dictionary.++ .. manim:: LabeledModifiedGraph+ :save_last_frame:++ class LabeledModifiedGraph(Scene):+ def construct(self):+ vertices = [1, 2, 3, 4, 5, 6, 7, 8]+ edges = [(1, 7), (1, 8), (2, 3), (2, 4), (2, 5),+ (2, 8), (3, 4), (6, 1), (6, 2),+ (6, 3), (7, 2), (7, 4)]+ g = Graph(vertices, edges, layout="circular", layout_scale=3,+ labels=True, vertex_config={7: {"fill_color": RED}},+ edge_config={(1, 7): {"stroke_color": RED},+ (2, 7): {"stroke_color": RED},+ (4, 7): {"stroke_color": RED}})+ self.add(g)++ """++ def __init__(+ self,+ vertices: List[Hashable],+ edges: List[Tuple[Hashable, Hashable]],+ labels: bool = False,+ label_fill_color: str = BLACK,+ layout: Union[str, dict] = "spring",+ layout_scale: float = 2,+ layout_config: Union[dict, None] = None,+ vertex_type: "Mobject" = Dot,+ vertex_config: Union[dict, None] = None,+ edge_type: "Mobject" = Line,+ edge_config: Union[dict, None] = None,+ ) -> None:+ VMobject.__init__(self)++ nx_graph = nx.Graph()+ nx_graph.add_nodes_from(vertices)+ nx_graph.add_edges_from(edges)+ self._graph = nx_graph++ automatic_layouts = {+ "circular": nx.layout.circular_layout,+ "kamada_kawai": nx.layout.kamada_kawai_layout,+ "planar": nx.layout.planar_layout,+ "random": nx.layout.random_layout,+ "shell": nx.layout.shell_layout,+ "spectral": nx.layout.spectral_layout,+ "spiral": nx.layout.spiral_layout,+ "spring": nx.layout.spring_layout,+ }++ if layout_config is None:+ layout_config = {}++ if isinstance(layout, dict):+ self._layout = layout+ elif layout in automatic_layouts and layout != "random":+ self._layout = automatic_layouts[layout](+ nx_graph, scale=layout_scale, **layout_config+ )+ self._layout = dict(+ [(k, np.append(v, [0])) for k, v in self._layout.items()]+ )+ elif layout == "random":+ # the random layout places coordinates in [0, 1)+ # we need to rescale manually afterwards...+ self._layout = automatic_layouts["random"](nx_graph, **layout_config)+ for k, v in self._layout.items():+ self._layout[k] = 2 * layout_scale * (v - np.array([0.5, 0.5]))+ self._layout = dict(+ [(k, np.append(v, [0])) for k, v in self._layout.items()]+ )+ else:+ raise ValueError(+ f"The layout '{layout}' is neither a recognized automatic layout, "+ "nor a vertex placement dictionary."+ )++ if isinstance(labels, dict):+ self._labels = labels+ elif isinstance(labels, bool):+ if labels:+ self._labels = dict(+ [(v, MathTex(v, fill_color=label_fill_color)) for v in vertices]+ )+ else:+ self._labels = dict()++ if self._labels and vertex_type is Dot:+ vertex_type = LabeledDot++ # build vertex_config+ if vertex_config is None:+ vertex_config = {}+ default_vertex_config = {}+ if vertex_config:+ default_vertex_config = dict(+ [(k, v) for k, v in vertex_config.items() if k not in vertices]+ )+ self._vertex_config = dict(+ [(v, vertex_config.get(v, copy(default_vertex_config))) for v in vertices]+ )+ for v, label in self._labels.items():+ self._vertex_config[v]["label"] = label++ self.vertices = dict(+ [(v, vertex_type(**self._vertex_config[v])) for v in vertices]+ )+ for v in self.vertices:+ self[v].move_to(self._layout[v])++ # build edge_config+ if edge_config is None:+ edge_config = {}+ default_edge_config = {}+ if edge_config:+ default_edge_config = dict(+ (k, v)+ for k, v in edge_config.items()+ if k not in edges and k[::-1] not in edges+ )+ self._edge_config = {}+ for e in edges:+ if e in edge_config:+ self._edge_config[e] = edge_config[e]+ elif e[::-1] in edge_config:+ self._edge_config[e] = edge_config[e[::-1]]+ else:+ self._edge_config[e] = copy(default_edge_config)++ self.edges = dict(+ [+ (+ (u, v),+ edge_type(+ self[u].get_center(),+ self[v].get_center(),+ z_index=-1,+ **self._edge_config[(u, v)],+ ),+ )+ for (u, v) in edges+ ]+ )++ self.add(*self.vertices.values())+ self.add(*self.edges.values())++ for (u, v), edge in self.edges.items():++ def update_edge(e, u=u, v=v):+ e.set_start_and_end_attrs(self[u].get_center(), self[v].get_center())+ e.generate_points()++ update_edge(edge)+ edge.add_updater(update_edge)++ def __getitem__(self: "Graph", v: Hashable) -> "Mobject":+ return self.vertices[v]++ def __repr__(self: "Graph") -> str:+ return f"Graph on {len(self.vertices)} vertices and {len(self.edges)} edges"diff --git a/poetry.lock b/poetry.lockindex c6342e923..b845c9ac7 100644--- a/poetry.lock+++ b/poetry.lock@@ -136,7 +136,7 @@ optional = falsepython-versions = "*"[package.extras]-test = ["flake8 (==3.7.8)", "hypothesis (==3.55.3)"]+test = ["flake8 (3.7.8)", "hypothesis (3.55.3)"][[package]]name = "cycler"@@ -157,6 +157,14 @@ category = "main"optional = falsepython-versions = ">=3.6, <3.7"+[[package]]+name = "decorator"+version = "4.4.2"+description = "Decorators for Humans"+category = "main"+optional = false+python-versions = ">=2.6, !=3.0.*, !=3.1.*"+[[package]]name = "docutils"version = "0.16"@@ -232,7 +240,7 @@ zipp = ">=0.5"[package.extras]docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"]-testing = ["pytest (>=3.5,!=3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "jaraco.test (>=3.2.0)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"]+testing = ["pytest (>=3.5,<3.7.3 || >3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "jaraco.test (>=3.2.0)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"][[package]]name = "iniconfig"@@ -244,7 +252,7 @@ python-versions = "*"[[package]]name = "isort"-version = "5.6.4"+version = "5.7.0"description = "A Python utility / library to sort Python imports."category = "dev"optional = false@@ -333,6 +341,30 @@ category = "dev"optional = falsepython-versions = "*"+[[package]]+name = "networkx"+version = "2.5"+description = "Python package for creating and manipulating graphs and networks"+category = "main"+optional = false+python-versions = ">=3.6"++[package.dependencies]+decorator = ">=4.3.0"++[package.extras]+all = ["numpy", "scipy", "pandas", "matplotlib", "pygraphviz", "pydot", "pyyaml", "lxml", "pytest"]+gdal = ["gdal"]+lxml = ["lxml"]+matplotlib = ["matplotlib"]+numpy = ["numpy"]+pandas = ["pandas"]+pydot = ["pydot"]+pygraphviz = ["pygraphviz"]+pytest = ["pytest"]+pyyaml = ["pyyaml"]+scipy = ["scipy"]+[[package]]name = "numpy"version = "1.19.4"@@ -534,7 +566,7 @@ urllib3 = ">=1.21.1,<1.27"[package.extras]security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"]-socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"]+socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7)", "win-inet-pton"][[package]]name = "rich"@@ -705,7 +737,7 @@ telegram = ["requests"][[package]]name = "typed-ast"-version = "1.4.1"+version = "1.4.2"description = "a fork of Python 2 and 3 ast modules with type comment support"category = "dev"optional = false@@ -730,7 +762,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"[package.extras]brotli = ["brotlipy (>=0.6.0)"]secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"]-socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]+socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7,<2.0)"][[package]]name = "watchdog"@@ -761,7 +793,7 @@ python-versions = ">=3.6"[package.extras]docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"]-testing = ["pytest (>=3.5,!=3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "jaraco.test (>=3.2.0)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"]+testing = ["pytest (>=3.5,<3.7.3 || >3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "jaraco.test (>=3.2.0)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"][extras]js_renderer = ["grpcio", "grpcio-tools", "watchdog"]@@ -769,7 +801,7 @@ js_renderer = ["grpcio", "grpcio-tools", "watchdog"][metadata]lock-version = "1.1"python-versions = "^3.6"-content-hash = "c2d54eafca0b27220ef8fd1432501a461399480e4bc81e61adce393b17d98f30"+content-hash = "a93e116c1f18b3051247c3f05c79d966b2b846e018d23284e4198422a33419d6"[metadata.files]alabaster = [@@ -831,6 +863,10 @@ dataclasses = [{file = "dataclasses-0.7-py3-none-any.whl", hash = "sha256:3459118f7ede7c8bea0fe795bff7c6c2ce287d01dd226202f7c9ebc0610a7836"},{file = "dataclasses-0.7.tar.gz", hash = "sha256:494a6dcae3b8bcf80848eea2ef64c0cc5cd307ffc263e17cdf42f3e5420808e6"},]+decorator = [+ {file = "decorator-4.4.2-py2.py3-none-any.whl", hash = "sha256:41fa54c2a0cc4ba648be4fd43cff00aedf5b9465c9bf18d64325bc225f08f760"},+ {file = "decorator-4.4.2.tar.gz", hash = "sha256:e3a62f0520172440ca0dcc823749319382e377f37f140a0b99ef45fecb84bfe7"},+]docutils = [{file = "docutils-0.16-py2.py3-none-any.whl", hash = "sha256:0c5b78adfbf7762415433f5515cd5c9e762339e23369dbe8000d84a4bf4ab3af"},{file = "docutils-0.16.tar.gz", hash = "sha256:c2de3a60e9e7d07be26b7f2b00ca0309c207e06c100f9cc2a94931fc75a478fc"},@@ -951,8 +987,8 @@ iniconfig = [{file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"},]isort = [- {file = "isort-5.6.4-py3-none-any.whl", hash = "sha256:dcab1d98b469a12a1a624ead220584391648790275560e1a43e54c5dceae65e7"},- {file = "isort-5.6.4.tar.gz", hash = "sha256:dcaeec1b5f0eca77faea2a35ab790b4f3680ff75590bfcb7145986905aab2f58"},+ {file = "isort-5.7.0-py3-none-any.whl", hash = "sha256:fff4f0c04e1825522ce6949973e83110a6e907750cd92d128b0d14aaaadbffdc"},+ {file = "isort-5.7.0.tar.gz", hash = "sha256:c729845434366216d320e936b8ad6f9d681aab72dc7cbc2d51bedc3582f3ad1e"},]jinja2 = [{file = "Jinja2-2.11.2-py2.py3-none-any.whl", hash = "sha256:f0a4641d3cf955324a89c04f3d94663aa4d638abe8f733ecd3582848e1c37035"},@@ -1109,6 +1145,10 @@ mypy-extensions = [{file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"},{file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"},]+networkx = [+ {file = "networkx-2.5-py3-none-any.whl", hash = "sha256:8c5812e9f798d37c50570d15c4a69d5710a18d77bafc903ee9c5fba7454c616c"},+ {file = "networkx-2.5.tar.gz", hash = "sha256:7978955423fbc9639c10498878be59caf99b44dc304c2286162fd24b458c1602"},+]numpy = [{file = "numpy-1.19.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:e9b30d4bd69498fc0c3fe9db5f62fffbb06b8eb9321f92cc970f2969be5e3949"},{file = "numpy-1.19.4-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:fedbd128668ead37f33917820b704784aff695e0019309ad446a6d0b065b57e4"},@@ -1380,36 +1420,36 @@ tqdm = [{file = "tqdm-4.55.0.tar.gz", hash = "sha256:f4f80b96e2ceafea69add7bf971b8403b9cba8fb4451c1220f91c79be4ebd208"},]typed-ast = [- {file = "typed_ast-1.4.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:73d785a950fc82dd2a25897d525d003f6378d1cb23ab305578394694202a58c3"},- {file = "typed_ast-1.4.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:aaee9905aee35ba5905cfb3c62f3e83b3bec7b39413f0a7f19be4e547ea01ebb"},- {file = "typed_ast-1.4.1-cp35-cp35m-win32.whl", hash = "sha256:0c2c07682d61a629b68433afb159376e24e5b2fd4641d35424e462169c0a7919"},- {file = "typed_ast-1.4.1-cp35-cp35m-win_amd64.whl", hash = "sha256:4083861b0aa07990b619bd7ddc365eb7fa4b817e99cf5f8d9cf21a42780f6e01"},- {file = "typed_ast-1.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:269151951236b0f9a6f04015a9004084a5ab0d5f19b57de779f908621e7d8b75"},- {file = "typed_ast-1.4.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:24995c843eb0ad11a4527b026b4dde3da70e1f2d8806c99b7b4a7cf491612652"},- {file = "typed_ast-1.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:fe460b922ec15dd205595c9b5b99e2f056fd98ae8f9f56b888e7a17dc2b757e7"},- {file = "typed_ast-1.4.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:fcf135e17cc74dbfbc05894ebca928ffeb23d9790b3167a674921db19082401f"},- {file = "typed_ast-1.4.1-cp36-cp36m-win32.whl", hash = "sha256:4e3e5da80ccbebfff202a67bf900d081906c358ccc3d5e3c8aea42fdfdfd51c1"},- {file = "typed_ast-1.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:249862707802d40f7f29f6e1aad8d84b5aa9e44552d2cc17384b209f091276aa"},- {file = "typed_ast-1.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8ce678dbaf790dbdb3eba24056d5364fb45944f33553dd5869b7580cdbb83614"},- {file = "typed_ast-1.4.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:c9e348e02e4d2b4a8b2eedb48210430658df6951fa484e59de33ff773fbd4b41"},- {file = "typed_ast-1.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:bcd3b13b56ea479b3650b82cabd6b5343a625b0ced5429e4ccad28a8973f301b"},- {file = "typed_ast-1.4.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:f208eb7aff048f6bea9586e61af041ddf7f9ade7caed625742af423f6bae3298"},- {file = "typed_ast-1.4.1-cp37-cp37m-win32.whl", hash = "sha256:d5d33e9e7af3b34a40dc05f498939f0ebf187f07c385fd58d591c533ad8562fe"},- {file = "typed_ast-1.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:0666aa36131496aed8f7be0410ff974562ab7eeac11ef351def9ea6fa28f6355"},- {file = "typed_ast-1.4.1-cp38-cp38-macosx_10_15_x86_64.whl", hash = "sha256:d205b1b46085271b4e15f670058ce182bd1199e56b317bf2ec004b6a44f911f6"},- {file = "typed_ast-1.4.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:6daac9731f172c2a22ade6ed0c00197ee7cc1221aa84cfdf9c31defeb059a907"},- {file = "typed_ast-1.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:498b0f36cc7054c1fead3d7fc59d2150f4d5c6c56ba7fb150c013fbc683a8d2d"},- {file = "typed_ast-1.4.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:7e4c9d7658aaa1fc80018593abdf8598bf91325af6af5cce4ce7c73bc45ea53d"},- {file = "typed_ast-1.4.1-cp38-cp38-win32.whl", hash = "sha256:715ff2f2df46121071622063fc7543d9b1fd19ebfc4f5c8895af64a77a8c852c"},- {file = "typed_ast-1.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:fc0fea399acb12edbf8a628ba8d2312f583bdbdb3335635db062fa98cf71fca4"},- {file = "typed_ast-1.4.1-cp39-cp39-macosx_10_15_x86_64.whl", hash = "sha256:d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf64ad54933ad4d34"},- {file = "typed_ast-1.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:92c325624e304ebf0e025d1224b77dd4e6393f18aab8d829b5b7e04afe9b7a2c"},- {file = "typed_ast-1.4.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:d648b8e3bf2fe648745c8ffcee3db3ff903d0817a01a12dd6a6ea7a8f4889072"},- {file = "typed_ast-1.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:fac11badff8313e23717f3dada86a15389d0708275bddf766cca67a84ead3e91"},- {file = "typed_ast-1.4.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:0d8110d78a5736e16e26213114a38ca35cb15b6515d535413b090bd50951556d"},- {file = "typed_ast-1.4.1-cp39-cp39-win32.whl", hash = "sha256:b52ccf7cfe4ce2a1064b18594381bccf4179c2ecf7f513134ec2f993dd4ab395"},- {file = "typed_ast-1.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:3742b32cf1c6ef124d57f95be609c473d7ec4c14d0090e5a5e05a15269fb4d0c"},- {file = "typed_ast-1.4.1.tar.gz", hash = "sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b"},+ {file = "typed_ast-1.4.2-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:7703620125e4fb79b64aa52427ec192822e9f45d37d4b6625ab37ef403e1df70"},+ {file = "typed_ast-1.4.2-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:c9aadc4924d4b5799112837b226160428524a9a45f830e0d0f184b19e4090487"},+ {file = "typed_ast-1.4.2-cp35-cp35m-manylinux2014_aarch64.whl", hash = "sha256:9ec45db0c766f196ae629e509f059ff05fc3148f9ffd28f3cfe75d4afb485412"},+ {file = "typed_ast-1.4.2-cp35-cp35m-win32.whl", hash = "sha256:85f95aa97a35bdb2f2f7d10ec5bbdac0aeb9dafdaf88e17492da0504de2e6400"},+ {file = "typed_ast-1.4.2-cp35-cp35m-win_amd64.whl", hash = "sha256:9044ef2df88d7f33692ae3f18d3be63dec69c4fb1b5a4a9ac950f9b4ba571606"},+ {file = "typed_ast-1.4.2-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:c1c876fd795b36126f773db9cbb393f19808edd2637e00fd6caba0e25f2c7b64"},+ {file = "typed_ast-1.4.2-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:5dcfc2e264bd8a1db8b11a892bd1647154ce03eeba94b461effe68790d8b8e07"},+ {file = "typed_ast-1.4.2-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:8db0e856712f79c45956da0c9a40ca4246abc3485ae0d7ecc86a20f5e4c09abc"},+ {file = "typed_ast-1.4.2-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:d003156bb6a59cda9050e983441b7fa2487f7800d76bdc065566b7d728b4581a"},+ {file = "typed_ast-1.4.2-cp36-cp36m-win32.whl", hash = "sha256:4c790331247081ea7c632a76d5b2a265e6d325ecd3179d06e9cf8d46d90dd151"},+ {file = "typed_ast-1.4.2-cp36-cp36m-win_amd64.whl", hash = "sha256:d175297e9533d8d37437abc14e8a83cbc68af93cc9c1c59c2c292ec59a0697a3"},+ {file = "typed_ast-1.4.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:cf54cfa843f297991b7388c281cb3855d911137223c6b6d2dd82a47ae5125a41"},+ {file = "typed_ast-1.4.2-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:b4fcdcfa302538f70929eb7b392f536a237cbe2ed9cba88e3bf5027b39f5f77f"},+ {file = "typed_ast-1.4.2-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:987f15737aba2ab5f3928c617ccf1ce412e2e321c77ab16ca5a293e7bbffd581"},+ {file = "typed_ast-1.4.2-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:37f48d46d733d57cc70fd5f30572d11ab8ed92da6e6b28e024e4a3edfb456e37"},+ {file = "typed_ast-1.4.2-cp37-cp37m-win32.whl", hash = "sha256:36d829b31ab67d6fcb30e185ec996e1f72b892255a745d3a82138c97d21ed1cd"},+ {file = "typed_ast-1.4.2-cp37-cp37m-win_amd64.whl", hash = "sha256:8368f83e93c7156ccd40e49a783a6a6850ca25b556c0fa0240ed0f659d2fe496"},+ {file = "typed_ast-1.4.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:963c80b583b0661918718b095e02303d8078950b26cc00b5e5ea9ababe0de1fc"},+ {file = "typed_ast-1.4.2-cp38-cp38-manylinux1_i686.whl", hash = "sha256:e683e409e5c45d5c9082dc1daf13f6374300806240719f95dc783d1fc942af10"},+ {file = "typed_ast-1.4.2-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:84aa6223d71012c68d577c83f4e7db50d11d6b1399a9c779046d75e24bed74ea"},+ {file = "typed_ast-1.4.2-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:a38878a223bdd37c9709d07cd357bb79f4c760b29210e14ad0fb395294583787"},+ {file = "typed_ast-1.4.2-cp38-cp38-win32.whl", hash = "sha256:a2c927c49f2029291fbabd673d51a2180038f8cd5a5b2f290f78c4516be48be2"},+ {file = "typed_ast-1.4.2-cp38-cp38-win_amd64.whl", hash = "sha256:c0c74e5579af4b977c8b932f40a5464764b2f86681327410aa028a22d2f54937"},+ {file = "typed_ast-1.4.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:07d49388d5bf7e863f7fa2f124b1b1d89d8aa0e2f7812faff0a5658c01c59aa1"},+ {file = "typed_ast-1.4.2-cp39-cp39-manylinux1_i686.whl", hash = "sha256:240296b27397e4e37874abb1df2a608a92df85cf3e2a04d0d4d61055c8305ba6"},+ {file = "typed_ast-1.4.2-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:d746a437cdbca200622385305aedd9aef68e8a645e385cc483bdc5e488f07166"},+ {file = "typed_ast-1.4.2-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:14bf1522cdee369e8f5581238edac09150c765ec1cb33615855889cf33dcb92d"},+ {file = "typed_ast-1.4.2-cp39-cp39-win32.whl", hash = "sha256:cc7b98bf58167b7f2db91a4327da24fb93368838eb84a44c472283778fc2446b"},+ {file = "typed_ast-1.4.2-cp39-cp39-win_amd64.whl", hash = "sha256:7147e2a76c75f0f64c4319886e7639e490fee87c9d25cb1d4faef1d8cf83a440"},+ {file = "typed_ast-1.4.2.tar.gz", hash = "sha256:9fc0b3cb5d1720e7141d103cf4819aea239f7d136acf9ee4a69b047b7986175a"},]typing-extensions = [{file = "typing_extensions-3.7.4.3-py2-none-any.whl", hash = "sha256:dafc7639cde7f1b6e1acc0f457842a83e722ccca8eef5270af2d74792619a89f"},diff --git a/pyproject.toml b/pyproject.tomlindex cff99152d..5f7b5e6f5 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -39,6 +39,7 @@ manimpango = "^0.1.4"grpcio = { version = "1.33.*", optional = true }grpcio-tools = { version = "1.33.*", optional = true }watchdog = { version = "*", optional = true }+networkx = "^2.5"[tool.poetry.extras]js_renderer = ["grpcio","grpcio-tools","watchdog"]diff --git a/tests/control_data/graphical_units_data/graph/AxesTest.npz b/tests/control_data/graphical_units_data/plot/AxesTest.npzsimilarity index 100%rename from tests/control_data/graphical_units_data/graph/AxesTest.npzrename to tests/control_data/graphical_units_data/plot/AxesTest.npzdiff --git a/tests/control_data/graphical_units_data/graph/PlotFunctions.npz b/tests/control_data/graphical_units_data/plot/PlotFunctions.npzsimilarity index 100%rename from tests/control_data/graphical_units_data/graph/PlotFunctions.npzrename to tests/control_data/graphical_units_data/plot/PlotFunctions.npzdiff --git a/tests/test_graph.py b/tests/test_graph.pynew file mode 100644index 000000000..d7052bb2d--- /dev/null+++ b/tests/test_graph.py@@ -0,0 +1,11 @@+from manim import Graph+++def test_graph_creation():+ vertices = [1, 2, 3, 4]+ edges = [(1, 2), (2, 3), (3, 4), (4, 1)]+ layout = {1: [0, 0, 0], 2: [1, 1, 0], 3: [1, -1, 0], 4: [-1, 0, 0]}+ G_manual = Graph(vertices=vertices, edges=edges, layout=layout)+ assert str(G_manual) == "Graph on 4 vertices and 4 edges"+ G_spring = Graph(vertices=vertices, edges=edges)+ assert str(G_spring) == "Graph on 4 vertices and 4 edges"diff --git a/tests/test_graphical_units/test_axes.py b/tests/test_graphical_units/test_axes.pyindex 6364b8989..f3d1f8f41 100644--- a/tests/test_graphical_units/test_axes.py+++ b/tests/test_graphical_units/test_axes.py@@ -30,7 +30,7 @@ class AxesTest(GraphScene):self.setup_axes(animate=True)-MODULE_NAME = "graph"+MODULE_NAME = "plot"@pytest.mark.slowdiff --git a/tests/test_graphical_units/test_graph.py b/tests/test_graphical_units/test_graphscene.pysimilarity index 97%rename from tests/test_graphical_units/test_graph.pyrename to tests/test_graphical_units/test_graphscene.pyindex 67e302e8c..a09a33ac4 100644--- a/tests/test_graphical_units/test_graph.py+++ b/tests/test_graphical_units/test_graphscene.py@@ -29,7 +29,7 @@ class PlotFunctions(GraphScene):self.play(Animation(f))-MODULE_NAME = "graph"+MODULE_NAME = "plot"@pytest.mark.slow