-
Notifications
You must be signed in to change notification settings - Fork 2.5k
enhance: Add background rectangle in Vector.coordinate_label based on keyword arg #1988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
19bfb90
7d3fb1f
9cd6b06
f161ac5
41d6d5b
972e6e1
2766eac
5603358
9ea5b46
598b8d0
4a75aa0
798aaee
dedb7ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1569,6 +1569,7 @@ def coordinate_label( | |
| integer_labels: bool = True, | ||
| n_dim: int = 2, | ||
| color: str = WHITE, | ||
| show_bg_rec: bool = False, | ||
| ): | ||
| """Creates a label based on the coordinates of the vector. | ||
|
|
||
|
|
@@ -1580,11 +1581,13 @@ def coordinate_label( | |
| The number of dimensions of the vector. | ||
| color | ||
| The color of the label. | ||
| show_bg_rec | ||
| Display background rectangle for a number. | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
||
| .. manim VectorCoordinateLabel | ||
| .. manim:: VectorCoordinateLabel | ||
| :save_last_frame: | ||
|
|
||
| class VectorCoordinateLabel(Scene): | ||
|
|
@@ -1593,12 +1596,13 @@ def construct(self): | |
|
|
||
| vect_1 = Vector([1, 2]) | ||
| vect_2 = Vector([-3, -2]) | ||
| label_1 = vect1.coordinate_label() | ||
| label_2 = vect2.coordinate_label(color=YELLOW) | ||
| 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) | ||
| """ | ||
| # avoiding circular imports | ||
| from ..mobject.shape_matchers import BackgroundRectangle | ||
| from .matrix import Matrix | ||
|
|
||
| vect = np.array(self.get_end()) | ||
|
|
@@ -1607,7 +1611,7 @@ def construct(self): | |
| vect = vect[:n_dim] | ||
| vect = vect.reshape((n_dim, 1)) | ||
|
|
||
| label = Matrix(vect) | ||
| label = Matrix(vect, include_background_rectangle=show_bg_rec) | ||
| label.scale(LARGE_BUFF - 0.2) | ||
|
|
||
| shift_dir = np.array(self.get_end()) | ||
|
|
@@ -1616,7 +1620,10 @@ def construct(self): | |
| else: # Pointing left | ||
| shift_dir -= label.get_right() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * RIGHT | ||
| label.shift(shift_dir) | ||
| label.set_color(color) | ||
| if show_bg_rec: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yes, that sounds better actually. Thanks! |
||
| label[1:].set_color(color) | ||
| else: | ||
| label.set_color(color) | ||
| return label | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.. manimkeyword at the start of the example, it needs a double colonThere was a problem hiding this comment.
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.