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: f64The Y value at which the threshold line is drawn.
color: AnsiColorThe ANSI color used to render the threshold line.
Defaults to AnsiColor::DEFAULT (no color).
character: charThe character used to draw the threshold line.
Defaults to ╌ (DEFAULT_CHAR_SET.dash_horizontal).
series_index: usizeThe 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
impl Threshold
Sourcepub fn new(value: f64) -> Self
pub fn new(value: f64) -> Self
Creates a threshold line at the given Y value using the default dashed character and no color.
Sourcepub fn with_color(value: f64, color: AnsiColor) -> Self
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.
Sourcepub fn with_char_and_color(
value: f64,
character: char,
color: AnsiColor,
) -> Self
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.