Kill CONFIG in numbers.py

This commit is contained in:
Grant Sanderson 2022-12-15 20:33:58 -08:00
parent 9039fe69e4
commit 7e46c87fc5

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import numpy as np import numpy as np
from manimlib.constants import DOWN, LEFT, RIGHT, UP from manimlib.constants import DOWN, LEFT, RIGHT, UP
from manimlib.constants import WHITE
from manimlib.mobject.svg.tex_mobject import SingleStringTex from manimlib.mobject.svg.tex_mobject import SingleStringTex
from manimlib.mobject.svg.text_mobject import Text from manimlib.mobject.svg.text_mobject import Text
from manimlib.mobject.types.vectorized_mobject import VMobject from manimlib.mobject.types.vectorized_mobject import VMobject
@ -11,28 +12,51 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Type, TypeVar from typing import Type, TypeVar
from manimlib.constants import ManimColor, np_vector
T = TypeVar("T", bound=VMobject) T = TypeVar("T", bound=VMobject)
class DecimalNumber(VMobject): class DecimalNumber(VMobject):
CONFIG = { CONFIG = {
"stroke_width": 0,
"fill_opacity": 1.0,
"num_decimal_places": 2,
"include_sign": False,
"group_with_commas": True,
"digit_buff_per_font_unit": 0.001,
"show_ellipsis": False,
"unit": None, # Aligned to bottom unless it starts with "^"
"include_background_rectangle": False,
"edge_to_fix": LEFT,
"font_size": 48,
"text_config": {} # Do not pass in font_size here
} }
def __init__(self, number: float | complex = 0, **kwargs): def __init__(
super().__init__(**kwargs) self,
number: float | complex = 0,
color: ManimColor = WHITE,
stroke_width: float = 0,
fill_opacity: float = 1.0,
num_decimal_places: int = 2,
include_sign: bool = False,
group_with_commas: bool = True,
digit_buff_per_font_unit: float = 0.001,
show_ellipsis: bool = False,
unit: str | None = None, # Aligned to bottom unless it starts with "^"
include_background_rectangle: bool = False,
edge_to_fix: np_vector = LEFT,
font_size: int = 48,
text_config: dict = dict(), # Do not pass in font_size here
**kwargs
):
self.num_decimal_places = num_decimal_places
self.include_sign = include_sign
self.group_with_commas = group_with_commas
self.digit_buff_per_font_unit = digit_buff_per_font_unit
self.show_ellipsis = show_ellipsis
self.unit = unit
self.include_background_rectangle = include_background_rectangle
self.edge_to_fix = edge_to_fix
self.font_size = font_size
self.text_config = text_config
super().__init__(
color=color,
stroke_width=stroke_width,
fill_opacity=fill_opacity,
**kwargs
)
self.set_submobjects_from_number(number) self.set_submobjects_from_number(number)
self.init_colors() self.init_colors()
@ -94,7 +118,7 @@ class DecimalNumber(VMobject):
super().init_data() super().init_data()
self.data["font_size"] = np.array([self.font_size], dtype=float) self.data["font_size"] = np.array([self.font_size], dtype=float)
def get_font_size(self) -> float: def get_font_size(self) -> int:
return int(self.data["font_size"][0]) return int(self.data["font_size"][0])
def get_formatter(self, **kwargs) -> str: def get_formatter(self, **kwargs) -> str:
@ -156,9 +180,13 @@ class DecimalNumber(VMobject):
class Integer(DecimalNumber): class Integer(DecimalNumber):
CONFIG = { def __init__(
"num_decimal_places": 0, self,
} number: int = 0,
num_decimal_places: int = 0,
**kwargs,
):
super().__init__(number, num_decimal_places=num_decimal_places, **kwargs)
def get_value(self) -> int: def get_value(self) -> int:
return int(np.round(super().get_value())) return int(np.round(super().get_value()))