Skip to content

Fix DisplayProgressBar min_value offset in fill calculation#990

Open
matthewgjohnson wants to merge 1 commit intomathoudebine:mainfrom
matthewgjohnson:fix/progressbar-min-value
Open

Fix DisplayProgressBar min_value offset in fill calculation#990
matthewgjohnson wants to merge 1 commit intomathoudebine:mainfrom
matthewgjohnson:fix/progressbar-min-value

Conversation

@matthewgjohnson
Copy link
Copy Markdown

Fixes #954.

DisplayProgressBar calculated the filled width/height from the raw value rather than the value's offset from min_value:

# Before
bar_filled_width = (value / (max_value - min_value) * width) - 1

# After
bar_filled_width = ((value - min_value) / (max_value - min_value) * width) - 1

When min_value is 0 (the default), this has no effect — which is why the bug went unnoticed. For any bar with a non-zero minimum (e.g. a temperature bar with min=25, max=95), the fill is wrong:

value min max buggy fill correct fill
25 25 95 36% 0%
60 25 95 86% 50%
95 25 95 136% 100%

DisplayRadialProgressBar already uses the correct form ((value - min_value) / (max_value - min_value)).

Both the horizontal (bar_filled_width) and vertical (bar_filled_height) branches had the same bug — both are fixed in this PR.

DisplayProgressBar calculated bar_filled_width/height from the raw
value rather than the value's offset from min_value. When min_value
was 0 (the default), this had no effect — which is why the bug went
unnoticed — but any bar with a non-zero minimum rendered the fill
incorrectly.

DisplayRadialProgressBar already uses the correct form
(value - min_value) / (max_value - min_value).

Fixes mathoudebine#954
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.

DisplayProgressBar: min_value ignored in fill width calculation

1 participant