Skip to main content

StatAnnotations

Struct StatAnnotations 

Source
pub struct StatAnnotations {
    pub show_min: bool,
    pub show_max: bool,
    pub show_mean: bool,
    pub show_median: bool,
    pub show_std_dev: bool,
    pub color: AnsiColor,
    pub series_index: usize,
}
Expand description

Opt-in statistical annotations rendered as horizontal reference lines at computed values across the data area.

The library computes each statistic from the data automatically — no manual calculation is required. Each annotation is individually controlled by a boolean flag, so you can display any combination of minimum, maximum, mean, median, and standard deviation.

By default, statistics are computed from the first series (series_index = 0). In a multi-series graph, set series_index to the index of the series you want to annotate. If the index is out of range, the function falls back to the first series silently.

Use StatAnnotations::new() to enable all five annotations at once, or set individual flags to false to disable specific ones. All annotations share a single color configured on the struct.

Annotations are rendered before the series, so series arc characters always appear on top where they overlap.

§Example

use asciigraph::{plot, Config, StatAnnotations, AnsiColor};

let data = vec![3.0, 1.0, 4.0, 1.0, 5.0, 9.0, 2.0, 6.0];

// Enable all annotations with no color.
let graph = plot(&data, Config::default().stat_annotations(StatAnnotations::new()));

// Enable only min and max in red.
let graph = plot(
    &data,
    Config::default().stat_annotations(StatAnnotations {
        show_min:     true,
        show_max:     true,
        show_mean:    false,
        show_median:  false,
        show_std_dev: false,
        series_index: 0,
        color:        AnsiColor::RED,
    }),
);

// Annotate the second series in a multi-series graph.
let graph = plot(
    &data,
    Config::default().stat_annotations(StatAnnotations {
        series_index: 1,
        ..StatAnnotations::new()
    }),
);

Fields§

§show_min: bool

Draws a reference line at the minimum value of the dataset.

§show_max: bool

Draws a reference line at the maximum value of the dataset.

§show_mean: bool

Draws a reference line at the mean (average) value of the dataset.

§show_median: bool

Draws a reference line at the median value of the dataset.

§show_std_dev: bool

Draws a reference line at one standard deviation above and below the mean, giving a visual indication of the data’s spread.

§color: AnsiColor

The ANSI color used to render all annotation lines. Defaults to AnsiColor::DEFAULT (no color).

§series_index: usize

The index of the series to compute statistics from.

In a single-series graph this is always 0. In a multi-series graph, set this to the index of the series you want to annotate. If the index is out of range, the function falls back to the first series silently.

Use struct update syntax to set this field without changing anything else:

use asciigraph::StatAnnotations;

let annotations = StatAnnotations {
    series_index: 1,
    ..StatAnnotations::new()
};

Implementations§

Source§

impl StatAnnotations

Source

pub fn new() -> Self

Creates a StatAnnotations value with all five annotations enabled, no color, and targeting the first series (series_index = 0).

Source

pub fn with_color(color: AnsiColor) -> Self

Creates a StatAnnotations value with all five annotations enabled, rendered in a specific ANSI color, and targeting the first series.

For multi-series graphs, override series_index with struct update syntax:

use asciigraph::{StatAnnotations, AnsiColor};

let annotations = StatAnnotations {
    series_index: 1,
    ..StatAnnotations::with_color(AnsiColor::YELLOW)
};

Trait Implementations§

Source§

impl Clone for StatAnnotations

Source§

fn clone(&self) -> StatAnnotations

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for StatAnnotations

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for StatAnnotations

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