use crate::figure::Figure;
use crate::format::FormatBuilder;
use crate::trace::Trace;
pub fn quick_plot_2d(x: impl Into<Vec<f64>>, y: impl Into<Vec<f64>>) -> Figure {
let trace = Trace::new_2d(x.into(), y.into());
let format = FormatBuilder::default().build().unwrap();
Figure::new(vec![trace], format)
}
pub fn quick_plot_2d_with_labels(
x: impl Into<Vec<f64>>,
y: impl Into<Vec<f64>>,
x_label: impl Into<String>,
y_label: impl Into<String>,
title: impl Into<String>,
) -> Figure {
let trace = Trace::new_2d(x.into(), y.into());
let format = FormatBuilder::default()
.x_label(x_label.into())
.y_label(y_label.into())
.title(title.into())
.build()
.unwrap();
Figure::new(vec![trace], format)
}
pub fn quick_plot_3d(
x: impl Into<Vec<f64>>,
y: impl Into<Vec<f64>>,
z: impl Into<Vec<f64>>,
) -> Figure {
let trace = Trace::new_3d(x.into(), y.into(), z.into());
let format = FormatBuilder::default().build().unwrap();
Figure::new(vec![trace], format)
}
pub fn quick_plot_3d_with_labels(
x: impl Into<Vec<f64>>,
y: impl Into<Vec<f64>>,
z: impl Into<Vec<f64>>,
x_label: impl Into<String>,
y_label: impl Into<String>,
z_label: impl Into<String>,
title: impl Into<String>,
) -> Figure {
let trace = Trace::new_3d(x.into(), y.into(), z.into());
let format = FormatBuilder::default()
.x_label(x_label.into())
.y_label(y_label.into())
.z_label(z_label.into())
.title(title.into())
.build()
.unwrap();
Figure::new(vec![trace], format)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_quick_plot_2d() {
let fig: Figure = quick_plot_2d([1.0, 2.0, 3.0], [1.0, 4.0, 9.0]);
assert_eq!(fig.traces[0].x, [1.0, 2.0, 3.0]);
assert_eq!(fig.traces[0].y, [1.0, 4.0, 9.0]);
assert!(fig.format.title.is_none());
assert!(fig.format.x_label.is_none());
assert!(fig.format.y_label.is_none());
assert!(fig.format.width.is_none());
assert!(fig.format.height.is_none());
}
#[test]
fn test_quick_plot_2d_with_labels() {
let fig: Figure =
quick_plot_2d_with_labels([1.0, 2.0, 3.0], [1.0, 4.0, 9.0], "x", "y", "y vs. x");
assert_eq!(fig.traces[0].x, [1.0, 2.0, 3.0]);
assert_eq!(fig.traces[0].y, [1.0, 4.0, 9.0]);
assert_eq!(fig.format.title.unwrap(), "y vs. x");
assert_eq!(fig.format.x_label.unwrap(), "x");
assert_eq!(fig.format.y_label.unwrap(), "y");
assert!(fig.format.width.is_none());
assert!(fig.format.height.is_none());
}
#[test]
fn test_quick_plot_3d() {
let fig: Figure = quick_plot_3d([1.0, 2.0, 10.0], [1.0, 4.0, 9.0], [2.0, 5.0, 10.0]);
assert_eq!(fig.traces[0].x, [1.0, 2.0, 10.0]);
assert_eq!(fig.traces[0].y, [1.0, 4.0, 9.0]);
assert_eq!(fig.traces[0].z.clone().unwrap(), [2.0, 5.0, 10.0]);
assert!(fig.format.title.is_none());
assert!(fig.format.x_label.is_none());
assert!(fig.format.y_label.is_none());
assert!(fig.format.z_label.is_none());
assert!(fig.format.width.is_none());
assert!(fig.format.height.is_none());
}
#[test]
fn test_quick_plot_3d_with_labels() {
let fig: Figure = quick_plot_3d_with_labels(
[1.0, 2.0, 10.0],
[1.0, 4.0, 9.0],
[2.0, 5.0, 10.0],
"x",
"y",
"z",
"z vs. x and y",
);
assert_eq!(fig.traces[0].x, [1.0, 2.0, 10.0]);
assert_eq!(fig.traces[0].y, [1.0, 4.0, 9.0]);
assert_eq!(fig.traces[0].z.clone().unwrap(), [2.0, 5.0, 10.0]);
assert_eq!(fig.format.title.unwrap(), "z vs. x and y");
assert_eq!(fig.format.x_label.unwrap(), "x");
assert_eq!(fig.format.y_label.unwrap(), "y");
assert_eq!(fig.format.z_label.unwrap(), "z");
assert!(fig.format.width.is_none());
assert!(fig.format.height.is_none());
}
}