use super::axis::AxisTheme;
use super::element::{Element, TextElement};
use super::length::{Length, Margin};
use super::palette::ThemeColor;
use super::RectElement;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum Direction {
#[default]
Auto,
Horizontal,
Vertical,
}
impl Direction {
pub fn resolve(self, side: crate::scales::chrome::LegendSide) -> ResolvedDirection {
use crate::scales::chrome::LegendSide;
match self {
Direction::Horizontal => ResolvedDirection::Horizontal,
Direction::Vertical => ResolvedDirection::Vertical,
Direction::Auto => match side {
LegendSide::Top | LegendSide::Bottom => ResolvedDirection::Horizontal,
LegendSide::Left | LegendSide::Right => ResolvedDirection::Vertical,
LegendSide::InPanel { .. } => ResolvedDirection::Vertical,
},
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ResolvedDirection {
Horizontal,
Vertical,
}
#[derive(Debug, Clone, PartialEq)]
pub struct KeyTheme {
pub frame: Element<RectElement>,
pub width: Length,
pub height: Length,
pub spacing: Length,
}
impl Default for KeyTheme {
fn default() -> Self {
Self {
frame: Element::Set(RectElement {
fill: Some(ThemeColor::mix(ThemeColor::Paper, ThemeColor::Ink, 0.08)),
color: None,
linewidth_pt: Some(Length::Abs(0.0)),
..RectElement::default()
}),
width: Length::Abs(15.84),
height: Length::Abs(15.84),
spacing: Length::Abs(4.0),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct BarTheme {
pub length: Length,
pub width: Length,
pub frame: Element<RectElement>,
}
impl Default for BarTheme {
fn default() -> Self {
Self {
length: Length::Abs(100.0),
width: Length::Abs(15.84),
frame: Element::Set(RectElement {
fill: None,
..RectElement::default()
}),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct LegendTheme {
pub background: Element<RectElement>,
pub title: Element<TextElement>,
pub margin: Margin,
pub padding: Margin,
pub direction: Direction,
pub axis: AxisTheme,
pub key: KeyTheme,
pub bar: BarTheme,
}
impl Default for LegendTheme {
fn default() -> Self {
Self {
background: Element::Blank,
title: Element::Inherit,
margin: Margin::ZERO,
padding: Margin::all(Length::Abs(6.0)),
direction: Direction::default(),
axis: AxisTheme {
line: Element::Blank,
ticks: Element::Blank,
ticks_minor: Element::Blank,
..AxisTheme::default()
},
key: KeyTheme::default(),
bar: BarTheme::default(),
}
}
}