Skip to main content

show_demo/
show_demo.rs

1//! Open a figure in a native-webview window. Build with:
2//!
3//!     cargo run --example show_demo --features gui
4//!
5//! On Linux, install `libwebkit2gtk-4.1-dev` first.
6
7use bland::{Figure, PaperSize, Stroke, TitleBlock};
8
9fn main() {
10    let xs: Vec<f64> = (0..=200).map(|i| i as f64 / 20.0).collect();
11    let response: Vec<f64> = xs.iter().map(|t| (-t / 4.0).exp() * t.cos()).collect();
12    let envelope: Vec<f64> = xs.iter().map(|t| (-t / 4.0).exp()).collect();
13
14    Figure::new()
15        .size(PaperSize::A5Landscape)
16        .title("Damped oscillation")
17        .xlabel("t [s]")
18        .ylabel("x(t)")
19        .line(&xs, &response, |s| s.label("response"))
20        .line(&xs, &envelope, |s| s.label("envelope").stroke(Stroke::Dashed))
21        .hline(0.0, |s| s.stroke(Stroke::Dotted))
22        .legend_top_right()
23        .title_block(
24            TitleBlock::new()
25                .project("BLAND Reference")
26                .title("Fig. 1 ยท Damped oscillation")
27                .drawn_by("JM")
28                .date("2026-04-29")
29                .scale("1:1")
30                .sheet("1 of 1")
31                .rev("A"),
32        )
33        .show();
34}