use super::elements::{ElementLine, ElementRect, ElementText};
use super::{LegendPosition, Margin, Theme};
const DEFAULT_BASE_SIZE: f64 = 11.0;
fn text_sizes(base_size: f64) -> (f64, f64, f64) {
let title = base_size * 1.2; let axis_title = base_size; let axis_text = base_size * 0.8; (title, axis_title, axis_text)
}
pub fn theme_gray() -> Theme {
theme_gray_base(DEFAULT_BASE_SIZE)
}
pub fn theme_gray_base(base_size: f64) -> Theme {
let (title_size, axis_title_size, axis_text_size) = text_sizes(base_size);
let half_line = base_size / 2.0;
Theme {
text: ElementText {
size: base_size,
color: (0, 0, 0),
..Default::default()
},
title: ElementText {
size: title_size,
color: (0, 0, 0),
..Default::default()
},
axis_text_x: ElementText {
size: axis_text_size,
color: (77, 77, 77), ..Default::default()
},
axis_text_y: ElementText {
size: axis_text_size,
color: (77, 77, 77), hjust: 1.0,
..Default::default()
},
axis_title_x: ElementText {
size: axis_title_size,
color: (0, 0, 0),
..Default::default()
},
axis_title_y: ElementText {
size: axis_title_size,
color: (0, 0, 0),
angle: 90.0,
..Default::default()
},
axis_line: ElementLine::blank(), axis_ticks: ElementLine {
color: (51, 51, 51), width: 0.5,
visible: true,
},
panel_background: ElementRect {
fill: Some((235, 235, 235)), color: None,
width: 0.0,
visible: true,
},
panel_grid_major: ElementLine {
color: (255, 255, 255), width: 1.0,
visible: true,
},
panel_grid_minor: ElementLine {
color: (255, 255, 255), width: 0.5,
visible: true,
},
plot_background: ElementRect {
fill: Some((255, 255, 255)),
color: None,
width: 0.0,
visible: true,
},
legend_position: LegendPosition::Right,
plot_margin: Margin {
top: half_line,
right: half_line,
bottom: half_line,
left: half_line,
},
subtitle: ElementText {
size: base_size,
color: (0, 0, 0),
..Default::default()
},
caption: ElementText {
size: axis_text_size, color: (0, 0, 0),
..Default::default()
},
legend_title: ElementText {
size: base_size,
color: (0, 0, 0),
..Default::default()
},
legend_text: ElementText {
size: axis_text_size, color: (0, 0, 0),
..Default::default()
},
strip_text: ElementText {
size: axis_text_size, color: (26, 26, 26), ..Default::default()
},
axis_line_x: None,
axis_line_y: None,
axis_ticks_x: None,
axis_ticks_y: None,
panel_grid_major_x: None,
panel_grid_major_y: None,
panel_grid_minor_x: None,
panel_grid_minor_y: None,
panel_border: ElementLine::blank(),
legend_background: ElementRect {
fill: Some((255, 255, 255)),
color: None,
width: 0.0,
visible: true,
},
legend_key: ElementRect {
fill: Some((242, 242, 242)), color: None,
width: 0.0,
visible: true,
},
strip_background: ElementRect {
fill: Some((217, 217, 217)), color: None, width: 0.0,
visible: true,
},
axis_ticks_length: half_line / 2.0,
legend_key_width: 12.0,
legend_key_height: 18.0,
legend_spacing: 4.0,
legend_margin: Margin {
top: 10.0,
right: 15.0,
bottom: 10.0,
left: 10.0,
},
panel_spacing: half_line,
panel_spacing_x: None,
panel_spacing_y: None,
primary: None,
}
}
pub fn theme_bw() -> Theme {
theme_bw_base(DEFAULT_BASE_SIZE)
}
pub fn theme_bw_base(base_size: f64) -> Theme {
Theme {
panel_background: ElementRect {
fill: Some((255, 255, 255)),
color: None,
width: 0.0,
visible: true,
},
panel_border: ElementLine {
color: (51, 51, 51), width: 1.0,
visible: true,
},
panel_grid_major: ElementLine {
color: (235, 235, 235), width: 0.5,
visible: true,
},
panel_grid_minor: ElementLine {
color: (235, 235, 235), width: 0.25,
visible: true,
},
strip_background: ElementRect {
fill: Some((217, 217, 217)), color: Some((51, 51, 51)), width: 0.5,
visible: true,
},
legend_key: ElementRect {
fill: Some((255, 255, 255)), color: None,
width: 0.0,
visible: true,
},
..theme_gray_base(base_size)
}
}
pub fn theme_minimal() -> Theme {
theme_minimal_base(DEFAULT_BASE_SIZE)
}
pub fn theme_minimal_base(base_size: f64) -> Theme {
Theme {
axis_ticks: ElementLine::blank(),
panel_background: ElementRect::blank(),
panel_border: ElementLine::blank(),
panel_grid_major: ElementLine {
color: (235, 235, 235), width: 0.5,
visible: true,
},
panel_grid_minor: ElementLine {
color: (235, 235, 235),
width: 0.25,
visible: true,
},
plot_background: ElementRect::blank(),
legend_background: ElementRect::blank(),
legend_key: ElementRect::blank(),
strip_background: ElementRect::blank(),
..theme_bw_base(base_size)
}
}
pub fn theme_classic() -> Theme {
theme_classic_base(DEFAULT_BASE_SIZE)
}
pub fn theme_classic_base(base_size: f64) -> Theme {
Theme {
panel_border: ElementLine::blank(),
panel_grid_major: ElementLine::blank(),
panel_grid_minor: ElementLine::blank(),
axis_line: ElementLine {
color: (0, 0, 0),
width: 0.5,
visible: true,
},
axis_ticks: ElementLine {
color: (0, 0, 0),
width: 0.5,
visible: true,
},
strip_background: ElementRect {
fill: Some((255, 255, 255)),
color: Some((0, 0, 0)),
width: 1.0,
visible: true,
},
..theme_bw_base(base_size)
}
}
pub fn theme_linedraw() -> Theme {
theme_linedraw_base(DEFAULT_BASE_SIZE)
}
pub fn theme_linedraw_base(base_size: f64) -> Theme {
Theme {
panel_border: ElementLine {
color: (0, 0, 0),
width: 1.0,
visible: true,
},
panel_grid_major: ElementLine {
color: (0, 0, 0), width: 0.1,
visible: true,
},
panel_grid_minor: ElementLine {
color: (0, 0, 0), width: 0.05,
visible: true,
},
axis_ticks: ElementLine {
color: (0, 0, 0),
width: 0.5,
visible: true,
},
strip_background: ElementRect {
fill: Some((0, 0, 0)), color: None,
width: 0.0,
visible: true,
},
strip_text: ElementText {
size: base_size * 0.8,
color: (255, 255, 255), ..Default::default()
},
..theme_bw_base(base_size)
}
}
pub fn theme_light() -> Theme {
theme_light_base(DEFAULT_BASE_SIZE)
}
pub fn theme_light_base(base_size: f64) -> Theme {
Theme {
panel_background: ElementRect {
fill: Some((255, 255, 255)),
color: None,
width: 0.0,
visible: true,
},
panel_border: ElementLine {
color: (179, 179, 179), width: 1.0,
visible: true,
},
panel_grid_major: ElementLine {
color: (222, 222, 222), width: 0.5,
visible: true,
},
panel_grid_minor: ElementLine {
color: (222, 222, 222), width: 0.25,
visible: true,
},
axis_ticks: ElementLine {
color: (179, 179, 179), width: 0.5,
visible: true,
},
legend_key: ElementRect {
fill: Some((255, 255, 255)),
color: None,
width: 0.0,
visible: true,
},
strip_background: ElementRect {
fill: Some((179, 179, 179)), color: None,
width: 0.0,
visible: true,
},
strip_text: ElementText {
size: base_size * 0.8,
color: (255, 255, 255), ..Default::default()
},
..theme_gray_base(base_size)
}
}
pub fn theme_dark() -> Theme {
theme_dark_base(DEFAULT_BASE_SIZE)
}
pub fn theme_dark_base(base_size: f64) -> Theme {
Theme {
panel_background: ElementRect {
fill: Some((127, 127, 127)), color: None,
width: 0.0,
visible: true,
},
panel_grid_major: ElementLine {
color: (107, 107, 107), width: 0.5,
visible: true,
},
panel_grid_minor: ElementLine {
color: (107, 107, 107), width: 0.25,
visible: true,
},
axis_ticks: ElementLine {
color: (51, 51, 51), width: 0.5,
visible: true,
},
strip_background: ElementRect {
fill: Some((38, 38, 38)), color: None,
width: 0.0,
visible: true,
},
strip_text: ElementText {
size: base_size * 0.8,
color: (230, 230, 230), ..Default::default()
},
legend_key: ElementRect {
fill: Some((127, 127, 127)), color: None,
width: 0.0,
visible: true,
},
..theme_gray_base(base_size)
}
}
pub fn theme_void() -> Theme {
theme_void_base(DEFAULT_BASE_SIZE)
}
pub fn theme_void_base(base_size: f64) -> Theme {
let (title_size, _, axis_text_size) = text_sizes(base_size);
Theme {
text: ElementText::blank(),
title: ElementText {
size: title_size,
..Default::default()
},
axis_text_x: ElementText::blank(),
axis_text_y: ElementText::blank(),
axis_title_x: ElementText::blank(),
axis_title_y: ElementText::blank(),
axis_line: ElementLine::blank(),
axis_ticks: ElementLine::blank(),
panel_background: ElementRect::blank(),
panel_grid_major: ElementLine::blank(),
panel_grid_minor: ElementLine::blank(),
plot_background: ElementRect::blank(),
legend_position: LegendPosition::Right, plot_margin: Margin {
top: 0.0,
right: 0.0,
bottom: 0.0,
left: 0.0,
},
subtitle: ElementText::blank(),
caption: ElementText::blank(),
legend_title: ElementText {
size: axis_text_size, ..Default::default()
},
legend_text: ElementText {
size: axis_text_size, ..Default::default()
},
strip_text: ElementText {
size: axis_text_size, ..Default::default()
},
axis_line_x: None,
axis_line_y: None,
axis_ticks_x: None,
axis_ticks_y: None,
panel_grid_major_x: None,
panel_grid_major_y: None,
panel_grid_minor_x: None,
panel_grid_minor_y: None,
panel_border: ElementLine::blank(),
legend_background: ElementRect::blank(),
legend_key: ElementRect::blank(),
strip_background: ElementRect::blank(),
axis_ticks_length: 0.0,
legend_key_width: 12.0,
legend_key_height: 18.0,
legend_spacing: 4.0,
legend_margin: Margin {
top: 0.0,
right: 0.0,
bottom: 0.0,
left: 0.0,
},
panel_spacing: 0.0,
panel_spacing_x: None,
panel_spacing_y: None,
primary: None,
}
}