Add big_tick_spacing option NumberLine

This commit is contained in:
Grant Sanderson 2024-02-22 11:45:31 -08:00
parent 4a89376fdd
commit e784c42f0d

View file

@ -16,7 +16,7 @@ from manimlib.utils.simple_functions import fdiv
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Iterable from typing import Iterable, Optional
from manimlib.typing import ManimColor, Vect3, Vect3Array, VectN, RangeSpecifier from manimlib.typing import ManimColor, Vect3, Vect3Array, VectN, RangeSpecifier
@ -28,12 +28,13 @@ class NumberLine(Line):
stroke_width: float = 2.0, stroke_width: float = 2.0,
# How big is one one unit of this number line in terms of absolute spacial distance # How big is one one unit of this number line in terms of absolute spacial distance
unit_size: float = 1.0, unit_size: float = 1.0,
width: float | None = None, width: Optional[float] = None,
include_ticks: bool = True, include_ticks: bool = True,
tick_size: float = 0.1, tick_size: float = 0.1,
longer_tick_multiple: float = 1.5, longer_tick_multiple: float = 1.5,
tick_offset: float = 0.0, tick_offset: float = 0.0,
# Change name # Change name
big_tick_spacing: Optional[float] = None,
numbers_with_elongated_ticks: list[float] = [], numbers_with_elongated_ticks: list[float] = [],
include_numbers: bool = False, include_numbers: bool = False,
line_to_number_direction: Vect3 = DOWN, line_to_number_direction: Vect3 = DOWN,
@ -54,7 +55,14 @@ class NumberLine(Line):
self.tick_size = tick_size self.tick_size = tick_size
self.longer_tick_multiple = longer_tick_multiple self.longer_tick_multiple = longer_tick_multiple
self.tick_offset = tick_offset self.tick_offset = tick_offset
self.numbers_with_elongated_ticks = list(numbers_with_elongated_ticks) if big_tick_spacing is not None:
self.numbers_with_elongated_ticks = np.arange(
x_range[0],
x_range[1] + big_tick_spacing,
big_tick_spacing,
)
else:
self.numbers_with_elongated_ticks = list(numbers_with_elongated_ticks)
self.line_to_number_direction = line_to_number_direction self.line_to_number_direction = line_to_number_direction
self.line_to_number_buff = line_to_number_buff self.line_to_number_buff = line_to_number_buff
self.include_tip = include_tip self.include_tip = include_tip