#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Legend {
pub position: String,
pub layout: Option<String>,
}
impl Default for Legend {
fn default() -> Self {
Legend {
position: "r".to_string(),
layout: None,
}
}
}
impl Legend {
pub fn new() -> Self {
Legend::default()
}
pub fn with_position(mut self, position: &str) -> Self {
self.position = position.to_string();
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_position_is_right() {
assert_eq!(Legend::new().position, "r");
assert!(Legend::new().layout.is_none());
}
#[test]
fn position_is_configurable() {
assert_eq!(Legend::new().with_position("b").position, "b");
}
}