Skip to content

Commit

Permalink
graph_scene: correct placement of labels (3b1b#661)
Browse files Browse the repository at this point in the history
* graph_scene: correct placement of labels

* Update test reference data

* Add test for axes and their labels

* black

* removing commented lines for generation of reference data

Co-authored-by: Leo Torres <[email protected]>

* black

* do not shift labels onto screen

if user wants the label above the y axis, it should go there, even if there is not enough space. they can still choose another placement

* updated test and reference data for test_axes

Co-authored-by: Leo Torres <[email protected]>
  • Loading branch information
PhilippImhof and leotrs authored Nov 3, 2020
1 parent d668fc1 commit e2759ad
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 1 addition & 3 deletions manim/scene/graph_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,10 @@ def setup_axes(self, animate=False):
if self.x_axis_label:
x_label = Tex(self.x_axis_label)
x_label.next_to(
x_axis.get_tips() if self.include_tip else x_axis.get_tick_marks(),
x_axis.get_corner(self.x_label_position),
self.x_label_position,
buff=SMALL_BUFF,
)
x_label.shift_onto_screen()
x_axis.add(x_label)
self.x_axis_label_mob = x_label

Expand Down Expand Up @@ -164,7 +163,6 @@ def setup_axes(self, animate=False):
self.y_label_position,
buff=SMALL_BUFF,
)
y_label.shift_onto_screen()
y_axis.add(y_label)
self.y_axis_label_mob = y_label

Expand Down
Binary file not shown.
Binary file modified tests/control_data/graphical_units_data/graph/PlotFunctions.npz
Binary file not shown.
42 changes: 42 additions & 0 deletions tests/test_graphical_units/test_axes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest

from manim import *
from ..utils.testing_utils import get_scenes_to_test
from ..utils.GraphicalUnitTester import GraphicalUnitTester


class AxesTest(GraphScene):
CONFIG = {
"x_min": -5,
"x_max": 5,
"y_min": -3,
"y_max": 3,
"x_axis_config": {
"add_start": 0.5,
"add_end": 0.5,
"include_tip": True,
},
"y_axis_config": {
"add_start": 0.25,
"add_end": 0.5,
"include_tip": True,
},
"x_axis_visibility": True,
"y_axis_visibility": True,
"y_label_position": UP,
"x_label_position": RIGHT,
"graph_origin": ORIGIN,
"axes_color": WHITE,
}

def construct(self):
self.setup_axes(animate=True)


MODULE_NAME = "graph"


@pytest.mark.slow
@pytest.mark.parametrize("scene_to_test", get_scenes_to_test(__name__), indirect=False)
def test_scene(scene_to_test, tmpdir, show_diff):
GraphicalUnitTester(scene_to_test[1], MODULE_NAME, tmpdir).test(show_diff=show_diff)

0 comments on commit e2759ad

Please sign in to comment.