-
Notifications
You must be signed in to change notification settings - Fork 255
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
Barchart doesn't render labels in entire width #513
Comments
I looked into the history for this a little bit. tui-rs has used This PR in ratatui seems to have changed it from See LHS: and RHS: You'll have to expand the diff to see the lines. Because of the refactor, the side by side diff doesn't show the change; and maybe that's why this change wasn't discussed in more detail. There are a lot of comments on the PR but I don't think I see comments in the PR related to this particular change. Maybe @karthago1 can comment on the change? I haven't tried using I do think in general we could start to use |
No need to apologize! Pinged you to check if you had a good reason for the change! For context, here's a test I just ran ( // main.rs
use unicode_width::UnicodeWidthStr;
use unicode_segmentation::UnicodeSegmentation;
fn main() {
let s = "abc";
dbg!(s);
dbg!(s.len());
dbg!(s.width());
dbg!(s.graphemes(true).count());
println!("");
let s = "写作业";
dbg!(s);
dbg!(s.len());
dbg!(s.width());
dbg!(s.graphemes(true).count());
println!("");
let s = "🤦🏼♂️";
dbg!(s);
dbg!(s.len());
dbg!(s.width());
dbg!(s.graphemes(true).count());
} $ rustc main.rs && ./main
[src/main.rs:6] s = "abc"
[src/main.rs:7] s.len() = 3
[src/main.rs:8] s.width() = 3
[src/main.rs:9] s.graphemes(true).count() = 3
[src/main.rs:14] s = "写作业"
[src/main.rs:15] s.len() = 9
[src/main.rs:16] s.width() = 6
[src/main.rs:17] s.graphemes(true).count() = 3
[src/main.rs:22] s = "🤦🏼♂️"
[src/main.rs:23] s.len() = 17
[src/main.rs:24] s.width() = 5
[src/main.rs:25] s.graphemes(true).count() = 1 |
Ok, that explains the unicode bit - changing back to .width() is reasonable because it's always been that way (even if it handles emoji oddly - that's to fix elsewhere) Is there an answer to why |
That is unclear, and without pinging |
One user friendIy approach to emoji is to specifically display them as 2 chars everywhere, but I think let's worry about exactly how unicode should be displayed in #75 and leave the concerns for this on whether it does.
Got it - I think based on this use case (of showing text labels the full width of a bar it's reasonable then to make this <= given there's no explanation of <. |
I'm good with |
Somehow I went all this time without realizing emojis are 2 width wide! |
I just realized, that I didn't introduce this behavior 😸 .
The only thing I can think of, to be able to distinguish small values. example:
now you will see
I don't know what is better, the first or second chart? (in this specific case maybe the first chart looks better) do we still want #515 (of course after fixing the unit tests), or maybe we should close it, if the original behavior is fine?
why? because |
to answer my self. 😸 (I just realized that unicodes are 2 character wide 🥲 ) except for emojis but I reverted the comparison back to
becomes
I will think of a solution in another PR. something similar to: if the bar contains only one character height and value text width is equal bar width, then we shouldn't print the value |
My bad, did that PR I linked above not introduce this? Maybe I read the diffs incorrectly? Do you happen to know where it was introduced?
I think this makes sense. |
There are two "bugs"
This is a really good example for working out what to show:
I think we can probably agree that for that scenario, we can't show the values at all (except perhaps 8).
Or should it be:
Or:
|
I actually think this is what I'd prefer:
and I'd prefer this if there's lesser room:
And this with a height of just 1:
My reasoning is that if someone is using the |
That does look nicer. So there's probably a few ways to choose where exactly to display the labels... which means there's probably some complexity in the implementation for this. |
I will try to help solving the following 2 cases: and
but for the following case maybe I will ignore it for the time being, because the numbers are reserving some space, which would be available for the bars currently
|
Please consider adding each of those as tests (rendering that data into 1,2,3 height), as they're good characterization tests to have if we decide to make it possible to set the label position. |
Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whether they will be shown or not. Add internal property to the Bar `transformed_value`, which is used only for in the vertical charts. This value is needed in 2 reasons: 1. to draw the bar itseld 2. to draw the bar value or text_value. If the transformed_value is below 8 and the bar_width is 1, then the value will not be printed transformed_value is line height multiplied by 8. (8 is the number of element of symbols::bar::Set struct) fixes ratatui-org#513 Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whether they will be shown or not. Add internal property to the Bar `transformed_value`, which is used only for in the vertical charts. This value is needed in 2 reasons: 1. to draw the vertical bar 2. to draw the bar value or text_value. If the transformed_value is below 8 and the bar_width is 1, then the value will not be printed transformed_value is line height multiplied by 8. (8 is the number of element of symbols::bar::Set struct) fixes ratatui-org#513 Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whether they will be shown or not. Add internal property to the Bar `transformed_value`, which is used only for in the vertical charts. This value is needed in 2 reasons: 1. to draw the vertical bar 2. to draw the bar value or text_value. If the transformed_value is below 8 and the bar_width is 1, then the value will not be printed transformed_value is line height multiplied by 8. (8 is the number of element of symbols::bar::Set struct) fixes ratatui-org#513 Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whether they will be shown or not. Add internal property to the Bar `transformed_value`, which is used only for in the vertical charts. This value is needed in 2 reasons: 1. to draw the vertical bar 2. to draw the bar value or text_value. If the transformed_value is below 8 and the bar_width is 1, then the value will not be printed transformed_value is line height multiplied by 8. (8 is the number of element of symbols::bar::Set struct) fixes ratatui-org#513 Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whether they will be shown or not. The bar values are not shown, if the value width is equal the bar width and the bar is height is less than one line fixes ratatui-org#513 Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whether they will be shown or not. The bar values are not shown, if the value width is equal the bar width and the bar is height is less than one line fixes ratatui-org#513 Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
The bar values are not shown if the value width is equal the bar width and the bar is height is less than one line Add an internal structure `LabelInfo` which stores the reserved height for the labels (0, 1 or 2) and also whether the labels will be shown. Fixes #513 Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
The bar values are not shown if the value width is equal the bar width and the bar is height is less than one line Add an internal structure `LabelInfo` which stores the reserved height for the labels (0, 1 or 2) and also whether the labels will be shown. Fixes ratatui-org#513 Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
Description
The barchart widget doesn't render labels that are the full width (this affects both non-unicode and unicode)
To Reproduce
with the following line removed:
And the same occurs replacing that with
Expected behavior
I think this should probably render like the following (hacking a couple of things in the barchart implementation to make it work):
Environment
Mac/iterm/FiraCode(NF)/main/crossterm
Additional context
The text was updated successfully, but these errors were encountered: