-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fixed :meth:BarChart.change_bar_values
not updating when height is 0
#2638
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
Conversation
The function is _create_bar.
Create temporary bar, replace the previous location in the self.bars vgroup with the new bar. Then re-initalize the colours depending on a flag. Also refactor out colour-setting to a method
BarChart.change_bar_values
didn't updateBarChart.change_bar_values
didn't update when the chart value is 0.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
BarChart.change_bar_values
didn't update when the chart value is 0.BarChart.change_bar_values
didn't update when the chart value is 0.
BarChart.change_bar_values
didn't update when the chart value is 0.BarChart.change_bar_values
not updating when height is 0.
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.
Cool! Thanks for the fix!
Left a suggestion and a potential design change and whether you think that would be a good idea.
from manim import *
class Foo(Scene):
def construct(self):
values=[0 for _ in range(11)]+[1,1,1]
chart = BarChart(
values,
y_range=[0, 10, 1],
y_axis_config={"font_size": 24},
)
new_values=[i for i in range(11)] + [-2,-3,-4]
self.add(chart)
self.play(chart.animate.change_bar_values(new_values)) Just a different flavor of test. |
The function is _create_bar.
Create temporary bar, replace the previous location in the self.bars vgroup with the new bar. Then re-initalize the colours depending on a flag. Also refactor out colour-setting to a method
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Removed setting self.bars in `BarChart._add_bars`
- Also, fix setting config.frame_width in __init__, since this causes BarChart's `y_length` to not be re-evaluated if the dimensions of the scene are changed.
- Also update params where `len` is taken to be a Sequence, not iterable
for more information, see https://pre-commit.ci
- MutableSequence instead of Sequence for self.values, since BarChart.change_bar_values adjusts the value of the sequence, requiring __get_item__. - Use try/except based on reviewer's reccomendation.
for more information, see https://pre-commit.ci
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.
Implemented most of the suggested changes, with some minor type/doc adjustments and a deprecation.
I also deprecated passing in a string to bar_colors
(unfortunately rather manually, since our deprecated
module doesn't support this type of deprecation {tried quite a bit to make deprecated_params
work})
Please review requested changes! |
Everything adressed but github doesn't check correctly
BarChart.change_bar_values
not updating when height is 0.BarChart.change_bar_values
not updating when height is 0
Overview: What does this pull request change?
Closes #2636
change_bar_values
is zero (caught during a try/except), then a new bar is created and replaces its position in theself.bars
VGroup
self.insert
methods toMobject
andOpenGLMobject
to accomodate this.BarChart._create_bar
for use inBarChart._add_bars
andchange_bar_values
self._update_colors
since if new bars are created, then their colour won't match the rest of the bar chart, so the colours will be re-initalized.Before:

After:

Motivation and Explanation: Why and how do your changes improve the library?
Links to added or changed documentation pages
Further Information and Comments
Currently missing proper tests. Also, there might be value in having a singular
change_bar_value
.Reviewer Checklist