Catlab.Graphics API
Catlab.Graphics.Graphviz
— Module.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
Catlab.Graphics.Graphviz.pprint
— Method.Pretty-print the Graphviz expression.
Catlab.Graphics.Graphviz.run_graphviz
— Method.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.
Catlab.Graphics.Graphviz.to_graphviz
— Method.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.
Catlab.Graphics.Graphviz.Html
— Type.AST type for Graphviz's "HTML-like" node labels.
The HTML is represented as an atomic string, for now.
Catlab.Graphics.GraphvizWiringDiagrams
— Module.Draw wiring diagrams (aka string diagrams) using Graphviz.
Catlab.Graphics.Graphviz.to_graphviz
— Method.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 digraphdirection=:vertical
: layout direction. Either:vertical
(top to bottom) or:horizontal
(left to right).node_labels=true
: whether to label the nodeslabels=false
: whether to label the edgeslabel_attr=:label
: what kind of edge label to use (iflabels
is true). One of:label
,:xlabel
,:headlabel
, or:taillabel
.port_size="24"
: minimum size of ports on box, in pointsjunction_size="0.05"
: size of junction nodes, in inchesouter_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 wiresgraph_attrs=default_graph_attrs
: top-level graph attributesnode_attrs=default_node_attrs
: top-level node attributesedge_attrs=default_edge_attrs
: top-level edge attributescell_attrs=default_cell_attrs
: main cell attributes in node HTML-like label
Create a label for an edge.
Escape special HTML characters: &, <, >, ", '
Borrowed from HttpCommon package: https://github.com/JuliaWeb/HttpCommon.jl
Graphviz box for a junction.
Graphviz box for a generic box.
Graphviz box for the outer box of a wiring diagram.
Create invisible nodes for the input or output ports of an outer box.
Encode attributes for Graphviz HTML-like labels.
Create "HTML-like" node label for a box.
Create a label for the main content of a box.
Graphviz anchor for port.
Create horizontal "HTML-like" label for the input or output ports of a box.
Create vertical "HTML-like" label for the input or output ports of a box.
Catlab.Graphics.TikZ
— Module.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.
Catlab.Graphics.TikZ.pprint
— Method.Pretty-print the TikZ expression.
Catlab.Graphics.TikZWiringDiagrams
— Module.Draw wiring diagrams (aka string diagrams) using TikZ.
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).
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).
A port on a box in a TikZ wiring diagram.
A wire (edge) in a TikZ wiring diagram.
A bundle of wires in a TikZ wiring diagram.
A graphical representation of an object.
Catlab.Graphics.TikZWiringDiagrams.box
— Method.Create box for a morphism expression.
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
).
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.
Catlab.Graphics.TikZWiringDiagrams.cap
— Method.A cap.
Used to draw unit morphisms in compact closed categories.
Create ports for a circular node.
Cross two wires.
Used to draw braid morphisms in symmatric monoidal categories.
Catlab.Graphics.TikZWiringDiagrams.cup
— Method.A cup.
Used to draw counit morphisms in compact closed categories.
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?
Catlab.Graphics.TikZWiringDiagrams.lines
— Method.Straight lines, used to draw identity morphisms.
Boxes in parallel, used to draw monoidal products.
Catlab.Graphics.TikZWiringDiagrams.rect
— Method.A rectangle, the default style for generators.
Boxes in sequence, used to draw compositions.
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.
A triangle node.
Supports any number of inputs and outputs, but looks best with at most one input and at most one output.
Catlab.Graphics.TikZWiringDiagrams.wires
— Method.Create wires for an object expression.
Default renderers for specific syntax systems.