Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

facett-demo/src/graphgen.rs

//! **Size + generator for the graph tabs** — now the `facett-graphgen` library
//! (lane F, 2026-10-02), re-exported here under its old path so every
//! `crate::graphgen::…` in the demo still holds. It moved so facet-wrapped's
//! `{"generate": …}` data seam (the Streamlit facet demo) builds the SAME graph from the
//! same `(source, size, seed)` as these tabs, through the same functions — one writer.
//!
//! What stays here: the [`GenSummary`] impls of the demo's own tab types (the trait is
//! the library's; the types are the demo's).

pub use facett_graphgen::*;

impl GenSummary for crate::vg_lab_tab::VgLabTab {
    fn gen_summary(&self) -> serde_json::Value {
        let mut j = nav_summary(self.nav());
        j["vglab"] = self.view_json();
        j
    }
}

// falkor's own state carries no per-node array (counts, the distinct labels, the lanes).
impl GenSummary for crate::falkor_tab::FalkorTab {
    fn gen_summary(&self) -> serde_json::Value {
        use facett::Facet;
        self.state_json()
    }
}

impl GenSummary for crate::graphview_tab::GraphviewTab {
    fn gen_summary(&self) -> serde_json::Value {
        self.summary_json()
    }
}

#[cfg(test)]
mod scale_probe {
    use super::*;
    use facett::Facet;

    /// Timing probe (run explicitly: `cargo test --release -p facett-demo --lib
    /// scale_probe -- --ignored --nocapture`): build + full state + summary per tab at 100k.
    #[test]
    #[ignore]
    fn time_the_100k_builds() {
        fn one<C: Facet + GenSummary>(name: &str, gg: &GenGraph, f: BuildFn<C>) {
            let t0 = now_ms();
            let c = f("probe", gg);
            let t1 = now_ms();
            let _ = c.gen_summary();
            let t2 = now_ms();
            eprintln!("  {name}: build {:.0} ms · summary {:.1} ms", t1 - t0, t2 - t1);
        }
        for src in [Source::Gen(GenKind::Community), Source::Gen(GenKind::Crates), Source::Population] {
            let t0 = now_ms();
            let gg = generate(src, 100_000, 1).unwrap();
            eprintln!("{src:?} n={} e={}: gen {:.0} ms", gg.g.n, gg.g.edges.len(), now_ms() - t0);
            one("Graphs", &gg, crate::gen_build::graphs);
            one("lineage", &gg, crate::gen_build::lineage);
            one("decograph", &gg, crate::gen_build::decograph);
            one("graphpan", &gg, crate::gen_build::graphpan);
            one("graph3d", &gg, crate::gen_build::graph3d);
            one("falkor", &gg, crate::gen_build::falkor);
            one("World coderoom", &gg, crate::gen_build::coderoom);
            one("graph", &gg, crate::gen_build::graph);
            one("graphview", &gg, crate::gen_build::graphview);
        }
    }
}