BarGraph

Struct BarGraph 

Source
pub struct BarGraph<'g> { /* private fields */ }
Expand description

A widget for displaying a bar graph.

The bars can be colored using a gradient, and can be rendered using either solid blocks or braille characters for a more granular appearance.

§Example

use tui_bar_graph::{BarGraph, BarStyle, ColorMode};

let data = vec![0.0, 0.1, 0.2, 0.3, 0.4, 0.5];
let bar_graph = BarGraph::new(data)
    .with_gradient(colorgrad::preset::turbo())
    .with_bar_style(BarStyle::Braille)
    .with_color_mode(ColorMode::VerticalGradient);
frame.render_widget(bar_graph, area);

Implementations§

Source§

impl<'g> BarGraph<'g>

Source

pub fn new(data: Vec<f64>) -> BarGraph<'g>

Creates a new bar graph with the given data.

Source

pub fn with_gradient(self, gradient: impl Gradient + 'g) -> BarGraph<'g>

Sets the gradient to use for coloring the bars.

See the colorgrad crate for information on creating gradients. Note that the default domain (range) of the gradient is [0, 1], so you may need to scale your data to fit this range, or modify the gradient’s domain to fit your data.

Source

pub fn with_max(self, max: impl Into<Option<f64>>) -> BarGraph<'g>

Sets the maximum value to display.

Values greater than this will be clamped to this value. If None, the maximum value is calculated from the data.

Source

pub fn with_min(self, min: impl Into<Option<f64>>) -> BarGraph<'g>

Sets the minimum value to display.

Values less than this will be clamped to this value. If None, the minimum value is calculated from the data.

Source

pub const fn with_color_mode(self, color: ColorMode) -> BarGraph<'g>

Sets the color mode for the bars.

The default is ColorMode::VerticalGradient.

  • Solid: Each bar has a single color based on its value.
  • Gradient: Each bar is gradient-colored from bottom to top.
Source

pub const fn with_bar_style(self, style: BarStyle) -> BarGraph<'g>

Sets the style of the bars.

The default is BarStyle::Braille.

  • Solid: Render bars using the full block character ‘’.
  • Quadrant: Render bars using quadrant block characters for a more granular representation.
  • Octant: Render bars using octant block characters for a more granular representation.
  • Braille: Render bars using braille characters for a more granular representation.

Octant and Braille offer the same level of granularity, but Braille is more widely supported by fonts.

Trait Implementations§

Source§

impl Widget for BarGraph<'_>

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.

Auto Trait Implementations§

§

impl<'g> Freeze for BarGraph<'g>

§

impl<'g> !RefUnwindSafe for BarGraph<'g>

§

impl<'g> !Send for BarGraph<'g>

§

impl<'g> !Sync for BarGraph<'g>

§

impl<'g> Unpin for BarGraph<'g>

§

impl<'g> !UnwindSafe for BarGraph<'g>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.