use crate::color::AnsiColor;
use crate::options::charset::{CharSet};
use crate::options::extensions::{ZeroLine, Threshold, StatAnnotations};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Config {
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]>,
#[cfg_attr(feature = "serde", serde(skip))]
pub x_axis_value_formatter: Option<Box<dyn Fn(f64) -> String>>,
#[cfg_attr(feature = "serde", serde(skip))]
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>,
}
impl Default for Config {
fn default() -> Self {
Config {
width: 0,
height: 0,
lower_bound: None,
upper_bound: None,
offset: 3,
caption: String::new(),
precision: None,
caption_color: AnsiColor::DEFAULT,
axis_color: AnsiColor::DEFAULT,
label_color: AnsiColor::DEFAULT,
series_colors: Vec::new(),
series_legends: Vec::new(),
line_ending: String::from("\n"),
series_chars: Vec::new(),
x_axis_tick_count: 0,
x_axis_range: None,
x_axis_value_formatter: None,
y_axis_value_formatter: None,
zero_line: None,
thresholds: Vec::new(),
moving_average_window: None,
x_axis_label: None,
y_axis_label: None,
stat_annotations: None,
}
}
}
impl Config {
pub fn width(mut self, w: usize) -> Self {
self.width = w;
self
}
pub fn height(mut self, h: usize) -> Self {
self.height = h;
self
}
pub fn lower_bound(mut self, min: f64) -> Self {
self.lower_bound = Some(min);
self
}
pub fn upper_bound(mut self, max: f64) -> Self {
self.upper_bound = Some(max);
self
}
pub fn offset(mut self, off: usize) -> Self {
self.offset = off;
self
}
pub fn precision(mut self, p: usize) -> Self {
self.precision = Some(p);
self
}
pub fn caption(mut self, c: &str) -> Self {
self.caption = c.trim().to_string();
self
}
pub fn caption_color(mut self, color: AnsiColor) -> Self {
self.caption_color = color;
self
}
pub fn axis_color(mut self, color: AnsiColor) -> Self {
self.axis_color = color;
self
}
pub fn label_color(mut self, color: AnsiColor) -> Self {
self.label_color = color;
self
}
pub fn series_colors(mut self, colors: &[AnsiColor]) -> Self {
self.series_colors = colors.to_vec();
self
}
pub fn series_legends(mut self, text: &[&str]) -> Self {
self.series_legends = text.iter().map(|s| s.to_string()).collect();
self
}
pub fn line_ending(mut self, ending: &str) -> Self {
self.line_ending = ending.to_string();
self
}
pub fn series_chars(mut self, cs: &[CharSet]) -> Self {
self.series_chars = cs.to_vec();
self
}
pub fn x_axis_tick_count(mut self, count: usize) -> Self {
if count >= 2 {
self.x_axis_tick_count = count;
}
self
}
pub fn x_axis_range(mut self, min: f64, max: f64) -> Self {
self.x_axis_range = Some([min, max]);
self
}
pub fn x_axis_value_formatter(mut self, formatter: Box<dyn Fn(f64) -> String>) -> Self {
self.x_axis_value_formatter = Some(formatter);
self
}
pub fn y_axis_value_formatter(mut self, formatter: Box<dyn Fn(f64) -> String>) -> Self {
self.y_axis_value_formatter = Some(formatter);
self
}
pub fn zero_line(mut self, zero_line: ZeroLine) -> Self {
self.zero_line = Some(zero_line);
self
}
pub fn threshold(mut self, t: Threshold) -> Self {
self.thresholds.push(t);
self
}
pub fn moving_average(mut self, window: usize) -> Self {
self.moving_average_window = Some(window);
self
}
pub fn x_axis_label(mut self, label: &str) -> Self {
self.x_axis_label = Some(label.to_string());
self
}
pub fn y_axis_label(mut self, label: &str) -> Self {
self.y_axis_label = Some(label.to_string());
self
}
pub fn stat_annotations(mut self, sa: StatAnnotations) -> Self {
self.stat_annotations = Some(sa);
self
}
}