#[derive(Clone, Debug, Default)]
pub struct Legend {
pub position: LegendPosition,
pub orientation: LegendOrientation,
pub interactive: bool,
}
impl Legend {
pub fn new() -> Self {
Self::default()
}
pub fn position(mut self, position: LegendPosition) -> Self {
self.position = position;
self
}
pub fn orientation(mut self, orientation: LegendOrientation) -> Self {
self.orientation = orientation;
self
}
pub fn interactive(mut self, interactive: bool) -> Self {
self.interactive = interactive;
self
}
pub fn top_left() -> Self {
Self::new().position(LegendPosition::TopLeft)
}
pub fn top_center() -> Self {
Self::new().position(LegendPosition::TopCenter)
}
pub fn top_right() -> Self {
Self::new().position(LegendPosition::TopRight)
}
pub fn bottom_left() -> Self {
Self::new().position(LegendPosition::BottomLeft)
}
pub fn bottom_center() -> Self {
Self::new().position(LegendPosition::BottomCenter)
}
pub fn bottom_right() -> Self {
Self::new().position(LegendPosition::BottomRight)
}
pub fn left() -> Self {
Self::new()
.position(LegendPosition::Left)
.orientation(LegendOrientation::Vertical)
}
pub fn right() -> Self {
Self::new()
.position(LegendPosition::Right)
.orientation(LegendOrientation::Vertical)
}
pub fn none() -> Self {
Self::new().position(LegendPosition::None)
}
pub fn hidden() -> Self {
Self::none()
}
pub fn is_visible(&self) -> bool {
self.position != LegendPosition::None
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum LegendPosition {
TopLeft,
TopCenter,
#[default]
TopRight,
BottomLeft,
BottomCenter,
BottomRight,
Left,
Right,
None,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum LegendOrientation {
#[default]
Horizontal,
Vertical,
}