graphviz-2999.7.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.
  • 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.
  • 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

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

Functor DotGraph 
Eq a => Eq (DotGraph a) 
Ord a => Ord (DotGraph a) 
Read a => Read (DotGraph a) 
Show a => Show (DotGraph a) 
ParseDot a => ParseDot (DotGraph a) 
PrintDot a => PrintDot (DotGraph 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.

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 is either a singular node, or a cluster containing nodes (or more clusters) within it. At the moment, clusters are not parsed.

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)