(
root: &DrawingArea<DB, plotters::coord::Shift>,
config: &LayoutConfig,
width: u32,
height: u32,
chart_margin: u32,
y_label_area: u32,
x_label_area: u32,
)
| 50 | |
| 51 | #[allow(clippy::too_many_arguments)] |
| 52 | pub(super) fn draw_axis_titles<DB: DrawingBackend>( |
| 53 | root: &DrawingArea<DB, plotters::coord::Shift>, |
| 54 | config: &LayoutConfig, |
| 55 | width: u32, |
| 56 | height: u32, |
| 57 | chart_margin: u32, |
| 58 | y_label_area: u32, |
| 59 | x_label_area: u32, |
| 60 | ) { |
| 61 | let top_margin = chart_margin + title_top_margin(config); |
| 62 | |
| 63 | // X-axis title |
| 64 | if let Some(ref label) = config.x_label { |
| 65 | let color = convert_rgb(&config.x_label_color); |
| 66 | let size = config.x_label_size as f64; |
| 67 | let style = TextStyle::from((config.x_label_font.as_str(), size).into_font()) |
| 68 | .color(&color) |
| 69 | .pos(Pos::new(HPos::Center, VPos::Bottom)); |
| 70 | let cx = config |
| 71 | .x_label_x |
| 72 | .map(|x| (x * width as f64) as i32) |
| 73 | .unwrap_or((chart_margin + y_label_area + width - chart_margin) as i32 / 2); |
| 74 | let cy = config |
| 75 | .x_label_y |
| 76 | .map(|y| ((1.0 - y) * height as f64) as i32) |
| 77 | .unwrap_or(height as i32 - 5); |
| 78 | root.draw_text(label, &style, (cx, cy)).unwrap(); |
| 79 | } |
| 80 | |
| 81 | // Y-axis title (rotated) |
| 82 | if let Some(ref label) = config.y_label { |
| 83 | let color = convert_rgb(&config.y_label_color); |
| 84 | let size = config.y_label_size as f64; |
| 85 | let style = TextStyle::from( |
| 86 | (config.y_label_font.as_str(), size) |
| 87 | .into_font() |
| 88 | .transform(FontTransform::Rotate270), |
| 89 | ) |
| 90 | .color(&color) |
| 91 | .pos(Pos::new(HPos::Center, VPos::Center)); |
| 92 | let cx = config |
| 93 | .y_label_x |
| 94 | .map(|x| (x * width as f64) as i32) |
| 95 | .unwrap_or(config.y_label_size as i32 / 2 + 2); |
| 96 | let cy = config |
| 97 | .y_label_y |
| 98 | .map(|y| ((1.0 - y) * height as f64) as i32) |
| 99 | .unwrap_or((top_margin + height - chart_margin - x_label_area) as i32 / 2); |
| 100 | root.draw_text(label, &style, (cx, cy)).unwrap(); |
| 101 | } |
| 102 | |
| 103 | // Y2-axis title (rotated, right side) |
| 104 | if let Some(ref label) = config.y2_label { |
| 105 | let color = convert_rgb(&config.y2_label_color); |
| 106 | let size = config.y2_label_size as f64; |
| 107 | let style = TextStyle::from( |
| 108 | (config.y2_label_font.as_str(), size) |
| 109 | .into_font() |
no test coverage detected