Skip to content

Conversation

@Rudransh24
Copy link

@Rudransh24 Rudransh24 commented Aug 31, 2021

Overview: What does this pull request change?

As mentioned in #1423 this PR adds the option of displaying background rectangle in the coordinate_label function in the Vector class. This is done by adding a parameter in the function call.

Motivation and Explanation: Why and how do your changes improve the library?

In some discussions and PR #1407 it was mentioned how this small enhancement is required in order to give the user an option to be able to display background rectangle or not.

Links to added or changed documentation pages

Earlier, when Vector.coordinate_label was called, it did not have a parameter for showing background color of the coordinate labels. I have added a parameter to the coordinate_label function which enables user to provide a background color to the coordinates

Old:

class A(Scene):
    def construct(self):
        vect = Vector([1, 2])
        label = vect.coordinate_label()
        self.add(vect, label)

Screenshot (253)

New:

class VectorCoordinateLabel(Scene):
    def construct(self):
        plane = NumberPlane()

        vect_1 = Vector([1, 2])
        vect_2 = Vector([-3, -2])
        label_1 = vect_1.coordinate_label(show_bg_rec=True)
        label_2 = vect_2.coordinate_label(color=YELLOW)

        self.add(plane, vect_1, vect_2, label_1, label_2)

Screenshot (248)

Further Information and Comments

This is my first PR in an open source project (outside of Hacktober Fest). Open to suggestions and modifications.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Copy link
Collaborator

@icedcoffeeee icedcoffeeee left a comment

Choose a reason for hiding this comment

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

I glossed over your PR and left some comments

shift_dir -= label.get_right() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * RIGHT
label.shift(shift_dir)
label.set_color(color)
if show_bg_rec:
Copy link
Collaborator

@icedcoffeeee icedcoffeeee Aug 31, 2021

Choose a reason for hiding this comment

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

This part is redundant no? Passing add_background_rectangles_to_entries in Matrix already does these.
Cancel that, why don't you pass include_background_rectangle to Matrix instead of add_background_rectangles_to_entries and adding a BackgroundRectangle separately?

Copy link
Author

Choose a reason for hiding this comment

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

Oh yes, that sounds better actually. Thanks!
I have made the change in the function.

show_bg_rec
Display background rectangle for a number.
Examples
Copy link
Collaborator

Choose a reason for hiding this comment

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

The example for the method isn't showing up, as shown here. Could you fix that? The indentation of the manim code block isn't quite right.

Copy link
Author

Choose a reason for hiding this comment

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

I didn't quite get this one. I saw the page and yes the example is missing. But upon checking the indentation in the function docstring and committing, I couldn't pinpoint the exact issue that could be causing the missing example. I tried crosschecking with the other examples present in the script as well. Will try investigating a bit more.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah sorry, I misjudged, the problem was at the .. manim keyword at the start of the example, it needs a double colon

Copy link
Author

Choose a reason for hiding this comment

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

Oh yes, found it. There was some build issue too due to wrong variable name in the example. Fixed both. Am able to see the example in the link now.

@huguesdevimeux
Copy link
Member

thanks for the PR !

Could you :

  • Put images examples of what your changes do,
  • Add tests.

Thanks !

@Rudransh24
Copy link
Author

thanks for the PR !

Could you :

  • Put images examples of what your changes do,
  • Add tests.

Thanks !

Hello @huguesdevimeux
I have added example and tests. Could you please review it?
Thanks!

@huguesdevimeux huguesdevimeux self-requested a review September 5, 2021 13:40
Copy link
Collaborator

@icedcoffeeee icedcoffeeee left a comment

Choose a reason for hiding this comment

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

I don't think that colored background rectangles is a desired result.

at line 1623, you can make small change:

if show_bg_rect:
    label[1:].set_color(color)
else:
    label.set_color(color)

@Rudransh24
Copy link
Author

Rudransh24 commented Sep 6, 2021

I don't think that colored background rectangles is a desired result.

at line 1623, you can make small change:

if show_bg_rec:
    label[1:].set_color(color)
else:
    label.set_color(color)

Hello @icedcoffeeee
I made the change but I am still little confused what this is achieving as this does not change anything. Do we only need background color on the digits(which I did in the first commit) or the whole coordinate(which I am doing right now)?

@icedcoffeeee
Copy link
Collaborator

which I did in the first commit

Technically, your first commit did bring the desired result. My suggestion of changes was just a mere simplification 😅

@Rudransh24
Copy link
Author

which I did in the first commit

Technically, your first commit did bring the desired result. My suggestion of changes was just a mere simplification 😅

Cancel that, why don't you pass include_background_rectangle to Matrix instead of add_background_rectangles_to_entries and adding a BackgroundRectangle separately?

After some observation I found out that there wasn't any need of BackgroundRectangle Function and a separate if-else condition, I think only passing a parameter show_bg_rec = True and add_background_rectangles_to_entries = show_bg_rec would give us the desired output which is displaying background on the entries of the coordinates.

label = Matrix(vect, add_background_rectangles_to_entries=show_bg_rec)
This line gives me the desired output!
Any thoughts?

@icedcoffeeee
Copy link
Collaborator

label = Matrix(vect, add_background_rectangles_to_entries=show_bg_rec)
This line gives me the desired output!

I don't think so, it still gives a colored background rect under each element.

Plus, personally when i pass show_bg_rec, i'd expect a background rect of the whole matrix rather than just the entries. But it might be different for everyone, we might need another's opinion.

@Rudransh24
Copy link
Author

label = Matrix(vect, add_background_rectangles_to_entries=show_bg_rec)
This line gives me the desired output!

I don't think so, it still gives a colored background rect under each element.

Plus, personally when i pass show_bg_rec, i'd expect a background rect of the whole matrix rather than just the entries. But it might be different for everyone, we might need another's opinion.

Ok, so we actually need 2 different parameters one for the entries' background only, and one for the whole matrix.

@Rudransh24
Copy link
Author

@huguesdevimeux @icedcoffeeee @behackl @hydrobeam any opinions?

@icedcoffeeee
Copy link
Collaborator

Hi sorry for the delay. I think a good method to customize the matrix would be to let users pass any keyword args as **kwargs instead. The coloring issue is best fixed from within the Matrix constructor. Currently, there isn't a way to specify a color to the matrix init. Could you make that possible?

@behackl
Copy link
Member

behackl commented Mar 24, 2022

Superseded by #2138.

@behackl behackl closed this Mar 24, 2022
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.

Allow background rectangles to be added in Vector.coordinate_label

4 participants