pub struct Config {Show 24 fields
pub width: usize,
pub height: usize,
pub lower_bound: Option<f64>,
pub upper_bound: Option<f64>,
pub offset: usize,
pub caption: String,
pub precision: Option<usize>,
pub caption_color: AnsiColor,
pub axis_color: AnsiColor,
pub label_color: AnsiColor,
pub series_colors: Vec<AnsiColor>,
pub series_legends: Vec<String>,
pub line_ending: String,
pub series_chars: Vec<CharSet>,
pub x_axis_tick_count: usize,
pub x_axis_range: Option<[f64; 2]>,
pub x_axis_value_formatter: Option<Box<dyn Fn(f64) -> String>>,
pub y_axis_value_formatter: Option<Box<dyn Fn(f64) -> String>>,
pub zero_line: Option<ZeroLine>,
pub thresholds: Vec<Threshold>,
pub moving_average_window: Option<usize>,
pub y_axis_label: Option<String>,
pub x_axis_label: Option<String>,
pub stat_annotations: Option<StatAnnotations>,
}Expand description
Configuration for controlling the appearance and behavior of a graph.
Config uses a builder pattern — start with Config::default() and
chain the methods for the options you want to set. Every method consumes
and returns Self, so calls can be chained fluently.
§Example
use asciigraph::{plot, Config, AnsiColor};
let data = vec![1.0, 2.0, 3.0, 2.0, 1.0];
let graph = plot(
&data,
Config::default()
.height(5)
.caption("My Graph")
.axis_color(AnsiColor::GREEN),
);Fields§
§width: usizeTarget width of the data area in columns. 0 means auto-size to the
number of data points.
height: usizeTarget height of the graph in rows. 0 means auto-size based on the
data range.
lower_bound: Option<f64>Optional lower bound for the Y-axis. Ignored if the data minimum is already below this value.
upper_bound: Option<f64>Optional upper bound for the Y-axis. Ignored if the data maximum is already above this value.
offset: usizeNumber of columns reserved for the Y-axis label area. Defaults to 3.
caption: StringCaption string rendered below the graph body.
precision: Option<usize>Number of decimal places for Y-axis labels. None means auto-detect.
caption_color: AnsiColorANSI color for the caption text.
axis_color: AnsiColorANSI color for axis lines and tick characters.
label_color: AnsiColorANSI color for Y-axis labels.
series_colors: Vec<AnsiColor>Per-series ANSI colors. The first color applies to the first series, the second to the second, and so on.
series_legends: Vec<String>Per-series legend labels rendered below the graph.
line_ending: StringLine ending sequence. Defaults to "\n". Use "\r\n" for Windows
raw terminals.
series_chars: Vec<CharSet>Per-series character sets. Falls back to [DEFAULT_CHAR_SET] for any
series that does not have an explicit entry.
x_axis_tick_count: usizeNumber of tick marks on the X-axis. 0 means auto-calculate.
Minimum when set explicitly is 2.
x_axis_range: Option<[f64; 2]>The [min, max] domain mapped onto the X-axis. Setting this enables
the X-axis.
x_axis_value_formatter: Option<Box<dyn Fn(f64) -> String>>Custom formatter for X-axis tick labels. Accepts any closure of the
form Fn(f64) -> String.
y_axis_value_formatter: Option<Box<dyn Fn(f64) -> String>>Custom formatter for Y-axis labels. Accepts any closure of the form
Fn(f64) -> String.
zero_line: Option<ZeroLine>Optional zero line drawn at Y = 0.0 across the data area.
thresholds: Vec<Threshold>Horizontal reference lines drawn at user-specified Y values.
moving_average_window: Option<usize>Window size for the moving average overlay. None means disabled.
y_axis_label: Option<String>Descriptive label rendered flush left above the graph body.
Set via Config::y_axis_label().
x_axis_label: Option<String>Descriptive label rendered inline on the same row as the X-axis line,
to the right of the tick marks. Only visible when Config::x_axis_range()
is also configured.
stat_annotations: Option<StatAnnotations>Optional statistical annotations rendered as horizontal reference lines
at computed values — minimum, maximum, mean, median, and standard deviation.
Set via Config::stat_annotations().
Implementations§
Source§impl Config
impl Config
Sourcepub fn width(self, w: usize) -> Self
pub fn width(self, w: usize) -> Self
Sets the graph width in columns.
When set to a positive value, the input data is interpolated to produce
exactly this many data columns regardless of how many points were
provided. Pass 0 to auto-size the width to the number of data points.
Sourcepub fn height(self, h: usize) -> Self
pub fn height(self, h: usize) -> Self
Sets the graph height in rows.
Pass 0 to auto-size the height based on the data range, which is the
default behavior.
Sourcepub fn lower_bound(self, min: f64) -> Self
pub fn lower_bound(self, min: f64) -> Self
Sets an optional lower bound for the Y-axis.
This value is only applied if it is lower than the actual data minimum. It will not compress the visible range — it can only expand it downward.
Sourcepub fn upper_bound(self, max: f64) -> Self
pub fn upper_bound(self, max: f64) -> Self
Sets an optional upper bound for the Y-axis.
This value is only applied if it is higher than the actual data maximum. It will not compress the visible range — it can only expand it upward.
Sourcepub fn offset(self, off: usize) -> Self
pub fn offset(self, off: usize) -> Self
Sets the number of columns reserved for the Y-axis label area.
Increase this value if your Y-axis labels are wider than the default
allows. Defaults to 3 when not set.
Sourcepub fn precision(self, p: usize) -> Self
pub fn precision(self, p: usize) -> Self
Sets the number of decimal places used in Y-axis labels.
When not set, the library auto-detects appropriate precision based on the data range — more decimal places for small values, fewer for large ones.
Sourcepub fn caption(self, c: &str) -> Self
pub fn caption(self, c: &str) -> Self
Sets the caption rendered below the graph body.
The caption is centered over the data area. Leading and trailing whitespace is trimmed before rendering.
Sourcepub fn caption_color(self, color: AnsiColor) -> Self
pub fn caption_color(self, color: AnsiColor) -> Self
Sets the ANSI color for the caption text.
Sourcepub fn axis_color(self, color: AnsiColor) -> Self
pub fn axis_color(self, color: AnsiColor) -> Self
Sets the ANSI color for axis lines and tick characters.
Sourcepub fn label_color(self, color: AnsiColor) -> Self
pub fn label_color(self, color: AnsiColor) -> Self
Sets the ANSI color for Y-axis labels.
Sourcepub fn series_colors(self, colors: &[AnsiColor]) -> Self
pub fn series_colors(self, colors: &[AnsiColor]) -> Self
Sets per-series ANSI colors.
The first color applies to the first series, the second to the second, and so on. Series without a corresponding color entry are rendered in the terminal default color.
Sourcepub fn series_legends(self, text: &[&str]) -> Self
pub fn series_legends(self, text: &[&str]) -> Self
Sets per-series legend labels rendered below the graph.
The first label corresponds to the first series, the second to the second, and so on. Labels are rendered alongside a colored square marker matching the series color.
Sourcepub fn line_ending(self, ending: &str) -> Self
pub fn line_ending(self, ending: &str) -> Self
Sets the line-ending sequence used between rows.
Defaults to "\n". Use "\r\n" for Windows raw terminals or any
environment that requires CRLF line endings.
Sourcepub fn series_chars(self, cs: &[CharSet]) -> Self
pub fn series_chars(self, cs: &[CharSet]) -> Self
Sets per-series character sets.
The first CharSet applies to the first series, the second to the
second, and so on. Series without a corresponding entry fall back to
[DEFAULT_CHAR_SET]. Use create_char_set to create a uniform set,
or struct update syntax to override individual characters.
Sourcepub fn x_axis_tick_count(self, count: usize) -> Self
pub fn x_axis_tick_count(self, count: usize) -> Self
Sets the number of tick marks on the X-axis, overriding the automatic calculation.
When this is not called, the library automatically determines a sensible
tick count based on the available graph width and the estimated width of
the tick labels. The minimum accepted value is 2 — values below 2
are ignored and the automatic calculation is used instead.
Only takes effect when an X-axis range has been set via
Config::x_axis_range().
Sourcepub fn x_axis_range(self, min: f64, max: f64) -> Self
pub fn x_axis_range(self, min: f64, max: f64) -> Self
Enables the X-axis and maps the domain [min, max] onto the plot width.
Once set, an X-axis line and tick labels are rendered below the graph
body. The number of ticks is calculated automatically — call
Config::x_axis_tick_count() to override.
§Example
use asciigraph::Config;
let config = Config::default().x_axis_range(0.0, 100.0);Sourcepub fn x_axis_value_formatter(
self,
formatter: Box<dyn Fn(f64) -> String>,
) -> Self
pub fn x_axis_value_formatter( self, formatter: Box<dyn Fn(f64) -> String>, ) -> Self
Sets a custom formatter for X-axis tick labels.
Accepts any closure of the form Fn(f64) -> String. Use this to add
units, control decimal places, or apply any other formatting to the
values printed below the X-axis ticks.
§Example
use asciigraph::Config;
let config = Config::default()
.x_axis_range(0.0, 1000.0)
.x_axis_value_formatter(Box::new(|v| format!("{:.0}ms", v)));Sourcepub fn y_axis_value_formatter(
self,
formatter: Box<dyn Fn(f64) -> String>,
) -> Self
pub fn y_axis_value_formatter( self, formatter: Box<dyn Fn(f64) -> String>, ) -> Self
Sets a custom formatter for Y-axis labels.
Accepts any closure of the form Fn(f64) -> String. Use this to add
units, convert between scales, or apply any other formatting to the
values printed on the Y-axis.
§Example
use asciigraph::Config;
let config = Config::default()
.y_axis_value_formatter(Box::new(|v| format!("{:.1} GiB", v / 1024.0)));Sourcepub fn zero_line(self, zero_line: ZeroLine) -> Self
pub fn zero_line(self, zero_line: ZeroLine) -> Self
Enables a horizontal reference line at Y = 0.0 across the data area.
The line is only visible when the data range straddles zero. Series arc characters always render on top of the zero line.
§Example
use asciigraph::{plot, Config, ZeroLine, AnsiColor};
let data = vec![-2.0, -1.0, 0.0, 1.0, 2.0];
let graph = plot(
&data,
Config::default().zero_line(ZeroLine::with_color(AnsiColor::RED)),
);Sourcepub fn threshold(self, t: Threshold) -> Self
pub fn threshold(self, t: Threshold) -> Self
Adds a horizontal reference line at a user-specified Y value.
Call this method multiple times to add more than one threshold. Series arc characters always render on top of threshold lines.
§Example
use asciigraph::{plot, Config, Threshold, AnsiColor};
let data = vec![60.0, 70.0, 85.0, 92.0, 78.0, 65.0];
let graph = plot(
&data,
Config::default()
.threshold(Threshold::with_color(80.0, AnsiColor::YELLOW))
.threshold(Threshold::with_color(90.0, AnsiColor::RED)),
);Sourcepub fn moving_average(self, window: usize) -> Self
pub fn moving_average(self, window: usize) -> Self
Enables a moving average overlay rendered as an additional series.
The smoothed series is drawn on top of the original data using the next
available series color and character set. A window of 0 or 1 has no
effect.
§Example
use asciigraph::{plot, Config};
let data = vec![3.0, 1.0, 5.0, 2.0, 4.0, 1.0, 6.0, 2.0, 5.0, 1.0];
let graph = plot(&data, Config::default().moving_average(3));Sourcepub fn x_axis_label(self, label: &str) -> Self
pub fn x_axis_label(self, label: &str) -> Self
Sets a descriptive label for the X-axis.
Rendered inline on the same row as the axis line, to the right of the
tick marks. Only visible when Config::x_axis_range() is also set.
§Example
use asciigraph::Config;
let config = Config::default()
.x_axis_range(0.0, 100.0)
.x_axis_label("Time (seconds)");Sourcepub fn y_axis_label(self, label: &str) -> Self
pub fn y_axis_label(self, label: &str) -> Self
Sets a descriptive label for the Y-axis.
Rendered flush left above the graph body.
§Example
use asciigraph::Config;
let config = Config::default().y_axis_label("Memory (MB)");Sourcepub fn stat_annotations(self, sa: StatAnnotations) -> Self
pub fn stat_annotations(self, sa: StatAnnotations) -> Self
Enables statistical annotations as horizontal reference lines across the data area.
Supports minimum, maximum, mean, median, and standard deviation. Annotations are rendered before the series so series arc characters always appear on top.
§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];
let graph = plot(
&data,
Config::default()
.stat_annotations(StatAnnotations::with_color(AnsiColor::YELLOW)),
);