Repository: ManimCommunity/manim
File: manim/mobject/graph.py (Python)

Code before:
        self.edges = {
            (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())

        def update_edges(graph):
            for (u, v), edge in graph.edges.items():
                edge.put_start_and_end_on(graph[u].get_center(), graph[v].get_center())

        self.add_updater(update_edges)

    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"

    def _add_vertex(
        self,
        vertex: Hashable,
        position: np.ndarray | None = None,
        label: bool = False,
        label_fill_color: str = BLACK,
        vertex_type: type[Mobject] = Dot,
        vertex_config: dict | None = None,
        vertex_mobject: dict | None = None,
    ) -> Mobject:
        """Add a vertex to the graph.

        Parameters
        ----------

        vertex
            A hashable vertex identifier.
        position
            The coordinates where the new vertex should be added. If ``None``, the center
            of the graph is used.
        label
            Controls whether or not the vertex is labeled. If ``False`` (the default),
            the vertex is not labeled; if ``True`` it is labeled using its
            names (as specified in ``vertex``) via :class:`~.MathTex`. Alternatively,
            any :class:`~.Mobject` can be passed to be used as the label.
        label_fill_color

Review comment (suggestion):
I like these changes to `Graph` vertex creation, regardless of the changed overridden animation. I do have to admit: I don't like the amount of bending of the Animation framework that needs to be done to make custom overrides of vertex creation work. Maybe it is not worth keeping the `@override_animate` idea around.

Code after:
        self.edges = {
            (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())

        def update_edges(graph):
            for (u, v), edge in graph.edges.items():
                edge.put_start_and_end_on(graph[u].get_center(), graph[v].get_center())

        self.add_updater(update_edges)

    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"

    def _create_vertex(
        self,
        vertex: Hashable,
        position: np.ndarray | None = None,
        label: bool = False,
        label_fill_color: str = BLACK,
        vertex_type: type[Mobject] = Dot,
        vertex_config: dict | None = None,
        vertex_mobject: dict | None = None,
    ) -> tuple[Hashable, np.ndarray, dict, Mobject]:
        if position is None:
            position = self.get_center()

        if vertex_config is None:
            vertex_config = {}

        if vertex in self.vertices:
            raise ValueError(
                f"Vertex identifier '{vertex}' is already used for a vertex in this graph.",
            )

        if isinstance(label, (Mobject, OpenGLMobject)):
            label = label
        elif label is True:
            label = MathTex(vertex, fill_color=label_fill_color)
        elif vertex in self._labels: