manim icon indicating copy to clipboard operation
manim copied to clipboard

`self.play(Create(G))` connects edges to the centre of vertices unlike `self.add(G)` for Graphs

Open drdebmath opened this issue 3 years ago • 8 comments

Description of bug / unexpected behavior

The edges connect to the center of vertices in self.play(Create(G))

Expected behavior

I would expect it to output a graph similar to what happens in self.add(G)

How to reproduce the issue

Code for reproducing the problem
from manim import *

class bugreport_expected(Scene):
    def construct(self):
        edges = [(1, 2), (1, 3), (2, 4), (2, 5), (2, 9), (3, 7), (3, 8), (4, 9), (9, 10), (5, 6), (6, 7), (6, 8), (7, 8), (8, 10), (10, 1)]
        vertices = list(range(1,11))
        vertex_config = {}
        for i in vertices:
            vertex_config[i] = {'radius': 0.2, 'color': WHITE}
        edge_config = {}
        for i in edges:
            edge_config[i] = {'stroke_width': 3, 'tip_length': 0.2, 'color': WHITE}
        labels = {}
        labels_text = "abcdefghij"
        for i in vertices:
            labels[i] = Tex(r''+labels_text[i-1], color=BLACK)
        G = Graph(vertices, edges, layout="circular", vertex_config=vertex_config, edge_config=edge_config, edge_type=Arrow, labels = labels)
        self.add(G)

class bugreport_actual(Scene):
    def construct(self):
        edges = [(1, 2), (1, 3), (2, 4), (2, 5), (2, 9), (3, 7), (3, 8), (4, 9), (9, 10), (5, 6), (6, 7), (6, 8), (7, 8), (8, 10), (10, 1)]
        vertices = list(range(1,11))
        vertex_config = {}
        for i in vertices:
            vertex_config[i] = {'radius': 0.2, 'color': WHITE}
        edge_config = {}
        for i in edges:
            edge_config[i] = {'stroke_width': 3, 'tip_length': 0.2, 'color': WHITE}
        labels = {}
        labels_text = "abcdefghij"
        for i in vertices:
            labels[i] = Tex(r''+labels_text[i-1], color=BLACK)
        G = Graph(vertices, edges, layout="circular", vertex_config=vertex_config, edge_config=edge_config, edge_type=Arrow, labels = labels)
        self.play(Create(G))

Additional media files

Images/GIFs

bugreport_ManimCE_v0 15 2

https://user-images.githubusercontent.com/5823408/174984342-1fbc91c4-5f1d-4f95-afa8-23dccc8f24f7.mp4

Logs

Terminal output
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR

System specifications

System Details
  • OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): Mac OS 12
  • RAM: 8GB
  • Python version (python/py/python3 --version): 3.10
  • Installed modules (provide output from pip list):
PASTE HERE
LaTeX details
  • LaTeX distribution (e.g. TeX Live 2020): TeX Live 2021
  • Installed LaTeX packages:
FFMPEG

Output of ffmpeg -version:

PASTE HERE

Additional comments

drdebmath avatar Jun 22 '22 08:06 drdebmath

This is a problem with how the graph is updated so that if vertices are moved, the endpoints of the edges move too -- if you do not care about moving vertices, you can run G.clear_updaters() before creating the graph, that should help.

behackl avatar Jun 22 '22 09:06 behackl

Thank you @behackl for the solution, it works. But I don't understand where the vertices have moved during the construction of the graph.

drdebmath avatar Jun 22 '22 09:06 drdebmath

Is it perhaps that the vertices are added at the center as usual when running Create(G) while add(G) directly adds it at the desired position, and thus resulting in a discrepancy in the endpoint location for the edges?

drdebmath avatar Jun 22 '22 09:06 drdebmath

They did not move: the Graph has an updater function attached which ensures that the endpoints of the edges match the vertices. This function is not called when you render a static image, but when rendering a video, the function is called at the end of every rendered frame.

behackl avatar Jun 22 '22 09:06 behackl

Thank you @noamzaks for the fix. I didn't expect it to be just a function call difference. But it seems like there are issues with the tests related to the 3D view of the vertices. Have you figured out any solution?

drdebmath avatar Jul 01 '22 15:07 drdebmath

Hi. Sorry, not yet. I'll try again today. I tried to create the supposed npz result and compare the framed, but without success

noamzaks avatar Jul 01 '22 15:07 noamzaks

Hey, small update; I found out some "workaround", but if you need this for something right now, you can try to use my WIP fix and make sure it looks good in your case

noamzaks avatar Jul 02 '22 21:07 noamzaks

Thank you. But I have already finished my presentation with a static graph, so not in any immediate need. I will wait for the next release.

drdebmath avatar Jul 02 '22 21:07 drdebmath