DOT Export

Introduction

This document inducts the user of Graph for Scala,
who is interested in visualizing graphs, into how to translate Graph
instances to the
DOT Language. Thus it may be viewed as a supplement of the Core User Guide.

At present DOT import is not supported.

Graph for Scala DOT is supplied as an extra module
(jar). As a rule of thumb, Graph-dot_majorX.minorX.patchX depends on
Graph-core_majorY.minorY.patchY with equaling major and minor versions.
In absence of versions being equal in this sense please refer the actual releases
listed on Download.

The following examples are based on a labeled graph shown on wikipedia,
more specifically at
commutative diagram.

Parameter edgeTransformer

edgeTransformer: Graph[N,E]#EdgeT => Option[(DotGraph, DotEdgeStmt)]

edgeTransformer, as the only obligatory transformer, will be called
for each edge of the graph except for working with hEdgeTransformer.
The caller, toDot, passes an inner edge to it and
edgeTransformer returns either Some tuple of
(DotGraph, DotEdgeStmt) or None.

The first member of the tuple of type DotGraph, must be be either

the DotRootGraph instance passed as the dotRoot
argument to toDot or

any other value of type DotSubGraph. This way you
may assign the edge to a DOT subgraph dynamically. Also, controlled by
the ancestor member of DotSubGraph, you are
free to define any tree structure of DOT subgraphs.

The edge attributes to be included in the DOT graph are determined by
means of the second member of the tuple of type DotEdgeStmt.

It is also possible to return None for specific edges
in order to exclude them from the DOT graph.

Parameter hEdgeTransformer

hEdgeTransformer comes in handy when transforming a hypergraph to the
DOT language. hEdgeTransformer allows to break down each hyperedge to
a sequence of DOT edge statements and thus to overcome the lack of support for hyperedges
in the DOT language. See the diHyper test in
TExport.scala for a simple example.

Parameter cNodeTransformer

The optional transformer argument cNodeTransformer,
with its prefix ‘c’
denoting connected, is called for connected nodes.
This transformer may be used, for example, to assign a list of nodes to
a DOT subgraph like

Parameter iNodeTransformer

The prefix ‘i’ of this second optional transformer
argument denotes isolated. If supplied, iNodeTransformer
is called for each isolated node. Unless your graph is guaranteed to be
connected or you want isolated nodes to be discarded in the DOT graph,
it is necessary to provide this transformer in addition to
edgeTransformer.

Parameter spacing

spacing: Spacing = DefaultSpacing

Finally, the spacing argument allows you to determine the layout
of the resulting DOT graph including indentation, separators and line breaks.

While testing the above code examples in REPL you might have noticed
that toDot's resulting lines were indented by TABs.
The reason for this is that we did not supply an argument different from
DefaultSpacing. For more details see the API Scaladoc.

Working with DOT record shapes

When working with DOT records you may bank on the Record
object. For the usage of this little grammar see def `Colons (':') in node_id's are handled
correctly` in TExport.scala.