use crate::style::Color;
use crate::widget::theme::SEPARATOR_COLOR;
#[derive(Clone, Debug, Default)]
pub struct ChartGrid {
pub x: bool,
pub y: bool,
pub color: Option<Color>,
pub style: GridStyle,
}
impl ChartGrid {
pub fn new() -> Self {
Self::default()
}
pub fn both() -> Self {
Self {
x: true,
y: true,
..Default::default()
}
}
pub fn x_only() -> Self {
Self {
x: true,
y: false,
..Default::default()
}
}
pub fn y_only() -> Self {
Self {
x: false,
y: true,
..Default::default()
}
}
pub fn x(mut self, show: bool) -> Self {
self.x = show;
self
}
pub fn y(mut self, show: bool) -> Self {
self.y = show;
self
}
pub fn color(mut self, color: Color) -> Self {
self.color = Some(color);
self
}
pub fn style(mut self, style: GridStyle) -> Self {
self.style = style;
self
}
pub fn char(&self) -> char {
match self.style {
GridStyle::Solid => '─',
GridStyle::Dashed => '╌',
GridStyle::Dotted => '·',
}
}
pub fn effective_color(&self) -> Color {
self.color.unwrap_or(SEPARATOR_COLOR)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum GridStyle {
#[default]
Solid,
Dashed,
Dotted,
}