MCPcopy Create free account
hub / github.com/alceal/plotlars / draw_plot_title

Function draw_plot_title

crates/plotlars-plotters/src/render/title.rs:7–41  ·  view source on GitHub ↗
(
    root: &DrawingArea<DB, plotters::coord::Shift>,
    config: &LayoutConfig,
    width: u32,
    height: u32,
)

Source from the content-addressed store, hash-verified

5use crate::converters::layout::LayoutConfig;
6
7pub(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
43pub(super) fn title_top_margin(config: &LayoutConfig) -> u32 {
44 if config.title.is_some() {

Callers 5

render_boxplotFunction · 0.85
render_bar_verticalFunction · 0.85
render_bar_horizontalFunction · 0.85
render_numericFunction · 0.85
render_heatmapFunction · 0.85

Calls 2

title_top_marginFunction · 0.85
colorMethod · 0.80

Tested by

no test coverage detected