(
root: &DrawingArea<DB, plotters::coord::Shift>,
config: &LayoutConfig,
width: u32,
height: u32,
)
| 5 | use crate::converters::layout::LayoutConfig; |
| 6 | |
| 7 | pub(super) fn draw_plot_title<DB: DrawingBackend>( |
| 8 | root: &DrawingArea<DB, plotters::coord::Shift>, |
| 9 | config: &LayoutConfig, |
| 10 | width: u32, |
| 11 | height: u32, |
| 12 | ) { |
| 13 | let title = match config.title { |
| 14 | Some(ref t) => t, |
| 15 | None => return, |
| 16 | }; |
| 17 | |
| 18 | let font_name = config.title_font.as_str(); |
| 19 | let font_size = config.title_font_size as f64; |
| 20 | let color = config |
| 21 | .title_color |
| 22 | .as_ref() |
| 23 | .map(convert_rgb) |
| 24 | .unwrap_or(BLACK); |
| 25 | |
| 26 | let style = TextStyle::from((font_name, font_size).into_font()) |
| 27 | .color(&color) |
| 28 | .pos(Pos::new(HPos::Center, VPos::Top)); |
| 29 | |
| 30 | // Position: default is centered at top, user can override with x/y |
| 31 | let tx = config |
| 32 | .title_x |
| 33 | .map(|x| (x * width as f64) as i32) |
| 34 | .unwrap_or(width as i32 / 2); |
| 35 | let ty = config |
| 36 | .title_y |
| 37 | .map(|y| ((1.0 - y) * height as f64) as i32) |
| 38 | .unwrap_or((15 + title_top_margin(config) as i32) / 2); |
| 39 | |
| 40 | root.draw_text(title, &style, (tx, ty)).unwrap(); |
| 41 | } |
| 42 | |
| 43 | pub(super) fn title_top_margin(config: &LayoutConfig) -> u32 { |
| 44 | if config.title.is_some() { |
no test coverage detected