Skip to main content

sim_lib_view_math/
cookbook.rs

1//! Deterministic cookbook builders for math view recipes.
2
3use sim_kernel::Expr;
4
5use crate::{HeatmapData, VIRIDIS_PALETTE, heatmap_view, plot_view};
6
7/// Build the domain-neutral masked heatmap Scene used by the cookbook recipe.
8pub fn heatmap_grid_demo() -> Expr {
9    let caps = sim_lib_view::SurfaceCaps::from_preset("desktop", "cookbook.heatmap")
10        .expect("desktop surface preset exists");
11    let scene = heatmap_view(
12        HeatmapData {
13            rows: 2,
14            cols: 3,
15            values: &[0.0, 0.2, 0.4, 0.6, 0.8, 1.0],
16            valid: &[true, true, false, true, true, true],
17            range: (0.0, 1.0),
18            palette: VIRIDIS_PALETTE,
19            label: "Normalized scalar field",
20            detector: "caller-prepared point samples",
21            advisory: Some("masked cells are unavailable"),
22        },
23        &caps,
24    )
25    .expect("static cookbook heatmap is within the desktop budget");
26    debug_assert!(sim_lib_scene::validate_scene(&scene).is_ok());
27    scene
28}
29
30/// Build the plot Scene used by the cookbook recipe.
31pub fn plot_series_demo() -> Expr {
32    let scene = plot_view("y = x^2", &[(0.0, 0.0), (1.0, 1.0), (2.0, 4.0)]);
33    debug_assert!(sim_lib_scene::validate_scene(&scene).is_ok());
34    scene
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn heatmap_grid_demo_is_a_valid_scene() {
43        sim_lib_scene::validate_scene(&heatmap_grid_demo()).expect("heatmap scene validates");
44    }
45
46    #[test]
47    fn plot_series_demo_is_a_valid_scene() {
48        sim_lib_scene::validate_scene(&plot_series_demo()).expect("plot scene validates");
49    }
50}