Skip to main content

BarChart

Struct BarChart 

Source
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>

Source

pub fn new(bars: impl IntoIterator<Item = Bar>) -> Self

A horizontal chart of bars.

Source

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.

Source

pub fn stacked(self) -> Self

Draws the series as segments of one bar per category instead of bars next to each other.

Source

pub fn vertical(self) -> Self

Stands the bars up side by side.

Source

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.

Source

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.

Source

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.

Source

pub fn selected(self, category: Option<usize>) -> Self

The selected category, which rises on a raised ground.

Source

pub fn disabled(self, disabled: bool) -> Self

Greys the chart out: it cannot be focused, hovered or selected.

Source

pub fn on_select(self, message: impl Fn(usize) -> Msg + 'static) -> Self

Message for moving the selection to a category, which turns the chart’s pointer and keyboard handling on.

Trait Implementations§

Source§

impl<Msg: 'static> Widget<Msg> for BarChart<Msg>

Source§

fn measure(&self, _cx: &mut MeasureCx<'_>, available: Size) -> Size

The size the widget wants when it may use up to available.
Source§

fn paint(&self, cx: &mut PaintCx<'_>, area: Rect)

Draws the widget into area.
Source§

fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool

Handles input. Returns true when the event was used; unused key and scroll events bubble to the parent widget.
Source§

fn focusable(&self) -> bool

Whether the widget can take keyboard focus.
Source§

fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)

Draws the widget’s overlay after the whole view was painted, when it asked for one with PaintCx::request_overlay. anchor is the area the widget was painted in.
Source§

fn children(&self) -> &[Node<Msg>]

Child nodes, for widgets that contain other widgets.
Source§

fn children_mut(&mut self) -> &mut [Node<Msg>]

Mutable child nodes, used to assign ids.

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>
where Option<Box<dyn Fn(usize) -> Msg>>: Freeze,

§

impl<Msg> Unpin for BarChart<Msg>
where Option<Box<dyn Fn(usize) -> Msg>>: Unpin,

§

impl<Msg> UnsafeUnpin for BarChart<Msg>
where Option<Box<dyn Fn(usize) -> Msg>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.