- Notifications
You must be signed in to change notification settings - Fork43
Interactive graph visualization widget for rust powered by egui and petgraph
License
blitzar-tech/egui_graphs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Graph visualization with rust,petgraph andegui in its DNA.
The project implements a Widget for the egui framework, enabling easy visualization of interactive graphs in rust. The goal is to implement the very basic engine for graph visualization within egui, which can be easily extended and customized for your needs.
- Visualization of any complex graphs;
- Zooming and panning;
- Node and Edge labels;
- Node and edges interactions and events reporting: click, double click, select, drag;
- Style configuration via egui context styles;
- Dark/Light theme support via egui context styles;
- Events reporting to extend the graph functionality by the user handling them;
- Layots and custom layout mechanism;
The project is on track for a stable release v1.0.0. For the moment, breaking releases are very possible.
Please use master branch for the latest updates.
Check thedemo example for the comprehensive overview of the widget possibilities.
In addition to the basic graph display functionality, the project provides a layout mechanism to arrange the nodes in the graph. TheLayout
trait can be implemented by the library user allowing for custom layouts. The following layouts are coming from the box:
- Random layout;
- Hierarchical layout;
- Force-directed layout; (coming soon)
Check thelayouts example.
The source code of the following steps can be found in thebasic example.
First, let's define theBasicApp
struct that will hold the graph.
pubstructBasicApp{g: egui_graphs::Graph,}
Next, implement thenew()
function for theBasicApp
struct.
implBasicApp{fnnew(_:&eframe::CreationContext<'_>) ->Self{let g =generate_graph();Self{g: egui_graphs::Graph::from(&g)}}}
Create a helper function calledgenerate_graph()
. In this example, we create three nodes and three edges.
fngenerate_graph() -> petgraph::StableGraph<(),()>{letmut g = petgraph::StableGraph::new();let a = g.add_node(());let b = g.add_node(());let c = g.add_node(()); g.add_edge(a, b,()); g.add_edge(b, c,()); g.add_edge(c, a,()); g}
Now, lets implement theeframe::App
trait for theBasicApp
. In theupdate()
function, we create aegui::CentralPanel
and add theegui_graphs::GraphView
widget to it.
impl eframe::AppforBasicApp{fnupdate(&mutself,ctx:&egui::Context, _:&mut eframe::Frame){ egui::CentralPanel::default().show(ctx, |ui|{ ui.add(&mut egui_graphs::GraphView::new(&mutself.g));});}}
Finally, run the application using theeframe::run_native()
function.
fnmain(){ eframe::run_native("egui_graphs_basic_demo", eframe::NativeOptions::default(),Box::new(|cc|Ok(Box::new(BasicApp::new(cc)))),).unwrap();}
You can further customize the appearance and behavior of your graph by modifying the settings or adding more nodes and edges as needed.
Can be enabled withevents
feature. Events describe a change made in graph whether it changed zoom level or node dragging.
Combining this feature with custom node draw function allows to implement custom node behavior and drawing according to the events happening.
About
Interactive graph visualization widget for rust powered by egui and petgraph
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.