Skip to content

Commit 73657bd

Browse files
yasuomaidanaandrei-ng
authored andcommitted
Creating axis builders
1 parent 92fc89c commit 73657bd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

plotly/src/layout/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,14 @@ impl Axis {
597597
self.domain = Some(domain.to_vec());
598598
self
599599
}
600+
601+
pub fn single_axis(axis: Axis)->Vec<Option<Box<Axis>>>{
602+
vec![Some(Box::new(axis))]
603+
}
604+
605+
pub fn from_axes(axes: Vec<Axis>) -> Vec<Option<Box<Axis>>> {
606+
axes.into_iter().map(|axis| Some(Box::new(axis))).collect()
607+
}
600608
}
601609

602610
#[derive(Serialize, Debug, Clone)]
@@ -2872,6 +2880,20 @@ mod tests {
28722880
assert_eq!(to_value(annotation).unwrap(), expected);
28732881
}
28742882

2883+
#[test]
2884+
fn test_single_axis_builder(){
2885+
let single_axis = Axis::single_axis(Axis::new());
2886+
let expected = json!([{}]);
2887+
assert_eq!(to_value(single_axis).unwrap(), expected);
2888+
}
2889+
2890+
#[test]
2891+
fn test_axes_builder(){
2892+
let axes = Axis::from_axes(vec![Axis::new(), Axis::new()]);
2893+
let expected = json!([{}, {}]);
2894+
assert_eq!(to_value(axes).unwrap(), expected);
2895+
}
2896+
28752897
#[test]
28762898
#[rustfmt::skip]
28772899
fn test_serialize_click_mode() {

0 commit comments

Comments
 (0)