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
48
49
50
51
52
53
54
55
56
57
use super::*;

/// Generates a Histogram plot
pub struct Histogram {
    pub colors: Vec<String>, // colors
    pub style: String,       // type; e.g. "bar"
    pub stacked: bool,       // stacked
    pub no_fill: bool,       // do not fill bars
    pub number_bins: i32,    // number of bins
    pub normalized: bool,    // normed

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

impl Histogram {
    pub fn new() -> Self {
        Histogram {
            colors: Vec::new(),
            style: String::new(),
            stacked: false,
            no_fill: false,
            number_bins: 0,
            normalized: false,
            buffer: String::new(),
        }
    }

    pub(crate) fn options(&self) -> String {
        let mut options = String::new();
        if self.colors.len() > 0 {
            options.push_str(&format!(",color={}", array2list(&self.colors)));
        }
        if self.style != "" {
            options.push_str(&format!(",histtype='{}'", self.style));
        }
        if self.stacked {
            options.push_str(",stacked=True");
        }
        if self.no_fill {
            options.push_str(",fill=False");
        }
        if self.number_bins > 0 {
            options.push_str(&format!(",bins={}", self.number_bins));
        }
        if self.normalized {
            options.push_str(",normed=True");
        }
        options
    }
}

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