Expand description
§ascii-petgraph
A library for visualizing petgraph graphs in terminal UIs using force-directed physics simulation and ASCII/Unicode box-drawing.
§Features
- Force-directed (spring) layout algorithm with gravity
- Configurable node box styles (single, double, rounded, ASCII)
- Unicode edge routing with arrows
- Ratatui widget integration
- Mutable color API for nodes and edges
- Extension trait for easy use with any petgraph graph type
§Quick Start
use petgraph::graph::DiGraph;
use ascii_petgraph::RenderedGraph;
let mut graph = DiGraph::new();
let a = graph.add_node("Start");
let b = graph.add_node("End");
graph.add_edge(a, b, "transition");
let mut rendered = RenderedGraph::from_graph(graph);
rendered.run_simulation();
// Use rendered.widget() with ratatui§Extension Trait
Import AsciiGraphExt to add .to_ascii() method to any petgraph graph:
use petgraph::graph::DiGraph;
use ascii_petgraph::AsciiGraphExt;
let mut graph = DiGraph::new();
let a = graph.add_node("A");
let b = graph.add_node("B");
graph.add_edge(a, b, "edge");
// Extension method on graph!
let mut rendered = graph.to_ascii();
rendered.run_simulation();Re-exports§
pub use render::ScalingMode;pub use style::BoxBorder;pub use style::EdgeStyle;pub use style::NodeStyle;
Modules§
- physics
- Force-directed physics simulation for graph layout.
- render
- ASCII/Unicode rendering for graphs.
- style
- Style definitions for nodes and edges.
Structs§
- Rendered
Graph - A rendered graph ready for display in a TUI.
- Rendered
Graph Builder - Builder for RenderedGraph with configuration options.
Traits§
- Ascii
Graph Ext - Extension trait that adds ASCII rendering capabilities to petgraph graphs.