#![warn(missing_docs)]
mod graph;
use std::{collections::HashMap, fmt::Display, hash::Hash};
pub use graph::DirectedGraph;
mod acyclic;
mod grid;
mod formatter;
pub use formatter::{IDFormatter, NodeFormat, ValueFormatter};
mod config;
pub use config::{Color, Config, LineGlyphBuilder, LineGlyphs};
mod levels;
pub fn display<ID, T>(graph: &DirectedGraph<ID, T>, config: &Config<ID, T>)
where
ID: Hash + Eq + Display,
{
fdisplay(graph, config, std::io::stdout())
}
pub fn fdisplay<ID, T, W>(graph: &DirectedGraph<ID, T>, config: &Config<ID, T>, mut dest: W)
where
ID: Hash + Eq + Display,
W: std::io::Write,
{
if graph.is_empty() {
return;
}
let (agraph, reved_edges) = graph.to_acyclic();
let names: HashMap<&ID, String> = agraph
.nodes
.iter()
.map(|(id, value)| (*id, config.formatter.format_node(*id, value)))
.collect();
let levels = levels::levels(&agraph, config, &names);
let grid = grid::Grid::construct(&agraph, levels, reved_edges, config, names);
grid.fdisplay(
config.color_palette.as_ref(),
&config.line_glyphs,
&mut dest,
);
let _ = writeln!(dest);
}