4.1.8.4. dg/Printer

class mod.DGPrintData

This class is used to hold extra data about how a specific derivation graph is visualised.

The idea is that in the visualized network each vertex/hyperedge is specified by a pair \((id, dup)\) where \(id\) is the ID of the vertex/hyperedge and \(dup\) is an versioning integer that can be specified in objects of this class.

Initially, each vertex/hyperedge has only one version: duplicate number 0. The duplication is primarily specified via the hyperedges, with the duplication of vertices being induced afterwards. Thus hyperedge duplicates are managed by makeDuplicate() and removeDuplicate(), while the vertex duplicates are managed implicitly by reconnectSource() and reconnectTarget(). In the end, when the data is used for printing, it will be compiled to form the actual duplication data.

__init__(dg)

Construct a data object where all derivations have a single version, duplicate number 0, connected to version 0 of all heads and tails.

Parameters:

dg (DG) – the derivation graph to hold data for.

Raises:

LogicError if not dg.isLocked.

dg

(Read-only) The derivation graph the object holds data for.

makeDuplicate(e, eDup)

Create another version of the given hyperedge and give it the given duplicate number. It will connect to duplicate 0 of all head and tail vertices.

Parameters:
  • e (DG.HyperEdge) – a reference to the derivation to duplicate.

  • eDup (int) – the duplicate number for the new version of the derivation.

Raises:

LogicError if not e.

Raises:

LogicError if e.dg != dg.

Raises:

LogicError if duplicate eDup already exists for e.

removeDuplicate(e, eDup)

Remove the version of the given hyperedge with the given duplicate number.

Parameters:
  • e (DG.HyperEdge) – a reference to the derivation to duplicate.

  • eDup (int) – the duplicate number for the version of the derivation to remove.

Raises:

LogicError if not e.

Raises:

LogicError if e.dg != dg.

Raises:

LogicError if duplicate eDup does not exist for e.

reconnectSource(e, eDup, v, vDupTar)

For the given hyperedge duplicate, reconnect the given source vertex to the given duplicate of that source. If the vertex is a source multiple times, then an arbitrary one of them is reconnected.

Parameters:
  • e (DG.HyperEdge) – a reference to the derivation to reconnect.

  • eDup (int) – the duplicate number of the derivation to reconnect.

  • v (DG.Vertex) – a source vertex to reconnect.

  • vDupTar (int) – the new duplicate number for the source vertex.

Raises:

LogicError if not e.

Raises:

LogicError if e.dg != dg.

Raises:

LogicError if not v.

Raises:

LogicError if v.dg != dg.

Raises:

LogicError if v is not a source vertex of e.

Raises:

LogicError if duplicate eDup does not exist for e.

reconnectTarget(e, eDup, v, vDupTar)

For the given hyperedge duplicate, reconnect the given head to the given duplicate of that head. If the vertex is a head multiple times, then an arbitrary one of them is reconnected.

Parameters:
  • e (DG.HyperEdge) – a reference to the derivation to reconnect.

  • eDup (int) – the duplicate number of the derivation to reconnect.

  • v (DG.Vertex) – a target vertex to reconnect.

  • vDupTar (int) – the new duplicate number for the target vertex.

Raises:

LogicError if not e.

Raises:

LogicError if e.dg != dg.

Raises:

LogicError if not v.

Raises:

LogicError if v.dg != dg.

Raises:

LogicError if v is not a target vertex of e.

Raises:

LogicError if duplicate eDup does not exist for e.

class mod.DGPrinter

This class is used to configure how derivation graphs are visualised, how much is visualised and which extra properties are printed.

graphPrinter

Access the GraphPrinter used when printing images of graphs. Note that assignment to the property copies the argument.

The initial printer has GraphPrinter.enableAll() called, and then indices are removed (GraphPrinter.withIndex set to False).

Type:

GraphPrinter

withShortcutEdges

Control whether hyperedges \((T, H)\) with \(|T| = |H| = 1\) are printed as a simple arrow without the usual rectangle.

Type:

bool

withGraphImages

Control whether each vertex is printed with a image of its graph in it.

Type:

bool

labelsAsLatexMath

