use plotpy::{Histogram, Plot, StrError};
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
const OUT_DIR: &str = "/tmp/plotpy/integ_tests";
#[test]
fn test_histogram_1() -> Result<(), StrError> {
let mut histogram = Histogram::new();
histogram
.set_colors(&vec!["#cd0000", "#1862ab", "#cd8c00"])
.set_style("barstacked");
let values = vec![
vec![1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4, 5, 6], vec![-1, -1, 0, 1, 2, 3], vec![5, 6, 7, 8], ];
let labels = ["first".to_string(), "second".to_string(), "third".to_string()];
histogram.draw(&values, &labels);
let mut plot = Plot::new();
plot.add(&histogram);
let path = Path::new(OUT_DIR).join("integ_histogram_1.svg");
plot.save(&path)?;
let file = File::open(path).map_err(|_| "cannot open file")?;
let buffered = BufReader::new(file);
let lines_iter = buffered.lines();
assert!(lines_iter.count() > 670);
Ok(())
}
#[test]
fn test_histogram_2() -> Result<(), StrError> {
let mut histogram = Histogram::new();
histogram
.set_no_fill(true)
.set_number_bins(16)
.set_stacked(true)
.set_extra("orientation='horizontal'");
let values = vec![
vec![1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4, 5, 6], vec![-1, -1, 0, 1, 2, 3], vec![5, 6, 7, 8], ];
let labels = ["first", "second", "third"];
histogram.draw(&values, &labels);
let mut plot = Plot::new();
plot.add(&histogram);
let path = Path::new(OUT_DIR).join("integ_histogram_2.svg");
plot.save(&path)?;
let file = File::open(path).map_err(|_| "cannot open file")?;
let buffered = BufReader::new(file);
let lines_iter = buffered.lines();
assert!(lines_iter.count() > 810);
Ok(())
}