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
impl Histogram
Sourcepub fn new(data: impl IntoIterator<Item = f64>) -> Self
pub fn new(data: impl IntoIterator<Item = f64>) -> Self
Create from samples (non-finite values are ignored).
Sourcepub fn kde(self, v: bool) -> Self
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).
Sourcepub fn stats(self, v: bool) -> Self
pub fn stats(self, v: bool) -> Self
Mark the mean (μ) and median (med) with labelled vertical lines
(vertical, non-cumulative histograms only).
Sourcepub fn kde_bandwidth(self, v: f64) -> Self
pub fn kde_bandwidth(self, v: f64) -> Self
KDE bandwidth (default: Silverman’s rule). Implies nothing unless
Histogram::kde is on.
Sourcepub fn gradient(self, v: Gradient) -> Self
pub fn gradient(self, v: Gradient) -> Self
Color bars by height using a gradient (instead of one flat color).
Sourcepub fn theme(self, theme: impl Into<Theme>) -> Self
pub fn theme(self, theme: impl Into<Theme>) -> Self
Apply a Theme (accent bar color, axes, background). An explicit
Histogram::color wins.
Sourcepub fn base_style(self, style: Style) -> Self
pub fn base_style(self, style: Style) -> Self
Base style painted over the whole area (beats the theme).
Sourcepub fn orientation(self, v: BarOrientation) -> Self
pub fn orientation(self, v: BarOrientation) -> Self
Bar direction.
Sourcepub fn show_values(self, v: bool) -> Self
pub fn show_values(self, v: bool) -> Self
Print counts.
Sourcepub fn cumulative(self, v: bool) -> Self
pub fn cumulative(self, v: bool) -> Self
Cumulative mode: each bar shows the running total up to and including its bin.
Sourcepub fn normalized(self, v: bool) -> Self
pub fn normalized(self, v: bool) -> Self
Normalized mode: bars show probability density (area = 1); combined with
cumulative the last bar reaches 1.
Sourcepub fn bar_marker(self, v: Marker) -> Self
pub fn bar_marker(self, v: Marker) -> Self
Draw the bars with dot glyphs (see BarChart::marker). Default:
eighth blocks.
Sourcepub fn marker(self, v: Marker) -> Self
pub fn marker(self, v: Marker) -> Self
Glyph family of the KDE curve (default Marker::Braille).
Sourcepub fn value_axis(self, a: Axis) -> Self
pub fn value_axis(self, a: Axis) -> Self
Count axis.
Sourcepub fn compute_bins(&self) -> Vec<Bin>
pub fn compute_bins(&self) -> Vec<Bin>
Compute the bins.
Sourcepub fn heights(&self) -> Vec<f64>
pub fn heights(&self) -> Vec<f64>
Bar heights per bin, honouring the cumulative / normalized modes.
Sourcepub fn kde_curve(
&self,
points: usize,
bandwidth: Option<f64>,
) -> Vec<(f64, f64)>
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 Themed for Histogram
Available on crate feature theme only.
impl Themed for Histogram
theme only.Source§fn apply_theme(self, theme: &Theme) -> Self
fn apply_theme(self, theme: &Theme) -> Self
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
fn themed(self, provider: &impl ThemeProvider) -> Self
ThemeProvider.Auto Trait Implementations§
impl !RefUnwindSafe for Histogram
impl !UnwindSafe for Histogram
impl Forget for Histogram
impl Freeze for Histogram
impl Send for Histogram
impl Sync for Histogram
impl Unpin for Histogram
impl UnsafeUnpin for Histogram
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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