Skip to content

Repository files navigation

Typed Pictures

A CLI and Rust library for drawing typed string diagrams.

cargo install typed-pictures-cli

Usage (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:

NOR gate diagram

The circuit example has three parts:

  • examples/circuit/circuit.hex: the metacat theory and circuit definitions
  • examples/circuit/circuit-generators.json: metadata mapping operations to SVG assets
  • examples/circuit/*.svg: custom generator assets and rendered outputs

Usage (Library)

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.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages