A CLI and Rust library for drawing typed string diagrams.
cargo install typed-pictures-cli
Using the circuit example in this repository, run
cargo run -q -p typed-pictures-cli -- \
--definition \
--generators examples/circuit/circuit-generators.json \
--no-wire-labels \
examples/circuit/circuit.hex \
nor \
> examples/circuit/nor.svg
To produce the following diagram of a NOR gate:
The circuit example has three parts:
examples/circuit/circuit.hex: the metacat theory and circuit definitionsexamples/circuit/circuit-generators.json: metadata mapping operations to SVG assetsexamples/circuit/*.svg: custom generator assets and rendered outputs
If you already have an OpenHypergraph, provide a renderer for your generators
and turn it into SVG:
use open_hypergraphs::lax::OpenHypergraph;
use typed_pictures::render::render;
use typed_pictures::svg::adaptive_svg::AdaptiveSVG;
use typed_pictures::svg::SVGPicture;
use typed_pictures::types::Operation;
fn render_svg<O, A>(
graph: OpenHypergraph<O, A>,
draw_op: impl Fn(&Operation<O, A>) -> SVGPicture,
) -> Result<String, Box<dyn std::error::Error>>
where
O: Clone + PartialEq,
A: Clone,
{
let picture = render(graph, &AdaptiveSVG, &draw_op)?;
Ok(picture.to_document(16).to_string())
}See typed-pictures/examples for complete examples.