use crate::color::Color;
use crate::colormap::ColorMap;
use crate::config::{
AxisOptions, AxisScale, AxisTitleOptions, BarAlign, ChartTitleOptions, ColorBarOptions, Config,
DrawStyle, GridOptions, LabelStyle, Legend, LegendCorner, TickVisibility,
};
use crate::format::LabelFormat;
use crate::layout::{ChartArea, Rect, Side};
use crate::line::LineStylePreset;
use crate::text::RichText;
pub fn default_rich_text() -> RichText {
RichText {
segments: Vec::new(),
color: Color::BLACK,
font_size: 12.0,
font: String::new(),
}
}
pub fn default_chart_title_options() -> ChartTitleOptions {
ChartTitleOptions {
text: RichText {
segments: Vec::new(),
color: Color::BLACK,
font_size: 28.0,
font: String::new(),
},
visible: true,
offset_x: 0.0,
offset_y: 0.0,
top_margin: 32.0,
}
}
pub fn default_axis_title_options() -> AxisTitleOptions {
AxisTitleOptions {
text: RichText {
segments: Vec::new(),
color: Color::BLACK,
font_size: 22.0,
font: String::new(),
},
visible: true,
offset_x: 0.0,
offset_y: 0.0,
}
}
pub fn default_label_style_x() -> LabelStyle {
LabelStyle {
visible: true,
color: Color::BLACK,
font_size: 18.0,
label_visible: true,
label_font: String::new(),
label_offset_x: 0.0,
label_offset_y: 0.0,
format: LabelFormat::Decimal,
significant_digits: 3,
}
}
pub fn default_label_style_y() -> LabelStyle {
default_label_style_x()
}
pub fn default_axis_options_x() -> AxisOptions {
AxisOptions {
scale: AxisScale::Linear,
min: 0.0,
max: 1.0,
major_spacing: 0.2,
minor_count: 4,
inverted: false,
label_style: default_label_style_x(),
tick: TickVisibility::Inside,
title_option: default_axis_title_options(),
out_margin: 80.0,
line_offset: 0.0,
line_visible: true,
line_color: Color::BLACK,
line_width: 1.0,
line_style: LineStylePreset::Solid,
major_tick_length: 5.0,
minor_tick_length: 3.0,
}
}
pub fn default_axis_options_y() -> AxisOptions {
AxisOptions {
scale: AxisScale::Linear,
min: 0.0,
max: 1.0,
major_spacing: 0.2,
minor_count: 4,
inverted: false,
label_style: default_label_style_y(),
tick: TickVisibility::Inside,
title_option: default_axis_title_options(),
out_margin: 110.0,
line_offset: 0.0,
line_visible: true,
line_color: Color::BLACK,
line_width: 1.0,
line_style: LineStylePreset::Solid,
major_tick_length: 5.0,
minor_tick_length: 3.0,
}
}
pub fn default_axis_options_colorbar() -> AxisOptions {
let mut title_option = default_axis_title_options();
title_option.visible = false;
AxisOptions {
scale: AxisScale::Linear,
min: 0.0,
max: 1.0,
major_spacing: 0.2,
minor_count: 4,
inverted: false,
label_style: default_label_style_y(),
tick: TickVisibility::Outside,
title_option,
out_margin: 60.0,
line_offset: 0.0,
line_visible: false,
line_color: Color::BLACK,
line_width: 1.0,
line_style: LineStylePreset::Solid,
major_tick_length: 5.0,
minor_tick_length: 3.0,
}
}
pub fn default_colorbar_options() -> ColorBarOptions {
ColorBarOptions {
visible: true,
side: Side::Right,
thickness_px: 18.0,
gap_px: 24.0,
length_frac: 0.75,
align: BarAlign::Center,
offset_x: 0.0,
offset_y: 0.0,
colormap: ColorMap::Viridis,
nan_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
border_color: Color::from_rgb8(80, 80, 80),
border_width: 1.0,
axis: default_axis_options_colorbar(),
}
}
pub fn default_grid_options() -> GridOptions {
GridOptions {
show_major_x: true,
major_x_color: Color::from_rgb8(200, 200, 200),
major_x_width: 1.0,
major_x_style: LineStylePreset::Solid,
show_major_y: true,
major_y_color: Color::from_rgb8(200, 200, 200),
major_y_width: 1.0,
major_y_style: LineStylePreset::Solid,
show_minor_x: false,
minor_x_color: Color::from_rgb8(230, 230, 230),
minor_x_width: 0.5,
minor_x_style: LineStylePreset::Dot,
show_minor_y: false,
minor_y_color: Color::from_rgb8(230, 230, 230),
minor_y_width: 0.5,
minor_y_style: LineStylePreset::Dot,
}
}
pub fn default_legend() -> Legend {
Legend {
visible: false,
content: RichText {
segments: Vec::new(),
color: Color::BLACK,
font_size: 14.0,
font: String::new(),
},
corner: LegendCorner::TopRight,
offset_x: 0.0,
offset_y: 0.0,
padding: 8.0,
bg_color: Color {
r: 1.0,
g: 1.0,
b: 1.0,
a: 0.85,
},
border_color: Color {
r: 0.6,
g: 0.6,
b: 0.6,
a: 1.0,
},
}
}
pub fn default_chart_area() -> ChartArea {
ChartArea(Rect {
x: 0,
y: 0,
width: 1000,
height: 800,
})
}
pub fn default_config() -> Config {
let mut top_x = default_axis_options_x();
top_x.label_style.label_visible = false;
top_x.title_option.visible = false;
top_x.out_margin = 8.0;
let mut right_y = default_axis_options_y();
right_y.label_style.label_visible = false;
right_y.title_option.visible = false;
right_y.out_margin = 8.0;
Config {
chart_area: default_chart_area(),
top_x,
bottom_x: default_axis_options_x(),
left_y: default_axis_options_y(),
right_y,
chart_title: default_chart_title_options(),
grid: default_grid_options(),
legend: default_legend(),
picked_points: None,
picked_data: None,
colorbar: None,
draw_style: DrawStyle::Precise,
}
}