ratatui: Barchart doesn't render labels in entire width
Description
The barchart widget doesn’t render labels that are the full width (this affects both non-unicode and unicode)
To Reproduce
fn render_simple_barchart(area: Rect, buf: &mut Buffer) {
let data = [
("Sat", 76),
("Sun", 69),
("Mon", 65),
("Tue", 67),
("Wed", 65),
("Thu", 69),
("Fri", 73),
];
let data = data
.into_iter()
.map(|(label, value)| {
Bar::default()
.value(value)
// cannot use this until the column width bug is fixed
.text_value(format!("{}°", value))
.label(label.into())
})
.collect_vec();
let group = BarGroup::default().bars(&data);
BarChart::default()
.data(group)
.bar_width(3)
.bar_gap(1)
.render(area, buf);
}
with the following line removed:
.text_value(format!("{}°", value))
And the same occurs replacing that with
.text_value(format!("{}x", value))
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
- Is this expected behavior for some historical reason?
- If this is expected, how should it be documented?
- What significance should unicode play here (e.g. the degree symbol has string len = 2 and unicode width = 1)? Is #75 relevant to the degree symbol?
- What is the history of this? Check for any guidance from commits, and comments on PRs/ issues in Ratatui and tui-rs.
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 19 (11 by maintainers)
Commits related to this issue
- feat(barchart): allow to render charts smaller than 3 lines Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whethe... — committed to karthago1/ratatui by karthago1 9 months ago
- feat(barchart): allow to render charts smaller than 3 lines Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whethe... — committed to karthago1/ratatui by karthago1 9 months ago
- feat(barchart): allow to render charts smaller than 3 lines Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whethe... — committed to karthago1/ratatui by karthago1 9 months ago
- feat(barchart): allow to render charts smaller than 3 lines Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whethe... — committed to karthago1/ratatui by karthago1 9 months ago
- feat(barchart): allow to render charts smaller than 3 lines Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whethe... — committed to karthago1/ratatui by karthago1 9 months ago
- feat(barchart): allow to render charts smaller than 3 lines Add an internal structure `LabelInfo`, which stores the reserved height for the labels (0, 1 or 2) and also the state of the labels, whethe... — committed to karthago1/ratatui by karthago1 9 months ago
- feat(barchart): render charts smaller than 3 lines (#532) 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 struct... — committed to ratatui-org/ratatui by karthago1 9 months ago
- feat(barchart): render charts smaller than 3 lines (#532) 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 struct... — committed to tonogdlp/ratatui by karthago1 9 months ago
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
barchart
widget, not getting any bar chart is an unexpected experience.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.