Skip to content

Improvements and Bugfixes for value formatting#128

Open
TarEnethil wants to merge 5 commits intomkaz:mainfrom
TarEnethil:fix-no-readable
Open

Improvements and Bugfixes for value formatting#128
TarEnethil wants to merge 5 commits intomkaz:mainfrom
TarEnethil:fix-no-readable

Conversation

@TarEnethil
Copy link

This PR got a bit larger than expected, sorry!

Originally, I kept searching for the reason why --no-readable was not working. I tracked this down to #120, where the code was (accidentally) removed. Before fixing the issue itself however, I tried to consistently use format_value across all chart types. After fixing the issue, I wrote some unit tests to ensure the handling of formatting arguments will stay consistent in the future. Through testing I found another bug for custom ticks with VerticalCharts and fixed that up as well.

In summary, this PR

  • uses format_value consistently across all chart types (I cannot guarantee that some existing parameter combinations now lead to a different output than before)
  • fixes the --no-readable argument by preventing cvt_to_readable() from being called if the option is set
  • adds new unit tests to test the formatting arguments
  • adds support for custom_ticks in VerticalCharts

The changes are in separate commits and described in their respective commit messages, so you can pick and choose which changes you like.

Please let me know what you think!

* use format_value across all chart types
* format_value now takes the full args object instead of individual
  parameters.
* format_value evaluates the args format, percentage, suffix and no_values
* cvt_to_readable is no longer responsible for percentage conversion
* suffix is no longer appended when no_values is True

Signed-off-by: Thorben Roemer <thorbenroemer@t-online.de>
Support for the --no-readable argument was (accidentally?) removed in
41adfd4 Additional refactoring and consolidation (mkaz#120).

With the refactored version of format_value, this is now an easy fix.
Only call cvt_to_readable if no_readable is False (as it was before). It
now also works for all chart types.

Fixes 41adfd4

Signed-off-by: Thorben Roemer <thorbenroemer@t-online.de>
Since Args self-initializes with a default, I see no reason to do
excessive type checking.

Signed-off-by: Thorben Roemer <thorbenroemer@t-online.de>
Add tests that ensure formatting options are working as expected (and so
that future refactorings don't break things again).

A new helper function run_for_all_charts() is introduced. Histograms are
optional, as their value/formatting works a bit differently.

Signed-off-by: Thorben Roemer <thorbenroemer@t-online.de>
When changing test_custom_tick_appears_in_output() to use the new
run_for_all_tests() function, I discovered that VerticalChart had no
support for custom ticks.

After a little refactoring (tick is now a member of Chart and only
initialized once), all Charts now support custom ticks.

Signed-off-by: Thorben Roemer <thorbenroemer@t-online.de>
@TarEnethil TarEnethil changed the title Improvments and Bugfixes for value formatting Improvements and Bugfixes for value formatting Feb 26, 2026
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.

1 participant