Skip to content

Text Mobject does not recursively propagation to submodules key kwargs arguments #4667

@Marius-Juston

Description

@Marius-Juston

Description of bug / unexpected behavior

Some kwargs parameters for Text do not get propagated to it's children in construction, making it so that things like z_order does not work as intended and only the top level Text object has the proper z_order but the actual letters do not have the z_order that is properly set. This is also true with the opacity parameter.

The issue was found in following Discord help-forum thread https://discord.com/channels/1453870851807117363/1485929006254657557

Expected behavior

def construct(self):
  self.play(FadeIn(Dot(ORIGIN, radius=0.2, color=BLUE, z_index=1)), FadeIn(Text("A", font_size=18, color=WHITE, weight=BOLD, z_index=3)))

We should always be able to see the label; however, as you can see the label goes behind the dot. As such this is because the z_order is not being applied.

So there's a class of mobjects which should probably propagate their style to their submobjects, but there are also classes which shouldn't (Axes comes to mind).

How to reproduce the issue

Code for reproducing the problem

The problems:

def construct(self):
  self.play(FadeIn(Dot(ORIGIN, radius=0.2, color=BLUE, z_index=1)), FadeIn(Text("A", font_size=18, color=WHITE, weight=BOLD, z_index=3)))

Seems like setting z index in the constructor doesn't work, but setting it explicitly with a method does:

def construct(self):
    dot = Dot(ORIGIN, radius=0.2, color=BLUE).set_z_index(1)
    label = Text("A", font_size=18, color=WHITE, weight=BOLD).set_z_index(3)
    self.play(FadeIn(dot), FadeIn(label))
    self.wait()

If I had to guess, it might be because setting z index in the constructor doesn't set it recursively, and so the submobjects of the Text object may not have their z index updated at creation?
(and since the circle has z index 1, it is rendered above the text submobjects which probably have z index 0)

providing z_index in the kwargs of a mobject constructor only affects the top-level mobject. When we explicitly make the label one layer deep, it works:

def construct(self):
    dot = Dot(ORIGIN, radius=0.5, color=BLUE, z_index=1)
    label = Text("A", font_size=36, fill_color=WHITE, weight=BOLD, z_index=3)
    label.set_points(label[0].points).remove(label[0]) # flatten
    self.play(FadeIn(dot), FadeIn(label))
    self.wait()

there was a similar bug for setting opacity from the kwargs

def construct(self):
  self.play(FadeIn(Text("A", font_size=18, color=WHITE, weight=BOLD, opacity=0)))

Which can get fixed by doing it in the following manner:

def construct(self):
  self.play(FadeIn(Text("A", font_size=18, color=WHITE, weight=BOLD).set_opacity(0)))

Additional media files

Images/GIFs
scriptoutput.mp4

System specifications

System Details
  • OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): Discord Manim renderer any OS
  • Python version (python/py/python3 --version): Unknown for Discord Manim renderer
  • Installed modules (provide output from pip list): Unknown for Discord Manim renderer

Additional comments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions