use plotine_core::Color;
use crate::mpl_policy::font as font_policy;
#[inline]
pub fn points_to_px(points: f64, dpi: f64) -> f64 {
points * (dpi / 72.0).max(0.05)
}
#[inline]
pub fn points_to_px_f32(points: f32, dpi: f64) -> f32 {
points_to_px(points as f64, dpi) as f32
}
#[derive(Debug, Clone, PartialEq)]
pub struct Theme {
pub background: Color,
pub axes_face: Color,
pub spine: Color,
pub tick: Color,
pub grid: Color,
pub label: Color,
pub title: Color,
pub title_size: f32,
pub label_size: f32,
pub tick_label_size: f32,
pub spine_width: f64,
pub tick_width: f64,
pub tick_length: f64,
pub grid_width: f64,
pub show_grid: bool,
}
impl Theme {
pub fn light() -> Self {
Self {
background: Color::BACKGROUND,
axes_face: Color::AXES_FACE,
spine: Color::SPINE,
tick: Color::TICK,
grid: Color::GRID,
label: Color::LABEL,
title: Color::TITLE,
title_size: font_policy::TITLE_PT,
label_size: font_policy::LABEL_PT,
tick_label_size: font_policy::TICK_PT,
spine_width: 0.95,
tick_width: 0.9,
tick_length: 5.0,
grid_width: 0.75,
show_grid: true,
}
}
pub fn dark() -> Self {
Self {
background: Color::rgb(0x1a, 0x1d, 0x21),
axes_face: Color::rgb(0x21, 0x25, 0x29),
spine: Color::rgb(0xad, 0xb5, 0xbd),
tick: Color::rgb(0xad, 0xb5, 0xbd),
grid: Color::rgb(0x49, 0x50, 0x57),
label: Color::rgb(0xde, 0xe2, 0xe6),
title: Color::rgb(0xf8, 0xf9, 0xfa),
title_size: font_policy::TITLE_PT,
label_size: font_policy::LABEL_PT,
tick_label_size: font_policy::TICK_PT,
spine_width: 0.95,
tick_width: 0.9,
tick_length: 5.0,
grid_width: 0.75,
show_grid: true,
}
}
pub fn paper() -> Self {
Self {
background: Color::rgb(0xff, 0xff, 0xff),
axes_face: Color::rgb(0xff, 0xfc, 0xf5),
spine: Color::rgb(0x33, 0x37, 0x3d),
tick: Color::rgb(0x33, 0x37, 0x3d),
grid: Color::rgb(0xe9, 0xec, 0xef),
label: Color::rgb(0x21, 0x25, 0x29),
title: Color::rgb(0x12, 0x12, 0x12),
title_size: font_policy::TITLE_PT,
label_size: font_policy::LABEL_PT,
tick_label_size: font_policy::TICK_PT,
spine_width: 1.1,
tick_width: 1.0,
tick_length: 5.5,
grid_width: 0.7,
show_grid: true,
}
}
}
impl Default for Theme {
fn default() -> Self {
Self::light()
}
}