Skip to content

Commit

Permalink
Creating axis builders
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuomaidana authored and andrei-ng committed Sep 16, 2024
1 parent 92fc89c commit 73657bd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions plotly/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,14 @@ impl Axis {
self.domain = Some(domain.to_vec());
self
}

pub fn single_axis(axis: Axis)->Vec<Option<Box<Axis>>>{
vec![Some(Box::new(axis))]
}

pub fn from_axes(axes: Vec<Axis>) -> Vec<Option<Box<Axis>>> {
axes.into_iter().map(|axis| Some(Box::new(axis))).collect()
}
}

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

#[test]
fn test_single_axis_builder(){
let single_axis = Axis::single_axis(Axis::new());
let expected = json!([{}]);
assert_eq!(to_value(single_axis).unwrap(), expected);
}

#[test]
fn test_axes_builder(){
let axes = Axis::from_axes(vec![Axis::new(), Axis::new()]);
let expected = json!([{}, {}]);
assert_eq!(to_value(axes).unwrap(), expected);
}

#[test]
#[rustfmt::skip]
fn test_serialize_click_mode() {
Expand Down

0 comments on commit 73657bd

Please sign in to comment.