Control whether labels on vertices and hyperedges are put inline \(\LaTeX\) math. Specifically, a label label is written as $\mathrm{label'}$, with label' being label with all space characters escaped.

Type:

bool

pushVertexVisible(f)

Add another function or constant controlling the visibility of vertices. All visibility functions must return true for a vertex to be visible.

Parameters:

f (Callable[[DG.Vertex], bool] or bool) – the function or constant to push for specifying vertex visibility.

popVertexVisible()

Remove the last pushed vertex visibility function.

Raises:

LogicError if no callback is left to pop.

pushEdgeVisible(f)

Add another function or constant controlling the visibility of hyperedges. All visibility functions must return true for a hyperedge to be visible.

Parameters:

f (Callable[[DG.HyperEdge], bool] or bool) – the function or constant to push for specifying hyperedge visibility.

popEdgeVisible()

Remove the last pushed hyperedge visibility function.

Raises:

LogicError if no callback is left to pop.

withShortcutEdgesAfterVisibility

Control whether hyperedges are depicted as simple arrows when all but 1 head and tail are hidden.

Type:

bool

vertexLabelSep

The string used as separator between each part of each vertex label.

Type:

str

edgeLabelSep

The string used as separator between each part of each edge label.

Type:

str

pushVertexLabel(f)

Add another function or constant for vertex labelling. The result of this function is added to the end of each label.

Parameters:

f (Callable[[DG.Vertex], str] or str) – the function or constant to push for labelling vertices.

popVertexLabel()

Remove the last pushed vertex labelling function.

Raises:

LogicError if no callback is left to pop.

pushEdgeLabel(f)

Add another function or constant for edge labelling. The result of this function is appended to each label.

Parameters:

f (Callable[[DG.HyperEdge], str] or str) – the function or constant to push for labelling edges.

popEdgeLabel()

Remove the last pushed edge labelling function.

Raises:

LogicError if no callback is left to pop.

withGraphName

Control whether graph names are appended to the vertex labels (see also DGPrinter.pushVertexLabel()).

Type:

bool

withRuleName

Control whether rule names are appended to the edge labels (see also DGPrinter.pushEdgeLabel()).

Type:

bool

withRuleId

Control whether rule IDs are appended to the edge labels (see also DGPrinter.pushEdgeLabel()).

Type:

bool

withInlineGraphs

Control whether graph depictions should be precompiled, or be included inline in the DG figure.

Type:

bool

pushVertexColour(f, extendToEdges=True)

Add another function or constant for colouring vertices. The final colour of a vertex is the result of the first colour function returning a non-empty string. The functions are evaluated in the order they are pushed and the resulting string is used directly as a colour in Tikz. A hyperedge is also coloured if at least one head and one tail can be coloured with a colour for which extendToEdges is True. In this case, the hyperedge (and a subset of the head and tail connectors) is coloured with the first applicable colour. The edge extension of vertex colour takes lower precedence than explicitly added hyperedge colouring functions.

Parameters:
  • f (Callable[[DG.Vertex], str] or str) – the function to push for colouring vertices.

  • extendToEdges (bool) – whether some hyperedges are coloured as well (see above).

popVertexColour()

Remove the last pushed vertex colouring function.

Raises:

LogicError if no callback is left to pop.

pushEdgeColour(f)

Add another function or constant for colouring hyperedges. The final colour of a hyperedge (and all of its head and tail connectors) is the result of the first colour function returning a non-empty string.

Parameters:

f (Callable[[DG.HyperEdge], str] or str) – the function or constant to push for colouring hyperedges.

popEdgeColour()

Remove the last pushed hyperedge colouring function.

Raises:

LogicError if no callback is left to pop.

setRotationOverwrite(f)

Overwrite the rotation set in the nested GraphPrinter. The given function will be used to set the rotation of each printed graph.

Parameters:

f (Callable[[Graph], int] or int) – the constant or the function called on each graph to retrieve the rotation to render it with.

setMirrorOverwrite(f)

Overwrite the mirror set in the nested GraphPrinter. The given function will be used to set the mirror of each printed graph.

Parameters:

f (Callable[[Graph], bool] or bool) – the function called on each graph to retrieve the mirror to render it with.

setImageOverwrite(f)

Overwrite the image generation for graphs depicted in the vertices of the printed derivation graph. For each duplicate of each vertex to be depicted, the given callback is called. It must then return two strings:

  1. Either

    • an empty string if the standard depiction should be used, in which case the second string is ignored, or

    • the filename of the PDF that should be included in the final compiled figure.

  2. Either

    • an empty string if no additional post-processing command is needed, or

    • a string of Bash code which will be inserted in the post-processing instructions. For example, one can write out source code in the callback, and then return a command that compiles that code into the PDF needed by inclusion.

The image overwrite can be removed by calling with None.

Parameters:

f (Callable[[DG.Vertex, int], tuple[str, str]] or None) – the callback to use, or None to remove an existing callback.

graphvizPrefix

The string that will be inserted into generated DOT files, just after the graph declaration.

Type:

str

tikzpictureOption

Access the string that will be inserted into generated Tikz files, in the options for the \tikzpicture macro used for the DG.

Type:

str