Data.GraphViz.Types.Canonical

graphviz-2999.18.1.0: Bindings to Graphviz for graph visualisation.

Copyright | (c) Matthew Sackman, Ivan Lazar Miljenovic
License | 3-Clause BSD-style
Maintainer | Ivan.Miljenovic@gmail.com
Safe Haskell | Safe
Language | Haskell2010

Data.GraphViz.Types.Canonical

Contents

- Sub-components of a `DotGraph`.
- Re-exported from `Data.GraphViz.Types`

Description

A canonical Dot graph requires that within each graph/sub-graph, the statements are in the following order:

- global attributes
- sub-graphs/clusters
- nodes
- edges

This Dot graph representation is ideally suited for converting other data structures to Dot form (especially with the help of `graphElemsToDot` from Data.GraphViz).

If you require arbitrary ordering of statements, then use Data.GraphViz.Types.Generalised.

The sample graph could be implemented (this is actually the result of calling `canonicalise` from Data.GraphViz.Algorithms on the generalised one) as:

    DotGraph { strictGraph = False
             , directedGraph = True
             , graphID = Just (Str "G")
             , graphStatements = DotStmts { attrStmts = []
                                          , subGraphs = [ DotSG { isCluster = True
                                                                , subGraphID = Just (Int 0)
                                                                , subGraphStmts = DotStmts { attrStmts = [ GraphAttrs [ style filled
                                                                                                                      , color LightGray
                                                                                                                      , textLabel "process #1"]
                                                                                                         , NodeAttrs [style filled, color White]]}
                                                                                           , subGraphs = []
                                                                                           , nodeStmts = [ DotNode "a0" []
                                                                                                         , DotNode "a1" []
                                                                                                         , DotNode "a2" []
                                                                                                         , DotNode "a3" []]
                                                                                           , edgeStmts = [ DotEdge "a0" "a1" []
                                                                                                         , DotEdge "a1" "a2" []
                                                                                                         , DotEdge "a2" "a3" []
                                                                                                         , DotEdge "a3" "a0" []]}}
                                                        , DotSG { isCluster = True
                                                                , subGraphID = Just (Int 1)
                                                                , subGraphStmts = DotStmts { attrStmts = [ GraphAttrs [textLabel "process #2", color Blue]
                                                                                                         , NodeAttrs [style filled]]
                                                                                           , subGraphs = []
                                                                                           , nodeStmts = [ DotNode "b0" []
                                                                                                         , DotNode "b1" []
                                                                                                         , DotNode "b2" []
                                                                                                         , DotNode "b3" []]
                                                                                           , edgeStmts = [ DotEdge "b0" "b1" []
                                                                                                         , DotEdge "b1" "b2" []
                                                                                                         , DotEdge "b2" "b3" []]}}]
                                          , nodeStmts = [ DotNode "end" [shape MSquare]
                                                        , DotNode "start" [shape MDiamond]]
                                          , edgeStmts = [ DotEdge "start" "a0" []
                                                        , DotEdge "start" "b0" []
                                                        , DotEdge "a1" "b3" []
                                                        , DotEdge "b2" "a3" []
                                                        , DotEdge "a3" "end" []
                                                        , DotEdge "b3" "end" []]}}

Note that whilst the above graph represents the same Dot graph as specified in Data.GraphViz.Types.Generalised, etc., it may be drawn slightly differently by the various Graphviz tools.

Synopsis

- data DotGraph n = DotGraph {
  - strictGraph :: Bool
  - directedGraph :: Bool
  - graphID :: Maybe GraphID
  - graphStatements :: DotStatements n
  }
- data DotStatements n = DotStmts {
  - attrStmts :: [GlobalAttributes]
  - subGraphs :: [DotSubGraph n]
  - nodeStmts :: [DotNode n]
  - edgeStmts :: [DotEdge n]
  }
- data DotSubGraph n = DotSG {
  - isCluster :: Bool
  - subGraphID :: Maybe GraphID
  - subGraphStmts :: DotStatements n
  }
- data GraphID
  - = Str Text
  - | Num Number
- data GlobalAttributes
  - = GraphAttrs {
    - attrs :: Attributes
    }
  - | NodeAttrs {
    - attrs :: Attributes
    }
  - | EdgeAttrs {
    - attrs :: Attributes
    }
- data DotNode n = DotNode {
  - nodeID :: n
  - nodeAttributes :: Attributes
  }
- data DotEdge n = DotEdge {
  - fromNode :: n
  - toNode :: n
  - edgeAttributes :: Attributes
  }

# Documentation

data DotGraph n

A Dot graph in canonical form.

Constructors

DotGraph |
Fields strictGraph :: Bool If `True`, no multiple edges are drawn. directedGraph :: Bool graphID :: Maybe GraphID graphStatements :: DotStatements n

Instances

Functor DotGraph | Assumed to be an injective mapping function.
(Ord n, PrintDot n, ParseDot n) => PPDotRepr DotGraph n |
(Ord n, ParseDot n) => ParseDotRepr DotGraph n |
(Ord n, PrintDot n) => PrintDotRepr DotGraph n |
Ord n => DotRepr DotGraph n |
Ord n => FromGeneralisedDot DotGraph n |
Eq n => Eq (DotGraph n) |
Ord n => Ord (DotGraph n) |
Read n => Read (DotGraph n) |
Show n => Show (DotGraph n) |
ParseDot n => ParseDot (DotGraph n) |
PrintDot n => PrintDot (DotGraph n) |

# Sub-components of a `DotGraph`.

data DotStatements n

Constructors

DotStmts |
Fields attrStmts :: [GlobalAttributes] subGraphs :: [DotSubGraph n] nodeStmts :: [DotNode n] edgeStmts :: [DotEdge n]

Instances

Functor DotStatements |
Eq n => Eq (DotStatements n) |
Ord n => Ord (DotStatements n) |
Read n => Read (DotStatements n) |
Show n => Show (DotStatements n) |
ParseDot n => ParseDot (DotStatements n) |
PrintDot n => PrintDot (DotStatements n) |

data DotSubGraph n

Constructors

DotSG |
Fields isCluster :: Bool subGraphID :: Maybe GraphID subGraphStmts :: DotStatements n

Instances

Functor DotSubGraph |
Eq n => Eq (DotSubGraph n) |
Ord n => Ord (DotSubGraph n) |
Read n => Read (DotSubGraph n) |
Show n => Show (DotSubGraph n) |
ParseDot n => ParseDot (DotSubGraph n) |
PrintDot n => PrintDot (DotSubGraph n) |

# Re-exported from `Data.GraphViz.Types`

data GraphID

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 Text |
Num Number |

Instances

Eq GraphID |
Ord GraphID |
Read GraphID |
Show GraphID |
ParseDot GraphID |
PrintDot GraphID |

data GlobalAttributes

Represents a list of top-level list of `Attribute`s for the entire graph/sub-graph. Note that `GraphAttrs` also applies to `DotSubGraph`s.

Note that Dot allows a single `Attribute` to be listed 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

Instances

Eq GlobalAttributes |
Ord GlobalAttributes |
Read GlobalAttributes |
Show GlobalAttributes |
ParseDot GlobalAttributes |
PrintDot GlobalAttributes |

data DotNode n

A node in `DotGraph`.

Constructors

DotNode |
Fields nodeID :: n nodeAttributes :: Attributes

Instances

Functor DotNode |
Eq n => Eq (DotNode n) |
Ord n => Ord (DotNode n) |
Read n => Read (DotNode n) |
Show n => Show (DotNode n) |
ParseDot n => ParseDot (DotNode n) |
PrintDot n => PrintDot (DotNode n) |

data DotEdge n

An edge in `DotGraph`.

Constructors

DotEdge |
Fields fromNode :: n toNode :: n edgeAttributes :: Attributes

Instances

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