mod common;
use kuva::backend::svg::SvgBackend;
use kuva::plot::BoxPlot;
use kuva::render::layout::Layout;
use kuva::render::plots::Plot;
use kuva::render::render::render_multiple;
#[test]
fn test_boxplot_groups_svg_output_builder() {
let boxplot = BoxPlot::new()
.with_group("A", vec![1.0, 2.0, 2.5, 3.0, 4.0, 5.0])
.with_group("B", vec![2.0, 2.1, 3.5, 3.8, 4.0, 4.2])
.with_color("darkred");
let plots = vec![Plot::Box(boxplot)];
let layout = Layout::auto_from_plots(&plots)
.with_title("Box Plot")
.with_y_label("Values");
let scene = render_multiple(plots, layout);
let svg = SvgBackend.render_scene(&scene);
common::write_test_output("test_outputs/boxplot_groups_builder.svg", svg.clone()).unwrap();
assert!(svg.contains("<svg"));
}
#[test]
fn test_boxplot_svg_output_builder() {
let boxplot = BoxPlot::new()
.with_group("A", vec![1.0, 2.0, 2.5, 3.0, 4.0, 5.0])
.with_color("darkred");
let plots = vec![Plot::Box(boxplot)];
let layout = Layout::auto_from_plots(&plots)
.with_title("Box Plot")
.with_y_label("Values");
let scene = render_multiple(plots, layout);
let svg = SvgBackend.render_scene(&scene);
common::write_test_output("test_outputs/boxplot_builder.svg", svg.clone()).unwrap();
assert!(svg.contains("<svg"));
}
#[test]
fn test_boxplot_group_colors_full() {
let boxplot = BoxPlot::new()
.with_group("A", vec![1.0, 2.0, 2.5, 3.0, 4.0, 5.0])
.with_group("B", vec![2.0, 2.1, 3.5, 3.8, 4.0, 4.2])
.with_group("C", vec![3.0, 3.5, 4.0, 4.5, 5.0, 5.5])
.with_color("black")
.with_group_colors(["steelblue", "tomato", "seagreen"]);
let plots = vec![Plot::Box(boxplot)];
let layout = Layout::auto_from_plots(&plots).with_title("Per-group Colors");
let scene = render_multiple(plots, layout);
let svg = SvgBackend.render_scene(&scene);
common::write_test_output("test_outputs/boxplot_group_colors_full.svg", svg.clone()).unwrap();
assert!(svg.contains("<svg"));
assert!(svg.contains("steelblue") || svg.contains("#4682b4"));
assert!(svg.contains("tomato") || svg.contains("#ff6347"));
assert!(svg.contains("seagreen") || svg.contains("#2e8b57"));
}
#[test]
fn test_boxplot_group_colors_partial() {
let boxplot = BoxPlot::new()
.with_group("A", vec![1.0, 2.0, 2.5, 3.0, 4.0, 5.0])
.with_group("B", vec![2.0, 2.1, 3.5, 3.8, 4.0, 4.2])
.with_group("C", vec![3.0, 3.5, 4.0, 4.5, 5.0, 5.5])
.with_color("black")
.with_group_colors(["tomato"]);
let plots = vec![Plot::Box(boxplot)];
let layout = Layout::auto_from_plots(&plots).with_title("Partial Per-group Colors");
let scene = render_multiple(plots, layout);
let svg = SvgBackend.render_scene(&scene);
common::write_test_output("test_outputs/boxplot_group_colors_partial.svg", svg.clone())
.unwrap();
assert!(svg.contains("<svg"));
assert!(svg.contains("tomato") || svg.contains("#ff6347"));
assert!(svg.contains("black"));
}
#[test]
fn test_boxplot_horizontal() {
let plot = BoxPlot::new()
.with_group("Alpha", vec![1.0, 2.0, 3.0, 4.0, 5.0])
.with_group("Beta", vec![2.0, 3.5, 4.0, 4.5, 6.0])
.with_group("Gamma", vec![3.0, 4.0, 5.0, 6.0, 8.0])
.with_color("steelblue")
.with_horizontal(true);
let plots = vec![Plot::Box(plot)];
let layout = Layout::auto_from_plots(&plots)
.with_title("Horizontal Box Plot")
.with_x_label("Value")
.with_y_label("Group");
let scene = render_multiple(plots, layout);
let svg = SvgBackend.render_scene(&scene);
common::write_test_output("test_outputs/boxplot_horizontal.svg", svg.clone()).unwrap();
assert!(svg.contains("<svg"));
assert!(svg.contains("Alpha"));
assert!(svg.contains("Beta"));
assert!(svg.contains("Gamma"));
}