1use crate::figure::Figure;
2use crate::format::FormatBuilder;
3use crate::trace::Trace;
4
5pub fn quick_plot_2d(x: impl Into<Vec<f64>>, y: impl Into<Vec<f64>>) -> Figure {
30 let trace = Trace::new_2d(x.into(), y.into());
32
33 let format = FormatBuilder::default().build().unwrap();
35
36 Figure::new(vec![trace], format)
38}
39
40pub fn quick_plot_2d_with_labels(
74 x: impl Into<Vec<f64>>,
75 y: impl Into<Vec<f64>>,
76 x_label: impl Into<String>,
77 y_label: impl Into<String>,
78 title: impl Into<String>,
79) -> Figure {
80 let trace = Trace::new_2d(x.into(), y.into());
82
83 let format = FormatBuilder::default()
85 .x_label(x_label.into())
86 .y_label(y_label.into())
87 .title(title.into())
88 .build()
89 .unwrap();
90
91 Figure::new(vec![trace], format)
93}
94
95pub fn quick_plot_3d(
120 x: impl Into<Vec<f64>>,
121 y: impl Into<Vec<f64>>,
122 z: impl Into<Vec<f64>>,
123) -> Figure {
124 let trace = Trace::new_3d(x.into(), y.into(), z.into());
126
127 let format = FormatBuilder::default().build().unwrap();
129
130 Figure::new(vec![trace], format)
132}
133
134pub fn quick_plot_3d_with_labels(
171 x: impl Into<Vec<f64>>,
172 y: impl Into<Vec<f64>>,
173 z: impl Into<Vec<f64>>,
174 x_label: impl Into<String>,
175 y_label: impl Into<String>,
176 z_label: impl Into<String>,
177 title: impl Into<String>,
178) -> Figure {
179 let trace = Trace::new_3d(x.into(), y.into(), z.into());
181
182 let format = FormatBuilder::default()
184 .x_label(x_label.into())
185 .y_label(y_label.into())
186 .z_label(z_label.into())
187 .title(title.into())
188 .build()
189 .unwrap();
190
191 Figure::new(vec![trace], format)
193}
194
195#[cfg(test)]
196mod tests {
197 use super::*;
198
199 #[test]
200 fn test_quick_plot_2d() {
201 let fig: Figure = quick_plot_2d([1.0, 2.0, 3.0], [1.0, 4.0, 9.0]);
202 assert_eq!(fig.traces[0].x, [1.0, 2.0, 3.0]);
203 assert_eq!(fig.traces[0].y, [1.0, 4.0, 9.0]);
204 assert!(fig.format.title.is_none());
205 assert!(fig.format.x_label.is_none());
206 assert!(fig.format.y_label.is_none());
207 assert!(fig.format.width.is_none());
208 assert!(fig.format.height.is_none());
209 }
210
211 #[test]
212 fn test_quick_plot_2d_with_labels() {
213 let fig: Figure =
214 quick_plot_2d_with_labels([1.0, 2.0, 3.0], [1.0, 4.0, 9.0], "x", "y", "y vs. x");
215 assert_eq!(fig.traces[0].x, [1.0, 2.0, 3.0]);
216 assert_eq!(fig.traces[0].y, [1.0, 4.0, 9.0]);
217 assert_eq!(fig.format.title.unwrap(), "y vs. x");
218 assert_eq!(fig.format.x_label.unwrap(), "x");
219 assert_eq!(fig.format.y_label.unwrap(), "y");
220 assert!(fig.format.width.is_none());
221 assert!(fig.format.height.is_none());
222 }
223
224 #[test]
225 fn test_quick_plot_3d() {
226 let fig: Figure = quick_plot_3d([1.0, 2.0, 10.0], [1.0, 4.0, 9.0], [2.0, 5.0, 10.0]);
227 assert_eq!(fig.traces[0].x, [1.0, 2.0, 10.0]);
228 assert_eq!(fig.traces[0].y, [1.0, 4.0, 9.0]);
229 assert_eq!(fig.traces[0].z.clone().unwrap(), [2.0, 5.0, 10.0]);
230 assert!(fig.format.title.is_none());
231 assert!(fig.format.x_label.is_none());
232 assert!(fig.format.y_label.is_none());
233 assert!(fig.format.z_label.is_none());
234 assert!(fig.format.width.is_none());
235 assert!(fig.format.height.is_none());
236 }
237
238 #[test]
239 fn test_quick_plot_3d_with_labels() {
240 let fig: Figure = quick_plot_3d_with_labels(
241 [1.0, 2.0, 10.0],
242 [1.0, 4.0, 9.0],
243 [2.0, 5.0, 10.0],
244 "x",
245 "y",
246 "z",
247 "z vs. x and y",
248 );
249 assert_eq!(fig.traces[0].x, [1.0, 2.0, 10.0]);
250 assert_eq!(fig.traces[0].y, [1.0, 4.0, 9.0]);
251 assert_eq!(fig.traces[0].z.clone().unwrap(), [2.0, 5.0, 10.0]);
252 assert_eq!(fig.format.title.unwrap(), "z vs. x and y");
253 assert_eq!(fig.format.x_label.unwrap(), "x");
254 assert_eq!(fig.format.y_label.unwrap(), "y");
255 assert_eq!(fig.format.z_label.unwrap(), "z");
256 assert!(fig.format.width.is_none());
257 assert!(fig.format.height.is_none());
258 }
259}