1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use super::*;

/// Creates text to be added to a plot
pub struct Text {
    pub alignment_horizontal: String, // e.g., 'center'
    pub alignment_vertical: String,   // e.g., 'center'
    pub rotation: f64,                // text rotation
    pub font_size: f64,               // font size

    // buffer
    pub(crate) buffer: String,
}

impl Text {
    pub fn new() -> Self {
        Text {
            alignment_horizontal: String::new(),
            alignment_vertical: String::new(),
            rotation: 0.0,
            font_size: 0.0,
            buffer: String::new(),
        }
    }

    pub(crate) fn options(&self) -> String {
        let mut options = String::new();
        if self.alignment_horizontal != "" {
            options.push_str(&format!(",ha='{}'", self.alignment_horizontal));
        }
        if self.alignment_vertical != "" {
            options.push_str(&format!(",va='{}'", self.alignment_vertical));
        }
        if self.rotation > 0.0 {
            options.push_str(&format!(",rotation={}", self.rotation));
        }
        if self.font_size > 0.0 {
            options.push_str(&format!(",fontsize={}", self.font_size));
        }
        options
    }
}

impl GraphMaker for Text {
    fn get_buffer<'a>(&'a self) -> &'a String {
        &self.buffer
    }
}