Catlab.Graphics API

Catlab.Graphics API

AST and pretty printer for Graphviz's DOT language.

References:

  • DOT grammar: http://www.graphviz.org/doc/info/lang.html
  • DOT language guide: http://www.graphviz.org/pdf/dotguide.pdf
source

Pretty-print the Graphviz expression.

source

Run a Graphviz program.

Assumes that Graphviz is installed on the local system and invokes Graphviz through its command-line interface.

For bindings to the Graphviz C API, see the the GraphViz.jl package (https://github.com/Keno/GraphViz.jl). GraphViz.jl is unmaintained at the time of this writing.

source

Convert an attributed graph (MetaGraph) to a Graphviz graph.

This method is usually more convenient than direct AST manipulation for creating Graphviz graphs. It supports graphs that are directed or undirected, simple or multi-edged. For more advanced features, like nested subgraphs, you must use the Graphviz AST directly.

source

AST type for Graphviz's "HTML-like" node labels.

The HTML is represented as an atomic string, for now.

source

Draw wiring diagrams (aka string diagrams) using Graphviz.

source

Render a wiring diagram using Graphviz.

The input f can also be a morphism expression, which is converted into a wiring diagram.

Arguments

  • graph_name="G": name of Graphviz digraph
  • direction=:vertical: layout direction. Either :vertical (top to bottom) or :horizontal (left to right).
  • node_labels=true: whether to label the nodes
  • labels=false: whether to label the edges
  • label_attr=:label: what kind of edge label to use (if labels is true). One of :label, :xlabel, :headlabel, or :taillabel.
  • port_size="24": minimum size of ports on box, in points
  • junction_size="0.05": size of junction nodes, in inches
  • outer_ports=true: whether to display the outer box's input and output ports. If disabled, no incoming or outgoing wires will be shown either!
  • anchor_outer_ports=true: whether to enforce ordering of the outer box's input and output, i.e., ordering of the incoming and outgoing wires
  • graph_attrs=default_graph_attrs: top-level graph attributes
  • node_attrs=default_node_attrs: top-level node attributes
  • edge_attrs=default_edge_attrs: top-level edge attributes
  • cell_attrs=default_cell_attrs: main cell attributes in node HTML-like label
source

Create a label for an edge.

source

Escape special HTML characters: &, <, >, ", '

Borrowed from HttpCommon package: https://github.com/JuliaWeb/HttpCommon.jl

source

Graphviz box for a junction.

source

Graphviz box for a generic box.

source

Graphviz box for the outer box of a wiring diagram.

source

Create invisible nodes for the input or output ports of an outer box.

source

Encode attributes for Graphviz HTML-like labels.

source

Create "HTML-like" node label for a box.

source

Create a label for the main content of a box.

source

Graphviz anchor for port.

source

Create horizontal "HTML-like" label for the input or output ports of a box.

source

Create vertical "HTML-like" label for the input or output ports of a box.

source

AST and pretty printer for TikZ.

This module does not provide bindings to the TikZ LaTeX package. For that, see the TikzPictures.jl package: https://github.com/sisl/TikzPictures.jl

The AST is large but still incomplete! It supports:

  • Nodes (\node) and edges (\draw)
  • Nodes along edges (\draw ... node ...)
  • Graphs (\graph)
  • Matrices (\matrix)
  • Scopes and nested pictures

The AST is adapted from the (also incomplete) BNF grammar for TikZ in TikZit.

source

Pretty-print the TikZ expression.

source

Draw wiring diagrams (aka string diagrams) using TikZ.

source

Draw a wiring diagram in TikZ for the given morphism expression.

The diagram is constructed recursively, mirroring the structure of the formula. This is achieved by nesting TikZ pictures in TikZ nodes recursively–a feature not officially supported by TikZ but that is nonetheless in widespread use.

Warning: Since our implementation uses the remember picture option, LaTeX must be run at least twice to fully render the picture. See (TikZ Manual, Sec 17.13).

source

A box in a TikZ wiring diagram.

A Box is a graphical representation of a morphism, and need not be rendered as a geometric box (rectangle).

source

A port on a box in a TikZ wiring diagram.

source

A wire (edge) in a TikZ wiring diagram.

source

A bundle of wires in a TikZ wiring diagram.

A graphical representation of an object.

source

Create box for a morphism expression.

source

Create ports for a rectangular box.

This mainly involves computing the locations of anchors. The anchors are consistent with the monoidal product (see box_size).

source

Compute the size of a box from the number of its ports.

We use the unique formula consistent with the monoidal product, meaning that the size of a product of generator boxes depends only on the total number of ports, not the number of generators.

source

A cap.

Used to draw unit morphisms in compact closed categories.

source

Create ports for a circular node.

source

Cross two wires.

Used to draw braid morphisms in symmatric monoidal categories.

source

A cup.

Used to draw counit morphisms in compact closed categories.

source

A junction of wires drawn as a circle.

Used to morphisms in internal monoids and comonoids.

Implemented using a small, visible node for the point and a big, invisible node as a spacer. FIXME: Is there a more elegant way to achieve the desired margin?

source

Straight lines, used to draw identity morphisms.

source

Boxes in parallel, used to draw monoidal products.

source

A rectangle, the default style for generators.

source

Boxes in sequence, used to draw compositions.

source

A trapezium node, the default style for generators in dagger categories.

The node content is a nested TikZ picture that contains a single visible node. Nesting pictures even at this level may seem crazy, but it's the only way I know to get a bounding box on the inner node, regardless of its shape, before it's rendered.

source

A triangle node.

Supports any number of inputs and outputs, but looks best with at most one input and at most one output.

source

Create wires for an object expression.

source

Default renderers for specific syntax systems.

source