plotkit_core/charts/
stem.rs1use crate::artist::StemArtist;
6use crate::primitives::Color;
7
8impl StemArtist {
9 pub fn color(&mut self, c: Color) -> &mut Self { self.color = c; self }
11 pub fn label(&mut self, l: &str) -> &mut Self { self.label = Some(l.to_string()); self }
13 pub fn baseline(&mut self, b: f64) -> &mut Self { self.baseline = b; self }
15 pub fn marker_size(&mut self, s: f64) -> &mut Self { self.marker_size = s; self }
17 pub fn width(&mut self, w: f64) -> &mut Self { self.line_width = w; self }
19 pub fn alpha(&mut self, a: f64) -> &mut Self { self.alpha = a.clamp(0.0, 1.0); self }
21}
22
23#[cfg(test)] mod tests { use super::*; use crate::series::Series;
24 const T: f64 = 1e-12; fn eq(a:f64,b:f64)->bool{(a-b).abs()<T}
25 fn s()->StemArtist{StemArtist{x:Series::new(vec![1.0,2.0,3.0,4.0]),y:Series::new(vec![1.0,3.0,2.0,4.0]),color:Color::TAB_BLUE,line_width:1.5,marker_size:6.0,baseline:0.0,label:None,alpha:1.0}}
26 #[test]fn c(){let mut a=s();a.color(Color::TAB_RED);assert_eq!(a.color,Color::TAB_RED);}
27 #[test]fn l(){let mut a=s();assert!(a.label.is_none());a.label("x");assert_eq!(a.label.as_deref(),Some("x"));}
28 #[test]fn lo(){let mut a=s();a.label("a");a.label("b");assert_eq!(a.label.as_deref(),Some("b"));}
29 #[test]fn bl(){let mut a=s();a.baseline(2.5);assert!(eq(a.baseline,2.5));}
30 #[test]fn bn(){let mut a=s();a.baseline(-1.0);assert!(eq(a.baseline,-1.0));}
31 #[test]fn ms(){let mut a=s();a.marker_size(10.0);assert!(eq(a.marker_size,10.0));}
32 #[test]fn w(){let mut a=s();a.width(3.0);assert!(eq(a.line_width,3.0));}
33 #[test]fn ac(){let mut a=s();a.alpha(0.5);assert!(eq(a.alpha,0.5));a.alpha(-1.0);assert!(eq(a.alpha,0.0));a.alpha(2.0);assert!(eq(a.alpha,1.0));}
34 #[test]fn ab(){let mut a=s();a.alpha(0.0);assert!(eq(a.alpha,0.0));a.alpha(1.0);assert!(eq(a.alpha,1.0));}
35 #[test]fn ch(){let mut a=s();a.color(Color::TAB_GREEN).baseline(1.0).marker_size(8.0).width(2.0).label("T").alpha(0.8);assert_eq!(a.color,Color::TAB_GREEN);assert!(eq(a.baseline,1.0));assert!(eq(a.marker_size,8.0));assert!(eq(a.line_width,2.0));assert_eq!(a.label.as_deref(),Some("T"));assert!(eq(a.alpha,0.8));}
36 #[test]fn db(){let a=s();assert!(eq(a.baseline,0.0));}
37 #[test]fn dm(){let a=s();assert!(eq(a.marker_size,6.0));}
38}