graphviz-2999.8.0.0: Graphviz bindings for Haskell.

MaintainerIvan.Miljenovic@gmail.com

Data.GraphViz.Types

Contents

Description

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: http://graphviz.org/doc/info/lang.html

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.
  • If you want any GlobalAttributes in a DotSubGraph and want them to only apply to that DotSubGraph, then you must ensure it does indeed have a valid GraphID.
  • All DotSubGraphs with isCluster = True must have unique subGraphID values (well, only if you want them to be generated sensibly).
  • If eventually outputting to a format such as SVG, then you should make sure that your DotGraph has a graphID, as that is used as the title of the resulting image.
  • 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. If you wish to be able to use an arbitrary ordering, you may wish to use Data.GraphViz.Types.Generalised.
  • 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.

Synopsis

Abstraction from the representation type

class (PrintDot (dg n), ParseDot (dg n)) => DotRepr dg n whereSource

This class is used to provide a common interface to different ways of representing a graph in Dot form.

Methods

graphIsDirected :: dg n -> BoolSource

Is this graph directed?

makeStrict :: dg n -> dg nSource

A strict graph disallows multiple edges.

setID :: GraphID -> dg n -> dg nSource

Set the ID of the graph.

graphNodes :: dg n -> [DotNode n]Source

Return all the DotNodes contained within this DotRepr. There is no requirement for it to return implicitly defined nodes found only within a DotEdge.

graphEdges :: dg n -> [DotEdge n]Source

Return all the DotEdges contained within this DotRepr.

Instances

Printing and parsing a DotRepr.

printDotGraph :: DotRepr dg n => dg n -> StringSource

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

parseDotGraph :: DotRepr dg n => String -> dg nSource

Parse a limited subset of the Dot language to form an instance of DotRepr. Each instance may have its own limitations on what may or may not be parseable Dot code.

Also removes any comments, etc. before parsing.

The overall representation of a graph in Dot format.

data DotGraph a Source

The internal representation of a graph in Dot form.

Constructors

DotGraph 

Fields

strictGraph :: Bool

If True, no multiple edges are drawn.

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

Instances

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.

Instances

Eq a => Eq (DotError a) 
Ord a => Ord (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.

Constructors

Str String 
Int Int 
Dbl Double 
HTML URL 

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.

Constructors

GraphAttrs 

Fields

attrs :: Attributes
 
NodeAttrs 

Fields

attrs :: Attributes
 
EdgeAttrs 

Fields

attrs :: Attributes
 

data DotNode a Source

A node in DotGraph.

Constructors

DotNode 

Instances

Functor DotNode 
Eq a => Eq (DotNode a) 
Ord a => Ord (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.

Instances

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