How blitzar-tech/egui_graphs works
Project type and purpose
• This is a Rust library workspace (“egui_graphs”) for interactive graph visualization. It publishes a core crate (crates/egui_graphs) and provides two non-published demo crates:
• crates/demo-core (shared logic for native demos via eframe)
• crates/demo-web (WASM web demo via trunk).
• The primary goal is to offer an egui GraphView widget that you drop into your UI to render and interact with a petgraph::Graph.
File structure
• Top-level workspace files: Cargo.toml, .cargo/config.toml, GitHub workflows.
• crates/egui_graphs: library code broken into modules:
• graph.rs, graph_view.rs (the core widget)
• layouts/ (random, hierarchical, force-directed + extras)
• elements/, events/, settings.rs, metadata.rs
• crates/demo-core: shares application logic and assets (JSON graph specs), offering tabs, overlays, UI controls.
• crates/demo-web: minimal web wrapper: index.html, WASM build, uses the core demo logic.
• Config files (build.rs, trunk.toml via .cargo/config.toml, GitHub Actions) orchestrate builds (native, WASM).
README insights
• Emphasizes the GraphView widget as the primary API: ui.add(&mut GraphView::new(&mut graph)).
• Highlights pluggable Layout trait, styling hooks, optional events feature.
• Demonstrates native vs. WASM demo running via eframe or trunk.
Demonstrate the role of GraphView
• It as “Widget: orchestrates layout calculation, drawing, and user interactions.”
• Generic parameters: <Graph, Layout, State> enabling pluggable behavior.
• petgraph::Graph (reads/writes node/edge data)
• Layout trait implementations (invokes layout.apply(&mut model, &mut state))
• Drawers (calls into display.draw_node(), display.draw_edge())
• egui::Context (issues painting commands and receives input events)
• SettingsStyle hooks (for dynamic stroke styling)
• Optional events emitter (sends events back to the host app)