graphviz-2999.5.1.0: GraphViz bindings for Haskell.




This module defines the overall types and methods that interact with them for the GraphViz library. The specifications are based loosely upon the information available at:

Printing of Dot code is done as strictly as possible, whilst parsing is as permissive as possible. For example, if the types allow it then "2" will be parsed as an Int value. Note that quoting and escaping of String values is done automagically.

A summary of known limitations/differences:

  • When creating GraphID values for graphID and subGraphID, you should ensure that none of them have the same printed value as one of the nodeID values to avoid any possible problems.
  • Whilst DotGraph, etc. are polymorphic in their node type, you should ensure that you use a relatively simple node type (that is, it only covers a single line, etc.).
  • Also, whilst GraphViz allows you to mix the types used for nodes, this library requires/assumes that they are all the same type.
  • DotEdge defines an edge (a, b) (with an edge going from a to b); in Dot parlance the edge has a head at a and a tail at b. Care must be taken when using the related Head* and Tail* Attributes. See the differences section in Data.GraphViz.Attributes for more information.
  • It is common to see multiple edges defined on the one line in Dot (e.g. n1 -> n2 -> n3 means to create a directed edge from n1 to n2 and from n2 to n3). These types of edge definitions are parseable; however, they are converted to singleton edges.
  • Cannot create edges with subgraphs/clusters as one of the end points.
  • When either creating a DotGraph by hand or parsing one, it is possible to specify that directedGraph = d, but DotEdge values with directedEdge = not d.
  • Nodes cannot have Port values.
  • Cannot place items in an arbitrary order: in particular, this means that it is not possible to use the normal GraphViz hack of having graph attributes that do not apply to subgraphs/clusters by listing them after the subgraphs/clusters.
  • The parser will strip out comments and convert multiline strings into a single line string. Pre-processor lines (i.e. those started by #) and string concatenation are not yet supported.

See Data.GraphViz.Attributes for more limitations.


The overall representation of a graph in Dot format.

data DotGraph a Source

The internal representation of a graph in Dot form.




strictGraph :: Bool

If True, no multiple edges are drawn.

directedGraph :: Bool
graphID :: Maybe GraphID
graphStatements :: DotStatements a


Printing and parsing a DotGraph.

printDotGraph :: PrintDot a => DotGraph a -> StringSource

The actual Dot code for a DotGraph. Note that it is expected that parseDotGraph . printDotGraph == id (this might not be true the other way around due to un-parseable components).

parseDotGraph :: ParseDot a => String -> DotGraph aSource

Parse a limited subset of the Dot language to form a DotGraph (that is, the caveats listed in Data.GraphViz.Attributes aside, Dot graphs are parsed if they match the layout of DotGraph).

Also removes any comments, etc. before parsing.

Functions acting on a DotGraph.

setID :: GraphID -> DotGraph a -> DotGraph aSource

Set the ID of the graph.

makeStrict :: DotGraph a -> DotGraph aSource

A strict graph disallows multiple edges.

graphNodes :: DotGraph a -> [DotNode a]Source

Return all the DotNodes contained within this DotGraph. Note that it does not yet return all implicitly defined nodes contained only within DotEdges.

graphEdges :: DotGraph a -> [DotEdge a]Source

Return all the DotEdges contained within this DotGraph.

Reporting of errors in a DotGraph.

data DotError a Source

Used to record invalid Attribute usage. A Just value denotes that it was used in an explicit DotNode or DotEdge usage; Nothing means that it was used in a GlobalAttributes value.


Eq a => Eq (DotError a) 
Read a => Read (DotError a) 
Show a => Show (DotError a) 

isValidGraph :: DotGraph a -> BoolSource

Check if all the Attributes are being used correctly.

graphErrors :: DotGraph a -> [DotError a]Source

Return detectable errors in the DotGraph.

Sub-components of a DotGraph.

data GraphID Source

A polymorphic type that covers all possible ID values allowed by Dot syntax. Note that whilst the ParseDot and PrintDot instances for String will properly take care of the special cases for numbers, they are treated differently here.


Str String 
Int Int 
Dbl Double 

data GlobalAttributes Source

Represents a list of top-level list of Attributes for the entire graph/sub-graph. Note that GraphAttrs also applies to DotSubGraphs.

Note that Dot allows a single Attribute to be listen on a line; if this is the case then when parsing, the type of Attribute it is determined and that type of GlobalAttribute is created.




attrs :: Attributes


attrs :: Attributes


attrs :: Attributes

data DotNode a Source

A node in DotGraph is either a singular node, or a cluster containing nodes (or more clusters) within it. At the moment, clusters are not parsed.




Functor DotNode 
Eq a => Eq (DotNode a) 
Read a => Read (DotNode a) 
Show a => Show (DotNode a) 
ParseDot a => ParseDot (DotNode a) 
PrintDot a => PrintDot (DotNode a) 

data DotEdge a Source

An edge in DotGraph.


Functor DotEdge 
Eq a => Eq (DotEdge a) 
Read a => Read (DotEdge a) 
Show a => Show (DotEdge a) 
ParseDot a => ParseDot (DotEdge a) 
PrintDot a => PrintDot (DotEdge a)