Skip to content

Commit dd74b00

Browse files
Enhancement: Remove redundancy in FunctionGraph arguments (#1018)
* Fix x_min, x_max and color of FunctionGraph * Add graphical unit test to FunctionGraph * Apply review suggestions * Pass color as argument instead of updating kwargs and run black
1 parent 3ad385a commit dd74b00

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

manim/mobject/functions.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,21 @@ def generate_points(self):
119119

120120

121121
class FunctionGraph(ParametricFunction):
122-
def __init__(self, function, color=YELLOW, **kwargs):
123-
self.x_min = -config["frame_x_radius"]
124-
self.x_max = config["frame_x_radius"]
122+
def __init__(self, function, x_min=None, x_max=None, color=YELLOW, **kwargs):
123+
if x_min is None:
124+
x_min = -config["frame_x_radius"]
125+
if x_max is None:
126+
x_max = config["frame_x_radius"]
127+
self.x_min = x_min
128+
self.x_max = x_max
125129
self.parametric_function = lambda t: np.array([t, function(t), 0])
126130
ParametricFunction.__init__(
127-
self, self.parametric_function, t_min=self.x_min, t_max=self.x_max, **kwargs
131+
self,
132+
self.parametric_function,
133+
t_min=self.x_min,
134+
t_max=self.x_max,
135+
color=color,
136+
**kwargs
128137
)
129138
self.function = function
130139

Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
import numpy as np
3+
4+
from manim import *
5+
from ..utils.testing_utils import get_scenes_to_test
6+
from ..utils.GraphicalUnitTester import GraphicalUnitTester
7+
8+
9+
class FunctionGraphTest(Scene):
10+
def construct(self):
11+
graph = FunctionGraph(
12+
lambda x: 2 * np.cos(0.5 * x), x_min=-PI, x_max=PI, color=BLUE
13+
)
14+
self.add(graph)
15+
self.wait()
16+
17+
18+
MODULE_NAME = "functions"
19+
20+
21+
@pytest.mark.parametrize("scene_to_test", get_scenes_to_test(__name__), indirect=False)
22+
def test_scene(scene_to_test, tmpdir, show_diff):
23+
GraphicalUnitTester(scene_to_test[1], MODULE_NAME, tmpdir).test(show_diff=show_diff)

0 commit comments

Comments
 (0)