graphviz-2999.20.2.1: Bindings to Graphviz for graph visualisation.

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

Data.GraphViz.Types.Monadic

Contents

- Creating a generalised DotGraph.
- Adding global attributes.
- Adding items to the graph.
  - Subgraphs and clusters
  - Nodes
  - Edges

Description

This module is based upon the dotgen library by Andy Gill: http://hackage.haskell.org/package/dotgen

It provides a monadic interface for constructing generalised Dot graphs. Note that this does not have an instance for `DotRepr` (e.g. what would be the point of the `fromCanonical` function, as you can't do anything with the result): it is purely for construction purposes. Use the generalised Dot graph instance for printing, etc.

Note that the generalised Dot graph types are not re-exported, in case it causes a clash with other modules you may choose to import.

The example graph in Data.GraphViz.Types can be written as:

    digraph (Str "G") $ do

       cluster (Int 0) $ do
           graphAttrs [style filled, color LightGray]
           nodeAttrs [style filled, color White]
           "a0" --> "a1"
           "a1" --> "a2"
           "a2" --> "a3"
           graphAttrs [textLabel "process #1"]

       cluster (Int 1) $ do
           nodeAttrs [style filled]
           "b0" --> "b1"
           "b1" --> "b2"
           "b2" --> "b3"
           graphAttrs [textLabel "process #2", color Blue]

       "start" --> "a0"
       "start" --> "b0"
       "a1" --> "b3"
       "b2" --> "a3"
       "a3" --> "end"
       "b3" --> "end"

       node "start" [shape MDiamond]
       node "end" [shape MSquare]

Synopsis

- type Dot n = DotM n ()
- data DotM n a
- data GraphID
  - = Str Text
  - | Num Number
- digraph :: GraphID -> DotM n a -> DotGraph n
- digraph' :: DotM n a -> DotGraph n
- graph :: GraphID -> DotM n a -> DotGraph n
- graph' :: DotM n a -> DotGraph n
- graphAttrs :: Attributes -> Dot n
- nodeAttrs :: Attributes -> Dot n
- edgeAttrs :: Attributes -> Dot n
- subgraph :: GraphID -> DotM n a -> Dot n
- anonSubgraph :: DotM n a -> Dot n
- cluster :: GraphID -> DotM n a -> Dot n
- node :: n -> Attributes -> Dot n
- node' :: n -> Dot n
- edge :: n -> n -> Attributes -> Dot n
- (-->) :: n -> n -> Dot n
- (<->) :: n -> n -> Dot n

# Documentation

type Dot n = DotM n () Source #

The monadic representation of a Dot graph.

data DotM n a Source #

The actual monad; as with `Dot` but allows you to return a value within the do-block. The actual implementation is based upon the Writer monad.

#### Instances

Instances details

Applicative (DotM n) Source # |
Instance details Defined in Data.GraphViz.Types.Monadic Methods pure :: a -> DotM n a Source # (<*>) :: DotM n (a -> b) -> DotM n a -> DotM n b Source # liftA2 :: (a -> b -> c) -> DotM n a -> DotM n b -> DotM n c Source # (*>) :: DotM n a -> DotM n b -> DotM n b Source # (<*) :: DotM n a -> DotM n b -> DotM n a Source #
Functor (DotM n) Source # |
Instance details Defined in Data.GraphViz.Types.Monadic Methods fmap :: (a -> b) -> DotM n a -> DotM n b Source # (<$) :: a -> DotM n b -> DotM n a Source #
Monad (DotM n) Source # |
Instance details Defined in Data.GraphViz.Types.Monadic Methods (>>=) :: DotM n a -> (a -> DotM n b) -> DotM n b Source # (>>) :: DotM n a -> DotM n b -> DotM n b Source # return :: a -> DotM n a Source #
MonadFix (DotM n) Source # |
Instance details Defined in Data.GraphViz.Types.Monadic Methods mfix :: (a -> DotM n a) -> DotM n a Source #
Monoid a => Monoid (DotM n a) Source # |
Instance details Defined in Data.GraphViz.Types.Monadic Methods mempty :: DotM n a Source # mappend :: DotM n a -> DotM n a -> DotM n a Source # mconcat :: [DotM n a] -> DotM n a Source #
Semigroup a => Semigroup (DotM n a) Source # |
Instance details Defined in Data.GraphViz.Types.Monadic Methods (<>) :: DotM n a -> DotM n a -> DotM n a Source # sconcat :: NonEmpty (DotM n a) -> DotM n a Source # stimes :: Integral b => b -> DotM n a -> DotM n a Source #

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

#### Instances

Instances details

Read GraphID Source # |
Instance details Defined in Data.GraphViz.Types.Internal.Common Methods readsPrec :: Int -> ReadS GraphID Source # readList :: ReadS [GraphID] Source # readPrec :: ReadPrec GraphID Source # readListPrec :: ReadPrec [GraphID] Source #
Show GraphID Source # |
Instance details Defined in Data.GraphViz.Types.Internal.Common Methods showsPrec :: Int -> GraphID -> ShowS Source # show :: GraphID -> String Source # showList :: [GraphID] -> ShowS Source #
Eq GraphID Source # |
Instance details Defined in Data.GraphViz.Types.Internal.Common Methods (==) :: GraphID -> GraphID -> Bool Source # (/=) :: GraphID -> GraphID -> Bool Source #
Ord GraphID Source # |
Instance details Defined in Data.GraphViz.Types.Internal.Common Methods compare :: GraphID -> GraphID -> Ordering Source # (<) :: GraphID -> GraphID -> Bool Source # (<=) :: GraphID -> GraphID -> Bool Source # (>) :: GraphID -> GraphID -> Bool Source # (>=) :: GraphID -> GraphID -> Bool Source # max :: GraphID -> GraphID -> GraphID Source # min :: GraphID -> GraphID -> GraphID Source #
ParseDot GraphID Source # |
Instance details Defined in Data.GraphViz.Types.Internal.Common Methods parseUnqt :: Parse GraphID Source # parse :: Parse GraphID Source # parseUnqtList :: Parse [GraphID] Source # parseList :: Parse [GraphID] Source #
PrintDot GraphID Source # |
Instance details Defined in Data.GraphViz.Types.Internal.Common Methods unqtDot :: GraphID -> DotCode Source # toDot :: GraphID -> DotCode Source # unqtListToDot :: [GraphID] -> DotCode Source # listToDot :: [GraphID] -> DotCode Source #

# Creating a generalised DotGraph.

digraph :: GraphID -> DotM n a -> DotGraph n Source #

Create a directed dot graph with the specified graph ID.

digraph' :: DotM n a -> DotGraph n Source #

Create a directed dot graph with no graph ID.

graph :: GraphID -> DotM n a -> DotGraph n Source #

Create a undirected dot graph with the specified graph ID.

graph' :: DotM n a -> DotGraph n Source #

Create a undirected dot graph with no graph ID.

# Adding global attributes.

graphAttrs :: Attributes -> Dot n Source #

Add graph/sub-graph/cluster attributes.

nodeAttrs :: Attributes -> Dot n Source #

Add global node attributes.

edgeAttrs :: Attributes -> Dot n Source #

Add global edge attributes

# Adding items to the graph.

## Subgraphs and clusters

subgraph :: GraphID -> DotM n a -> Dot n Source #

Add a named subgraph to the graph.

anonSubgraph :: DotM n a -> Dot n Source #

Add an anonymous subgraph to the graph.

It is highly recommended you use `subgraph` instead.

cluster :: GraphID -> DotM n a -> Dot n Source #

Add a named cluster to the graph.

## Nodes

node :: n -> Attributes -> Dot n Source #

Add a node to the graph.

node' :: n -> Dot n Source #

Add a node with no attributes to the graph.

## Edges

If you wish to use something analogous to Dot's ability to write multiple edges with in-line subgraphs such as:

    {a b c} -> {d e f}

Then you can use `-->` and `<->` in combination with monadic traversal functions such as `traverse_`, `for_`, `mapM_`, `forM_` and `zipWithM_`; for example:

    ("a" -->) `traverse_` ["d", "e", "f"]
    ["a", "b", "c"] `for_` (--> "d")
    zipWithM_ (-->) ["a", "b", "c"] ["d", "e", "f"]

edge :: n -> n -> Attributes -> Dot n Source #

Add an edge to the graph.

(-->) :: n -> n -> Dot n infixr 9 Source #

Add an edge with no attributes.

(<->) :: n -> n -> Dot n infixr 9 Source #

An alias for `-->` to make edges look more undirected.