Skip to content

Conversation

@sparshg
Copy link
Contributor

@sparshg sparshg commented Jan 23, 2023

Overview: What does this pull request change?

Set z_index of graph edges to default value

Explanation:

vertices = [1, 2, 3, 4]
edges = [(1, 2), (2, 3), (3, 4), (1, 3), (1, 4)]
g = Graph(vertices, edges)
self.add(g)
self.play(
    LaggedStart(
        *(
            ShowPassingFlash(i.copy().set_stroke(width=10))
            for i in g.edges.values()
        ),
        lag_ratio=0.02,
    )
)

I implemented two changes, both solve this problem independently.

Before

AlphaScene.mp4

After

AlphaScene.mp4

Change 1

I tried to run the above code, but it showed nothing, like self.wait(). Trying to debug, I discovered that this broke in 69666f7 in #2594. The graph edges were set to be static mobjects inside begin_animations() in scene.py. I reverted the change, and shifted the piece of code which adds anim mobjects to scene animation._setup_scene(self) after the static and moving mobjects were detected, (because current animations will only have moving objects?). This worked. I think change 2 below is better but I still included this.

Change 2

But then why were static/moving mobjects not detected properly? I found that get_moving_mobjects() in scene.py goes through all mobjects, sorted by z_index. As soon as there's one that needs updating of some kind per frame, return the list from that point forward. The problem is that by default objects (means including Group) have z_index=0 but graph edges set z_index=-1. That means my mobjects list is something like, [Line, Line, ... Line, Group, other_mobs] (sorted by z_index) where Line are edges and Group is introduced by LaggedStart. So everything including and after Group is set to moving as it is in animation_mobjects, but not the lines of course. So they don't update.

To fix this, I removed z_index=-1 from graph edges config and added z_index=1 in vertex config.

Links to added or changed documentation pages

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

1 participant