use ruviz::prelude::*;
fn main() -> Result<()> {
let x: Vec<f64> = (0..20).map(|i| i as f64 * 0.5).collect();
let y: Vec<f64> = x.iter().map(|&xi| xi * xi / 10.0).collect();
let y_upper: Vec<f64> = y.iter().map(|&yi| yi + 1.0).collect();
let y_lower: Vec<f64> = y.iter().map(|&yi| (yi - 1.0).max(0.0)).collect();
let plot = Plot::new()
.line(&x, &y)
.title("Annotations Demo")
.xlabel("X");
#[cfg(feature = "typst-math")]
let plot = plot.ylabel("$Y = X^2 / 10$").typst(true);
#[cfg(not(feature = "typst-math"))]
let plot = plot.ylabel("Y = X^2 / 10");
plot
.annotate(Annotation::text(9.0, 8.0, "Peak region"))
.arrow(4.0, 6.0, 6.0, 3.6)
.hline(5.0)
.vline(5.0)
.fill_between(&x, &y_lower, &y_upper)
.axvspan(2.0, 4.0)
.axhspan(6.0, 8.0)
.save("generated/examples/annotations_demo.png")?;
println!("Annotations demo saved to generated/examples/annotations_demo.png");
Plot::new()
.line(&x, &y)
.title("Text and Arrow Annotations")
.annotate(Annotation::text(5.0, 2.5, "Midpoint"))
.arrow(1.0, 0.5, 3.0, 0.9)
.hline(4.0)
.vline(7.0)
.save("generated/examples/simple_annotations.png")?;
println!("Simple annotations saved to generated/examples/simple_annotations.png");
Ok(())
}