···11use eframe::egui;
22+use egui_graphs::{SettingsInteraction, SettingsNavigation};
33+44+use crate::types::{Filaments, Index};
2536/// The `Filaments Visualizer`, which is an instance of `eframe`, which uses `egui`
44-#[derive(Default)]
57pub struct FilViz {
66- /// example for now
77- text: String,
88+ filaments: Filaments,
89}
9101011impl FilViz {
1112 /// Create a new instance of the `FiLViz`
1212- const fn new(_cc: &eframe::CreationContext<'_>) -> Self {
1313+ fn new(_cc: &eframe::CreationContext<'_>, idx: &Index) -> Self {
1314 // Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_global_style.
1415 // Restore app state using cc.storage (requires the "persistence" feature).
1516 // Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
1617 // for e.g. egui::PaintCallback.
1718 Self {
1818- text: String::new(),
1919+ filaments: Filaments::from(idx),
1920 }
2021 }
21222223 /// Create and run the `FilViz`.
2323- pub fn run() -> color_eyre::Result<()> {
2424+ pub fn run(idx: &Index) -> color_eyre::Result<()> {
2425 let native_options = eframe::NativeOptions::default();
2526 eframe::run_native(
2627 "Filaments Visualizer",
2728 native_options,
2828- Box::new(|cc| Ok(Box::new(Self::new(cc)))),
2929+ Box::new(|cc| Ok(Box::new(Self::new(cc, idx)))),
2930 )?;
30313132 Ok(())
3233 }
3334}
34353636+type L = egui_graphs::LayoutForceDirected<egui_graphs::FruchtermanReingoldWithCenterGravity>;
3737+type S = egui_graphs::FruchtermanReingoldWithCenterGravityState;
3838+3539impl eframe::App for FilViz {
3640 fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
3741 egui::CentralPanel::default().show_inside(ui, |ui| {
3838- ui.heading("Hello World!");
3939- ui.text_edit_singleline(&mut self.text);
4242+ let g = &mut self.filaments.graph;
4343+4444+ let mut view = egui_graphs::GraphView::<_, _, _, _, _, _, S, L>::new(g)
4545+ .with_interactions(
4646+ &SettingsInteraction::new()
4747+ .with_hover_enabled(false)
4848+ .with_dragging_enabled(false)
4949+ .with_node_selection_enabled(false)
5050+ .with_node_selection_multi_enabled(false)
5151+ .with_edge_selection_enabled(false)
5252+ .with_edge_selection_multi_enabled(false),
5353+ )
5454+ .with_navigations(
5555+ &SettingsNavigation::new().with_fit_to_screen_padding(0.5), // .with_zoom_and_pan_enabled(true)
5656+ // .with_fit_to_screen_enabled(false),
5757+ );
5858+5959+ ui.add(&mut view);
40604161 // credits!
4262 ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
+3-1
src/main.rs
···5252 let tui_handle = std::thread::spawn({
5353 // arc stuff
5454 let tui_rt = rt.clone();
5555+ let kh = kh.clone();
55565657 // closure to run the tui
5758 move || -> color_eyre::Result<()> {
···6970 if args.visualizer {
7071 // enter the guard so egui_async works properly
7172 let _rt_guard = rt.enter();
7272- FilViz::run()?;
7373+ let index = rt.block_on(async { kh.read().await.index.clone() });
7474+ FilViz::run(&index)?;
7375 }
74767577 // join on the tui