pub struct BarChart<Msg> { /* private fields */ }Expand description
Bars measured in eighths of a cell, with labels and values.
Horizontal by default: one row per bar, labels on the left, values on the right. Vertical
charts stand bars side by side with the value above and the label below each. Bars scale to
the largest value unless a maximum is given. On narrow areas horizontal charts drop their
labels first; vertical bars get thinner and labels are cut with …. ASCII mode fills whole
cells.
A chart of Series shows several values per category: side by side by default, or as
segments of one bar with stacked. Series take their tones from the theme,
walking a ramp from the accent towards the faint end so neighbouring shares read apart
without a second accent colour; a horizontal segment writes its series name inside itself
when the name fits, so a stack is not read by colour alone.
The chart answers the pointer and the keyboard once it is given
on_select: the hovered and the selected category rise on a raised ground,
a horizontal chart marks the selected row with the accent pillar in its own lead cell, and the
arrow keys along the bars’ axis (↑/↓ or k/j horizontally, ←/→ or h/l vertically) with Home and
End move the selection. Nothing moves or resizes when a category is hovered or selected: a
chart is not a list, so it never slides.
Style keys: bar-chart and bar-chart.<variant> (fill), bar-chart-bar with hover,
selected and focus (bg, pillar), bar-chart-label (fg), bar-chart-value and
bar-chart-value.<variant> (fg, bold). Series take the theme’s series-<n> colour
tokens when it has them.
Implementations§
Source§impl<Msg> BarChart<Msg>
impl<Msg> BarChart<Msg>
Sourcepub fn new(bars: impl IntoIterator<Item = Bar>) -> Self
pub fn new(bars: impl IntoIterator<Item = Bar>) -> Self
A horizontal chart of bars.
Sourcepub fn series(
labels: impl IntoIterator<Item = impl Into<String>>,
series: impl IntoIterator<Item = Series>,
) -> Self
pub fn series( labels: impl IntoIterator<Item = impl Into<String>>, series: impl IntoIterator<Item = Series>, ) -> Self
A chart of the categories labels with one value per category in every series of
series.
The series of a category stand next to each other; stacked puts them in
one bar instead. A chart of a single series looks exactly like a chart of plain bars.
Sourcepub fn stacked(self) -> Self
pub fn stacked(self) -> Self
Draws the series as segments of one bar per category instead of bars next to each other.
Sourcepub fn max(self, max: f32) -> Self
pub fn max(self, max: f32) -> Self
The value of a full bar, e.g. 100.0 for percentages; the largest value by default. A
stacked chart scales to the largest category total instead.
Sourcepub fn gap(self, cells: u16) -> Self
pub fn gap(self, cells: u16) -> Self
Empty rows (horizontal) or columns (vertical) between bars; 1 by default, so neighbouring bars never merge into one block. Vertical charts keep at least one column. The bars of one category stand right next to each other, so a group reads as one shape.
Sourcepub fn unit(self, unit: impl Into<String>) -> Self
pub fn unit(self, unit: impl Into<String>) -> Self
Unit written after every value the chart itself formats, e.g. "h" for hours. A bar with
its own value_text keeps that text as it is.
Sourcepub fn selected(self, category: Option<usize>) -> Self
pub fn selected(self, category: Option<usize>) -> Self
The selected category, which rises on a raised ground.
Trait Implementations§
Source§impl<Msg: 'static> Widget<Msg> for BarChart<Msg>
impl<Msg: 'static> Widget<Msg> for BarChart<Msg>
Source§fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size
fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size
available.Source§fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
true when the event was used; unused key and scroll events
bubble to the parent widget.Source§fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)
fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)
PaintCx::request_overlay. anchor is the area the widget was painted in.Source§fn children_mut(&mut self) -> &mut [Node<Msg>]
fn children_mut(&mut self) -> &mut [Node<Msg>]
Auto Trait Implementations§
impl<Msg> !RefUnwindSafe for BarChart<Msg>
impl<Msg> !Send for BarChart<Msg>
impl<Msg> !Sync for BarChart<Msg>
impl<Msg> !UnwindSafe for BarChart<Msg>
impl<Msg> Freeze for BarChart<Msg>
impl<Msg> Unpin for BarChart<Msg>
impl<Msg> UnsafeUnpin for BarChart<Msg>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more