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()
andremoveDuplicate()
, while the vertex duplicates are managed implicitly byreconnectSource()
andreconnectTarget()
. 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
ifnot 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
ifnot e
.- Raises:
LogicError
ife.dg != dg
.- Raises:
LogicError
if duplicateeDup
already exists fore
.
- 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
ifnot e
.- Raises:
LogicError
ife.dg != dg
.- Raises:
LogicError
if duplicateeDup
does not exist fore
.
- 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
ifnot e
.- Raises:
LogicError
ife.dg != dg
.- Raises:
LogicError
ifnot v
.- Raises:
LogicError
ifv.dg != dg
.- Raises:
LogicError
ifv
is not a source vertex ofe
.- Raises:
LogicError
if duplicateeDup
does not exist fore
.
- 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
ifnot e
.- Raises:
LogicError
ife.dg != dg
.- Raises:
LogicError
ifnot v
.- Raises:
LogicError
ifv.dg != dg
.- Raises:
LogicError
ifv
is not a target vertex ofe
.- Raises:
LogicError
if duplicateeDup
does not exist fore
.
- 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 toFalse
).- Type:
- withShortcutEdges¶
Control whether hyperedges \((T, H)\) with \(|T| = |H| = 1\) are printed as a simple arrow without the usual rectangle.
- Type:
- labelsAsLatexMath¶
Control whether labels on vertices and hyperedges are put inline \(\LaTeX\) math. Specifically, a label
label
is written as$\mathrm{label'}$
, withlabel'
beinglabel
with all space characters escaped.- Type:
- pushVertexVisible(f)¶
Add another function or constant controlling the visibility of vertices. All visibility functions must return
true
for a vertex to be visible.
- 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:
- pushVertexLabel(f)¶
Add another function or constant for vertex labelling. The result of this function is added to the end of each label.
- 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:
- withRuleName¶
Control whether rule names are appended to the edge labels (see also
DGPrinter.pushEdgeLabel()
).- Type:
- withRuleId¶
Control whether rule IDs are appended to the edge labels (see also
DGPrinter.pushEdgeLabel()
).- Type:
- withInlineGraphs¶
Control whether graph depictions should be precompiled, or be included inline in the DG figure.
- Type:
- 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
isTrue
. 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.
- 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.
- setMirrorOverwrite(f)¶
Overwrite the mirror set in the nested
GraphPrinter
. The given function will be used to set the mirror of each printed graph.
- 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:
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.
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
.
- graphvizPrefix¶
The string that will be inserted into generated DOT files, just after the graph declaration.
- Type: