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 contour plot
pub struct Contour {
    pub colors: Vec<String>,     // colors
    pub levels: Vec<f64>,        // levels (may be nil)
    pub colormap_index: i32,     // colormap index
    pub number_format: String,   // number format
    pub no_lines: bool,          // no lines on top of filled contour
    pub no_labels: bool,         // no labels
    pub no_inline: bool,         // no labels 'inline'
    pub no_colorbar: bool,       // no colorbar
    pub colorbar_label: String,  // colorbar label
    pub selected_value: f64,     // selected value
    pub selected_color: String,  // color to mark selected level
    pub selected_linewidth: f64, // zero level linewidth

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

impl Contour {
    pub fn new() -> Self {
        Contour {
            colors: Vec::new(),
            levels: Vec::new(),
            colormap_index: 0,
            number_format: String::new(),
            no_lines: false,
            no_labels: false,
            no_inline: false,
            no_colorbar: false,
            colorbar_label: String::new(),
            selected_value: 0.0,
            selected_color: String::new(),
            selected_linewidth: 0.0,
            buffer: String::new(),
        }
    }

    pub(crate) fn options(&self) -> String {
        let mut options = String::new();
        if self.colors.len() > 0 {
            options.push_str(&format!(",colors={}", array2list(&self.colors)));
        }
        if self.levels.len() > 0 {
            options.push_str(&format!(",levels={}", array2list(&self.levels)));
        }
        options
    }
}

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