Skip to content

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

Merged
merged 27 commits into from
Jul 9, 2022

Conversation

hydrobeam
Copy link
Member

@hydrobeam hydrobeam commented Mar 27, 2022

Overview: What does this pull request change?

Closes #2636

  • Made it so that if the previous value of a bar chart is zero during change_bar_values is zero (caught during a try/except), then a new bar is created and replaces its position in the self.bars VGroup
  • Added self.insert methods to Mobject and OpenGLMobject to accomodate this.
  • Refactored out bar creation into BarChart._create_bar for use in BarChart._add_bars and change_bar_values
  • Added 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.
class Foo(Scene):
    def construct(self):
        values=[0 for _ in range(11)]

        chart = BarChart(
            values,
            y_range=[0, 10, 1],
            y_axis_config={"font_size": 24},
        )
        new_values=[1 for _ in range(11)]
        chart.change_bar_values(new_values)
        self.add(chart)

Before:
Foo_ManimCE_v0 14 0

After:
Foo_ManimCE_v0 14 0

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

  • 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

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
@hydrobeam hydrobeam changed the title Fix bug where BarChart.change_bar_values didn't update Fix bug where BarChart.change_bar_values didn't update when the chart value is 0. Mar 27, 2022
@hydrobeam hydrobeam changed the title Fix bug where BarChart.change_bar_values didn't update when the chart value is 0. Fix bug where :meth:BarChart.change_bar_values didn't update when the chart value is 0. Mar 27, 2022
@hydrobeam hydrobeam changed the title Fix bug where :meth:BarChart.change_bar_values didn't update when the chart value is 0. Fix :meth:BarChart.change_bar_values not updating when height is 0. Mar 27, 2022
@hydrobeam hydrobeam added the pr:bugfix Bug fix for use in PRs solving a specific issue:bug label Mar 27, 2022
Copy link
Collaborator

@ad-chaos ad-chaos left a 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.

@MrDiver
Copy link
Collaborator

MrDiver commented Jun 12, 2022

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.

hydrobeam and others added 15 commits June 12, 2022 17:33
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
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
- 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.
Copy link
Member Author

@hydrobeam hydrobeam left a 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})

@MrDiver
Copy link
Collaborator

MrDiver commented Jun 18, 2022

Please review requested changes!

@MrDiver MrDiver marked this pull request as draft June 18, 2022 20:27
@MrDiver MrDiver marked this pull request as ready for review July 9, 2022 13:33
@MrDiver MrDiver self-requested a review July 9, 2022 13:34
@MrDiver MrDiver enabled auto-merge (squash) July 9, 2022 13:39
@MrDiver MrDiver requested review from ad-chaos and removed request for ad-chaos July 9, 2022 13:58
@MrDiver MrDiver dismissed ad-chaos’s stale review July 9, 2022 14:28

Everything adressed but github doesn't check correctly

@MrDiver MrDiver merged commit 4cb43a2 into ManimCommunity:main Jul 9, 2022
@behackl behackl added this to the v0.16.0 milestone Jul 10, 2022
@behackl behackl changed the title Fix :meth:BarChart.change_bar_values not updating when height is 0. Fixed :meth:BarChart.change_bar_values not updating when height is 0 Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:bugfix Bug fix for use in PRs solving a specific issue:bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

BarChart bars of height 0 do not get updated as expected.
4 participants