Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Display Issue with Custom Axis Labels When renderer=opengl #3211

Merged
merged 1 commit into from Apr 25, 2023

Conversation

JinchuLi2002
Copy link
Contributor

@JinchuLi2002 JinchuLi2002 commented Apr 10, 2023

Closes #3069

Overview: What does this pull request change?

Fixes the issue causing axis labels being rendered incorrectly when renderer=opengl.

Typically when custom labels are applied (ex. LogScaling), NumberLine creates the labels by calling label_constructor with label_tex if label_tex is not a VMobject instance.

Issues arise when label_tex is of instance OpenGLVMobject. Since label_constructor is class MathTex by default which is supposed to take str as arguments, OpenGLMobject.__str__ is consequently called and passed into label_constructor.

Further Information and Comments

Example: Logarithmic Scaling

Test code
from manim import *
class LogScalingExample(Scene):
    def construct(self):
        ax = Axes(
            x_range=[0, 10, 1],
            y_range=[-2, 6, 1],
            tips=False,
            axis_config={"include_numbers": True},
            y_axis_config={"scaling": LogBase(custom_labels=True)},
        )

        # x_min must be > 0 because log is undefined at 0.
        graph = ax.plot(lambda x: x ** 2, x_range=[0.001, 10], use_smoothing=False)
        self.add(ax, graph)

with tempconfig({"quality": "high_quality", "preview": True, "renderer": "opengl"}):
    scene = LogScalingExample()
    scene.render()
Before Screen Shot 2023-04-09 at 8 00 34 PM
After Screen Shot 2023-04-09 at 8 00 56 PM

Example: Change Axis Label

Test code
from manim import *
class GetAxisLabelsExample(Scene):
    def construct(self):
        ax = Axes()
        labels = ax.get_axis_labels(
            Tex("x-axis").scale(0.7), Text("y-axis").scale(0.45)
        )
        self.add(ax, labels)

with tempconfig({"quality": "high_quality", "preview": True, "renderer": "opengl"}):
    scene = GetAxisLabelsExample()
    scene.render()
Before Screen Shot 2023-04-09 at 7 59 15 PM
After Screen Shot 2023-04-09 at 7 58 23 PM

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

Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@behackl behackl merged commit 4059bc1 into ManimCommunity:main Apr 25, 2023
20 checks passed
@behackl behackl added pr:bugfix Bug fix for use in PRs solving a specific issue:bug opengl Concerning the OpenGL renderer. labels Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
opengl Concerning the OpenGL renderer. pr:bugfix Bug fix for use in PRs solving a specific issue:bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong log axis labels when rendering with OpenGl
2 participants