some experiments

This commit is contained in:
2024-05-22 17:43:01 +02:00
parent 49caa60d21
commit 425fcd8544
13 changed files with 14010 additions and 3 deletions
+11
View File
@@ -0,0 +1,11 @@
[package]
name = "egui-graph-viz"
version = "0.1.0"
license = "MIT"
edition = "2021"
[dependencies]
egui = "0.27"
eframe = "0.27"
petgraph = "0.6"
egui_graphs = "0.20.0"
+9
View File
@@ -0,0 +1,9 @@
# Interactive
Modification of the [basic example](https://github.com/blitzarx1/egui_graph/tree/master/examples/basic) which shows how easy it is to enable interactivity.
Try to drag around and select some nodes.
## run
```bash
cargo run --release -p interactive
```
+64
View File
@@ -0,0 +1,64 @@
use eframe::{run_native, App, CreationContext};
use egui::Context;
use egui_graphs::{
DefaultEdgeShape, DefaultNodeShape, Graph, GraphView, SettingsInteraction, SettingsStyle,
};
use petgraph::stable_graph::StableGraph;
pub struct InteractiveApp {
g: Graph<(), ()>,
}
impl InteractiveApp {
fn new(_: &CreationContext<'_>) -> Self {
let g = generate_graph();
Self { g }
}
}
impl App for InteractiveApp {
fn update(&mut self, ctx: &Context, _: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
let interaction_settings = &SettingsInteraction::new()
.with_dragging_enabled(true)
.with_node_clicking_enabled(true)
.with_node_selection_enabled(true)
.with_node_selection_multi_enabled(true)
.with_edge_clicking_enabled(true)
.with_edge_selection_enabled(true)
.with_edge_selection_multi_enabled(true);
let style_settings = &SettingsStyle::new().with_labels_always(true);
ui.add(
&mut GraphView::<_, _, _, _, DefaultNodeShape, DefaultEdgeShape>::new(&mut self.g)
.with_styles(style_settings)
.with_interactions(interaction_settings),
);
});
}
}
fn generate_graph() -> Graph<(), ()> {
let mut g = StableGraph::new();
let a = g.add_node(());
let b = g.add_node(());
let c = g.add_node(());
g.add_edge(a, a, ());
g.add_edge(a, b, ());
g.add_edge(a, b, ());
g.add_edge(b, c, ());
g.add_edge(c, a, ());
Graph::from(&g)
}
fn main() {
let native_options = eframe::NativeOptions::default();
run_native(
"egui_graphs_interactive_demo",
native_options,
Box::new(|cc| Box::new(InteractiveApp::new(cc))),
)
.unwrap();
}