facett-demo/tests/popgraph_look.rs
//! Render the knut-graph demo tabs headless and save PNGs so we can LOOK (the law)
//! before deploying: the 12-label schema (GraphView) + the sampled population force
//! cloud (Graph3D). Run: `cargo test -p facett-demo --test popgraph_look -- --nocapture`
use egui_kittest::Harness;
use facett::graph::GraphView;
use facett::graph3d::{Graph3D, Layout3D};
use facett_core::Facet;
use facett_demo::popgraph;
fn save<F: Facet + 'static>(name: &str, view: F) {
let cell = std::rc::Rc::new(std::cell::RefCell::new(view));
let c2 = cell.clone();
let mut h = Harness::builder().with_size(egui::vec2(800.0, 800.0)).build_ui(move |ui| {
Facet::ui(&mut *c2.borrow_mut(), ui);
});
h.run_steps(8); // let the force layout settle
let img = h.render().expect("render");
let dir = std::env::temp_dir().join("facett-demo");
std::fs::create_dir_all(&dir).ok();
let png = dir.join(format!("popgraph_{name}.png"));
img.save(&png).ok();
eprintln!("[popgraph_look] {name}: wrote {} ({}x{})", png.display(), img.width(), img.height());
}
#[test]
fn render_knut_graph_tabs() {
// graph tab — the 11M-person Swedish graph DB schema.
let schema = GraphView::new(popgraph::schema_scene()).with_title("graph");
save("schema", schema);
// graph3d tab — sampled population force cloud.
let pop = popgraph::population_scene(120, 8, 7);
let g3d = Graph3D::new(
pop.nodes.iter().map(|n| (n.label.clone(), n.color)).collect(),
pop.edges.iter().map(|e| (e.src, e.dst)).collect(),
Layout3D::Force,
)
.with_title("graph3d");
save("population3d", g3d);
}