use itertools::Itertools;
use numbat::{
BaseRepresentationFactor, Context, module_importer::FileSystemImporter, resolver::CodeSource,
};
fn main() {
let mut importer = FileSystemImporter::default();
importer.add_path("numbat/modules");
let mut ctx = Context::new(importer);
let _ = ctx.interpret("use all", CodeSource::Internal).unwrap();
println!("digraph G {{");
println!(" layout=fdp;");
println!(" splines=true;");
println!(" rankdir=LR;");
println!(" overlap=false;");
for unit_name in ctx.base_units().sorted() {
println!(" {unit_name} [color=\"#eaea5e\",style=filled,shape=doublecircle]");
}
for (ref unit_name, base_representation) in ctx.unit_representations().map(|(u, b)| {
(
u,
b.0.iter()
.map(|BaseRepresentationFactor(name, exp)| (name.clone(), exp.to_integer()))
.collect::<Vec<_>>(),
)
})
{
let is_base = base_representation
.iter()
.map(|(a, b)| (a, b))
.eq([(unit_name, &1i128)]);
if !is_base {
for (base_factor, _) in base_representation {
println!(" {unit_name} -> {base_factor}");
}
}
}
println!("}}");
}