Skip to content
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

feat(barchart) set custom text value in the bar #309

Merged
merged 1 commit into from
Jul 14, 2023

Conversation

karthago1
Copy link
Contributor

Hello again 😸

somehow I missed this feature, while integrating the new code. (In my original PR #288, I had a function pointer, which formats the values. format: fn(u64) -> String).

This patch suggests adding a new function text_value to the Bar, which will override the default text value

Bar::default()
     .label("Temperature".into())
     .value(10)
     .text_value("10°C".to_string());

Commit message:

for now the value is converted to a string and then printed. in many cases the values are too wide or double values. so it make sense to set a custom value text instead of the default behavior.

this patch suggests to add a method fn text_value(mut self, text_value: String) to the Bar, which allows to override the value printed in the bar

bar

@codecov
Copy link

codecov bot commented Jul 13, 2023

Codecov Report

Merging #309 (7d0acaa) into main (2889c7d) will decrease coverage by 0.05%.
The diff coverage is 100.00%.

❗ Current head 7d0acaa differs from pull request most recent head 0e82d47. Consider uploading reports for the commit 0e82d47 to get more accurate results

@@            Coverage Diff             @@
##             main     #309      +/-   ##
==========================================
- Coverage   83.85%   83.81%   -0.05%     
==========================================
  Files          38       38              
  Lines        8045     8036       -9     
==========================================
- Hits         6746     6735      -11     
- Misses       1299     1301       +2     
Impacted Files Coverage Δ
src/widgets/barchart/bar.rs 100.00% <100.00%> (ø)
src/widgets/barchart/mod.rs 89.35% <100.00%> (-0.02%) ⬇️

... and 1 file with indirect coverage changes

@joshka
Copy link
Member

joshka commented Jul 14, 2023

@karthago1 to make it easier to merge in the future, can you please enable signing commits?
See https://docs.github.com/articles/about-gpg/ for more info

for now the value is converted to a string and then printed. in many
cases the values are too wide or double values. so it make sense
to set a custom value text instead of the default behavior.

this patch suggests to add a method
"fn text_value(mut self, text_value: String)"
to the Bar, which allows to override the value printed in the bar

Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
@joshka joshka added this pull request to the merge queue Jul 14, 2023
@joshka
Copy link
Member

joshka commented Jul 14, 2023

LGTM. Thanks again!

Merged via the queue into ratatui-org:main with commit 60150f6 Jul 14, 2023
1 check passed
@karthago1 karthago1 deleted the hich/barchart branch July 14, 2023 04:58
a-kenji pushed a commit to a-kenji/ratatui that referenced this pull request Jul 16, 2023
for now the value is converted to a string and then printed. in many
cases the values are too wide or double values. so it make sense
to set a custom value text instead of the default behavior.

this patch suggests to add a method
"fn text_value(mut self, text_value: String)"
to the Bar, which allows to override the value printed in the bar

Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
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.

None yet

3 participants