use charton::prelude::*;
use std::error::Error;
#[test]
fn test_line_1() -> Result<(), Box<dyn Error>> {
let a = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let b = vec![10.0, 20.0, 30.0, 40.0, 50.0];
let category = vec!["A", "B", "A", "B", "C"];
chart!(a, b, category)?
.mark_line()?
.encode((
alt::x("a"),
alt::y("b"),
))?
.with_size(500, 300)
.save("./tests/line_1.svg")?;
Ok(())
}
#[test]
fn test_line_2() -> Result<(), Box<dyn Error>> {
let a: Vec<f64> = (0..30).map(|i| i as f64 * 0.2).collect();
let b: Vec<f64> = a.iter().map(|&x| x.sin()).collect();
let category = ["Sine"; 30];
chart!(a, b, category)?
.mark_line()?
.configure_line(|l| l.with_loess(true).with_loess_bandwidth(0.3))
.encode((alt::x("a"), alt::y("b"), alt::color("category")))?
.with_size(600, 400)
.save("./tests/line_2.svg")?;
Ok(())
}
#[test]
fn test_line_3() -> Result<(), Box<dyn Error>> {
let x_values: Vec<f64> = (0..30).map(|i| i as f64 * 0.2).collect();
let y_sine: Vec<f64> = x_values.iter().map(|&x| x.sin()).collect();
let y_cosine: Vec<f64> = x_values.iter().map(|&x| x.cos()).collect();
let a = x_values.repeat(2);
let b = [y_sine, y_cosine].concat();
let category = [vec!["Sine"; 30], vec!["Cosine"; 30]].concat();
chart!(a, b, category)?
.mark_line()?
.encode((
alt::x("a"),
alt::y("b"),
alt::color("category"), ))?
.with_size(600, 400)
.coord_flip()
.save("./tests/line_3.svg")?;
Ok(())
}
#[test]
fn test_line_4() -> Result<(), Box<dyn Error>> {
let a: Vec<f64> = (0..30).map(|i| i as f64 * 0.2).collect();
let b: Vec<f64> = a.iter().map(|&x| x.sin()).collect();
let category = ["Sine"; 30];
chart!(a, b, category)?
.mark_line()?
.encode((
alt::x("a"),
alt::y("b"),
alt::color("category"), ))?
.with_size(500, 400)
.save("./tests/line_4.svg")?;
Ok(())
}