Skip to main content

Threshold

Struct Threshold 

Source
pub struct Threshold {
    pub value: f64,
    pub color: AnsiColor,
    pub character: char,
    pub series_index: usize,
}
Expand description

A horizontal reference line drawn at a user-specified Y value, associated with a specific data series.

Threshold lines are rendered as dashed lines () across the data area at the given value, making limits, targets, or alert boundaries immediately visible on the graph. Multiple thresholds can be added to a single graph by calling [Config::threshold()] repeatedly.

Each threshold is associated with a series via series_index, which defaults to 0 (the first series). Two rules are applied before a threshold is drawn:

Visibility rule — the threshold value must fall within the min/max range of its associated series specifically, not just the global graph range. This means a threshold at Y = 80.0 associated with a series whose values only reach 40.0 will be silently skipped, even if another series on the same graph reaches 90.0.

Color inheritance rule — when no explicit color is set on the threshold (i.e. color is AnsiColor::DEFAULT), the threshold automatically inherits the color of its associated series from Config::series_colors. An explicitly set color always takes priority.

Series arc characters always render on top of threshold lines.

§Example

use asciigraph::{plot_many, Config, Threshold, AnsiColor};

let s1 = vec![60.0, 75.0, 85.0, 92.0, 78.0, 65.0];
let s2 = vec![10.0, 18.0, 25.0, 35.0, 28.0, 15.0];

let graph = plot_many(
    &[&s1, &s2],
    Config::default()
        .series_colors(&[AnsiColor::BLUE, AnsiColor::GREEN])
        // Targets series 0 — inherits BLUE from series_colors.
        .threshold(Threshold::new(80.0))
        // Targets series 1 — overrides the inherited color.
        .threshold(Threshold {
            series_index: 1,
            ..Threshold::with_color(30.0, AnsiColor::RED)
        }),
);
println!("{}", graph);

Fields§

§value: f64

The Y value at which the threshold line is drawn.

§color: AnsiColor

The ANSI color used to render the threshold line. Defaults to AnsiColor::DEFAULT (no color).

§character: char

The character used to draw the threshold line. Defaults to (DEFAULT_CHAR_SET.dash_horizontal).

§series_index: usize

The index of the series this threshold is associated with.

The threshold is only rendered if its value falls within the min/max range of the series at this index. If the index is out of range or the threshold value falls outside the series range, the threshold is silently skipped. When no explicit color is set, the color of the associated series is inherited automatically.

Defaults to 0, which associates the threshold with the first series.

Implementations§

Source§

impl Threshold

Source

pub fn new(value: f64) -> Self

Creates a threshold line at the given Y value using the default dashed character and no color.

Source

pub fn with_color(value: f64, color: AnsiColor) -> Self

Creates a threshold line at the given Y value rendered in a specific ANSI color. Uses the default dashed character.

Source

pub fn with_char_and_color( value: f64, character: char, color: AnsiColor, ) -> Self

Creates a threshold line at the given Y value with both a custom character and a custom ANSI color.

Trait Implementations§

Source§

impl Clone for Threshold

Source§

fn clone(&self) -> Threshold

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 Copy for Threshold

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.