use esoc_color::Color;
#[derive(Clone, Debug)]
pub enum Annotation {
HLine {
y: f64,
color: Color,
width: f32,
dash: Option<Vec<f32>>,
label: Option<String>,
},
VLine {
x: f64,
color: Color,
width: f32,
dash: Option<Vec<f32>>,
label: Option<String>,
},
Band {
y_min: f64,
y_max: f64,
color: Color,
label: Option<String>,
},
Text {
x: f64,
y: f64,
text: String,
color: Color,
font_size: f32,
},
}
impl Annotation {
pub fn hline(y: f64) -> Self {
Self::HLine {
y,
color: Color::new(0.5, 0.5, 0.5, 1.0),
width: 1.0,
dash: Some(vec![4.0, 4.0]),
label: None,
}
}
pub fn vline(x: f64) -> Self {
Self::VLine {
x,
color: Color::new(0.5, 0.5, 0.5, 1.0),
width: 1.0,
dash: Some(vec![4.0, 4.0]),
label: None,
}
}
pub fn band(y_min: f64, y_max: f64) -> Self {
Self::Band {
y_min,
y_max,
color: Color::new(0.5, 0.5, 0.5, 0.15),
label: None,
}
}
pub fn text(x: f64, y: f64, text: impl Into<String>) -> Self {
Self::Text {
x,
y,
text: text.into(),
color: Color::BLACK,
font_size: 11.0,
}
}
pub fn with_color(mut self, color: Color) -> Self {
match &mut self {
Self::HLine { color: c, .. }
| Self::VLine { color: c, .. }
| Self::Band { color: c, .. }
| Self::Text { color: c, .. } => *c = color,
}
self
}
pub fn with_label(mut self, label: impl Into<String>) -> Self {
match &mut self {
Self::HLine { label: l, .. }
| Self::VLine { label: l, .. }
| Self::Band { label: l, .. } => {
*l = Some(label.into());
}
Self::Text { .. } => {}
}
self
}
}