Skip to main content

ascii_petgraph/
lib.rs

1//! # ascii-petgraph
2//!
3//! A library for visualizing petgraph graphs in terminal UIs using
4//! force-directed physics simulation and ASCII/Unicode box-drawing.
5//!
6//! ## Features
7//!
8//! - Force-directed (spring) layout algorithm with gravity
9//! - Configurable node box styles (single, double, rounded, ASCII)
10//! - Unicode edge routing with arrows
11//! - Ratatui widget integration
12//! - Mutable color API for nodes and edges
13//! - Extension trait for easy use with any petgraph graph type
14//!
15//! ## Quick Start
16//!
17//! ```rust
18//! use petgraph::graph::DiGraph;
19//! use ascii_petgraph::RenderedGraph;
20//!
21//! let mut graph = DiGraph::new();
22//! let a = graph.add_node("Start");
23//! let b = graph.add_node("End");
24//! graph.add_edge(a, b, "transition");
25//!
26//! let mut rendered = RenderedGraph::from_graph(graph);
27//! rendered.run_simulation();
28//!
29//! // Use rendered.widget() with ratatui
30//! ```
31//!
32//! ## Extension Trait
33//!
34//! Import [`AsciiGraphExt`] to add `.to_ascii()` method to any petgraph graph:
35//!
36//! ```rust
37//! use petgraph::graph::DiGraph;
38//! use ascii_petgraph::AsciiGraphExt;
39//!
40//! let mut graph = DiGraph::new();
41//! let a = graph.add_node("A");
42//! let b = graph.add_node("B");
43//! graph.add_edge(a, b, "edge");
44//!
45//! // Extension method on graph!
46//! let mut rendered = graph.to_ascii();
47//! rendered.run_simulation();
48//! ```
49
50pub mod physics;
51pub mod render;
52pub mod style;
53
54mod graph;
55mod ext;
56
57pub use graph::{RenderedGraph, RenderedGraphBuilder};
58pub use ext::AsciiGraphExt;
59pub use render::ScalingMode;
60pub use style::{BoxBorder, EdgeStyle, NodeStyle};