Skip to main content

Histogram

Struct Histogram 

Source
pub struct Histogram { /* private fields */ }
Expand description

Histogram widget.

§Example

use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
use tui_chart::{Histogram};

let chart = Histogram::new((0..100).map(|i| ((i * 37) % 23) as f64));
let area = Rect::new(0, 0, 40, 12);
let mut buf = Buffer::empty(area);
chart.render(area, &mut buf);

Implementations§

Source§

impl Histogram

Source

pub fn new(data: impl IntoIterator<Item = f64>) -> Self

Create from samples (non-finite values are ignored).

Source

pub fn bins(self, n: usize) -> Self

Fixed bin count (default: Sturges’ rule).

Source

pub fn range(self, min: f64, max: f64) -> Self

Fixed sample range.

Source

pub fn color(self, v: Color) -> Self

Bar color.

Source

pub fn kde(self, v: bool) -> Self

Overlay a Gaussian kernel density estimate curve on the bars (vertical, non-cumulative histograms only; ignored otherwise). The curve is scaled to the bar units (counts, or density when normalized).

Source

pub fn stats(self, v: bool) -> Self

Mark the mean (μ) and median (med) with labelled vertical lines (vertical, non-cumulative histograms only).

Source

pub fn kde_bandwidth(self, v: f64) -> Self

KDE bandwidth (default: Silverman’s rule). Implies nothing unless Histogram::kde is on.

Source

pub fn gradient(self, v: Gradient) -> Self

Color bars by height using a gradient (instead of one flat color).

Source

pub fn theme(self, theme: impl Into<Theme>) -> Self

Apply a Theme (accent bar color, axes, background). An explicit Histogram::color wins.

Source

pub fn base_style(self, style: Style) -> Self

Base style painted over the whole area (beats the theme).

Source

pub fn orientation(self, v: BarOrientation) -> Self

Bar direction.

Source

pub fn show_values(self, v: bool) -> Self

Print counts.

Source

pub fn cumulative(self, v: bool) -> Self

Cumulative mode: each bar shows the running total up to and including its bin.

Source

pub fn normalized(self, v: bool) -> Self

Normalized mode: bars show probability density (area = 1); combined with cumulative the last bar reaches 1.

Source

pub fn bar_marker(self, v: Marker) -> Self

Draw the bars with dot glyphs (see BarChart::marker). Default: eighth blocks.

Source

pub fn marker(self, v: Marker) -> Self

Glyph family of the KDE curve (default Marker::Braille).

Source

pub fn block(self, b: Block<'static>) -> Self

Wrap the chart in a Block.

Source

pub fn value_axis(self, a: Axis) -> Self

Count axis.

Source

pub fn compute_bins(&self) -> Vec<Bin>

Compute the bins.

Source

pub fn heights(&self) -> Vec<f64>

Bar heights per bin, honouring the cumulative / normalized modes.

Source

pub fn kde_curve( &self, points: usize, bandwidth: Option<f64>, ) -> Vec<(f64, f64)>

Gaussian kernel density estimate sampled at points evenly spaced x values across the bin range, as (x, density) pairs ready for a Series. bandwidth of None uses Silverman’s rule. Scale by n * bin_width to overlay on a count histogram.

Trait Implementations§

Source§

impl Clone for Histogram

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Histogram

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Themed for Histogram

Available on crate feature theme only.
Source§

fn apply_theme(self, theme: &Theme) -> Self

Return self styled from theme. Explicit per-item colors set on the widget should keep winning over the theme.
Source§

fn themed(self, provider: &impl ThemeProvider) -> Self

Apply the theme produced by any ThemeProvider.
Source§

impl Widget for &Histogram

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

impl Widget for Histogram

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§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<W> FxExt for W
where W: Widget,

Source§

fn glow(self, radius: u16, strength: f64) -> Fx<Self>

Wrap in an Fx with a glow of radius cells and strength.
Source§

fn scanlines(self, strength: f64) -> Fx<Self>

Wrap in an Fx with scanlines of strength.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.