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: boolDraws a reference line at the minimum value of the dataset.
show_max: boolDraws a reference line at the maximum value of the dataset.
show_mean: boolDraws a reference line at the mean (average) value of the dataset.
show_median: boolDraws a reference line at the median value of the dataset.
show_std_dev: boolDraws a reference line at one standard deviation above and below the mean, giving a visual indication of the data’s spread.
color: AnsiColorThe ANSI color used to render all annotation lines.
Defaults to AnsiColor::DEFAULT (no color).
series_index: usizeThe 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
impl StatAnnotations
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a StatAnnotations value with all five annotations enabled,
no color, and targeting the first series (series_index = 0).
Sourcepub fn with_color(color: AnsiColor) -> Self
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
impl Clone for StatAnnotations
Source§fn clone(&self) -> StatAnnotations
fn clone(&self) -> StatAnnotations
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more