Skip to content

Conversation

ksachdeva
Copy link
Contributor

@ksachdeva ksachdeva commented Feb 27, 2021

Motivation

Adding the documentation & examples for number_line module

Overview / Explanation for Changes

  • added the apis
  • added the examples showing various ways NumberLine can be used

Oneline Summary of Changes

- API docs & examples for number_line module (:pr:`1064`)

Testing Status

Locally verified the generated document

Further Comments

Have not documented init_leftmost_tick as it should be considered a private method

Acknowledgements

Reviewer Checklist

  • Newly added functions/classes are either private or have a docstring
  • Newly added functions/classes have tests added and (optional) examples in the docs
  • Newly added documentation builds, looks correctly formatted, and adds no additional build warnings
  • The oneline summary has been included in the wiki

Copy link
Member

@jsonvillanueva jsonvillanueva left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Wonderful example image illustrating the usage!

ksachdeva and others added 2 commits February 28, 2021 08:51
tick_frequency=1,
color: Colors = LIGHT_GREY,
unit_size: int = 1,
width: float = None,
Copy link
Member

Choose a reason for hiding this comment

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

use typing.Optional

x_max=config["frame_x_radius"],
numbers_with_elongated_ticks: typing.List[float] = [0],
include_numbers: bool = False,
numbers_to_show: typing.List[float] = None,
Copy link
Member

Choose a reason for hiding this comment

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

use typing.Optional

tip_height: float = 0.25,
add_start: float = 0, # extend number line by this amount at its starting point
add_end: float = 0, # extend number line by this amount at its end point
decimal_number_config: dict = {"num_decimal_places": 0},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
decimal_number_config: dict = {"num_decimal_places": 0},
decimal_number_config: typing.Dict[str,int] = {"num_decimal_places": 0},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, it is not appropriate in this context because decimal_number_config is essentially the kwargs for DecimalNumber class and the values for the dictionary entries passed could other types.

Maybe Any instead of int is appropriate.

That said, I think this is too confusing and somewhere stems from the overuse of passing 'dictionaries' in manim.

The correct way should be to define a dataclass and then pass it around. ... nevertheless whatever we do writing scalable and maintainable code in python is always going to be tricky in this project or any other project.

Given all this ambiguity, my humble suggestion is to leave it at dict, and when (and if) you refactor the manim code to use proper types (instead of dictionaries) then the types would help otherwise this does not bring any value.

x_min: float = -config["frame_x_radius"],
x_max: float = config["frame_x_radius"],
**kwargs
):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
):
) -> None:

self.tick_frequency, np.ceil(self.x_min / self.tick_frequency)
)

def add_tick_marks(self):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def add_tick_marks(self):
def add_tick_marks(self) -> None:

)

def get_tick(self, x, size=None):
def get_tick(self, x: float, size: float = None) -> Line:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def get_tick(self, x: float, size: float = None) -> Line:
def get_tick(self, x: float, size: typing.Optional[float] = None) -> Line:

Comment on lines +356 to +359
number_config: dict = None,
scale_val: float = None,
direction: np.ndarray = None,
buff: float = None,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
number_config: dict = None,
scale_val: float = None,
direction: np.ndarray = None,
buff: float = None,
number_config: typing.Optional[dict] = None,
scale_val: typing.Optional[float] = None,
direction: typing.Optional[np.ndarray] = None,
buff: typing.Optional[float] = None,

tick_frequency: float = 0.1,
numbers_with_elongated_ticks: typing.List[float] = [0, 1],
number_at_center: float = 0.5,
decimal_number_config: dict = {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
decimal_number_config: dict = {
decimal_number_config: typing.Dict[sstr,int] = {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think u have a typo here and I am not sure it is correct typing annotation in the first place. See above comment.

@ksachdeva
Copy link
Contributor Author

@naveen521kk I do not see the value in adding Optional typing where the None is specified (as it is obvious that argument is optional). I think it is overkill to do so and comes in the way of readability.

I am not going to add the typings that you are recommending for the reason mentioned above.

That said, I do respect the conventions and policies of a given project so if you want to archive/delete this pull request I am okay with it. Or if you want to merge it as it is and then do the necessary modifications as a follow-up as you see fit.

Thanks
Kapil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants