graphviz-2999.20.0.2: 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 | None
Language | Haskell2010

Data.GraphViz.Algorithms

Contents

- Canonicalisation Options
- Canonicalisation
- Dealing with transitive edges

Description

Defines various algorithms for use on `DotRepr` graphs. These are typically re-implementations of behaviour found in existing Graphviz tools but without the I/O requirement.

Note that one way that these algorithms differ from those found in Graphviz is that the order of clusters is not maintained, which may affect layout in some cases.

Synopsis

- data CanonicaliseOptions = COpts {
  - edgesInClusters :: Bool
  - groupAttributes :: Bool
  }
- defaultCanonOptions :: CanonicaliseOptions
- dotLikeOptions :: CanonicaliseOptions
- canonicalise :: DotRepr dg n => dg n -> DotGraph n
- canonicaliseOptions :: DotRepr dg n => CanonicaliseOptions -> dg n -> DotGraph n
- transitiveReduction :: DotRepr dg n => dg n -> DotGraph n
- transitiveReductionOptions :: DotRepr dg n => CanonicaliseOptions -> dg n -> DotGraph n

# Canonicalisation Options

For simplicity, many algorithms end up using the canonicalisation functions to create the new `DotGraph`. `CanonicaliseOptions` allows you to configure how the output is generated.

data CanonicaliseOptions #

Constructors

COpts |
Fields edgesInClusters :: Bool Place edges in the clusters where their nodes are rather than in the top-level graph. groupAttributes :: Bool Put common `Attributes` as top-level `GlobalAttributes`.

Instances

Eq CanonicaliseOptions # |
Instance details Defined in Data.GraphViz.Algorithms Methods (==) :: CanonicaliseOptions -> CanonicaliseOptions -> Bool # (/=) :: CanonicaliseOptions -> CanonicaliseOptions -> Bool #
Ord CanonicaliseOptions # |
Instance details Defined in Data.GraphViz.Algorithms Methods compare :: CanonicaliseOptions -> CanonicaliseOptions -> Ordering # (<) :: CanonicaliseOptions -> CanonicaliseOptions -> Bool # (<=) :: CanonicaliseOptions -> CanonicaliseOptions -> Bool # (>) :: CanonicaliseOptions -> CanonicaliseOptions -> Bool # (>=) :: CanonicaliseOptions -> CanonicaliseOptions -> Bool # max :: CanonicaliseOptions -> CanonicaliseOptions -> CanonicaliseOptions # min :: CanonicaliseOptions -> CanonicaliseOptions -> CanonicaliseOptions #
Read CanonicaliseOptions # |
Instance details Defined in Data.GraphViz.Algorithms Methods readsPrec :: Int -> ReadS CanonicaliseOptions # readList :: ReadS [CanonicaliseOptions] # readPrec :: ReadPrec CanonicaliseOptions # readListPrec :: ReadPrec [CanonicaliseOptions] #
Show CanonicaliseOptions # |
Instance details Defined in Data.GraphViz.Algorithms Methods showsPrec :: Int -> CanonicaliseOptions -> ShowS # show :: CanonicaliseOptions -> String # showList :: [CanonicaliseOptions] -> ShowS #

defaultCanonOptions :: CanonicaliseOptions #

dotLikeOptions :: CanonicaliseOptions #

Options that are more like how `dot -Tcanon` works.

# Canonicalisation

These functions implement similar functionality to `dot -Tcanon` (i.e. creates a canonical form of any `DotRepr` graph). without requiring IO.

Note that due to implementation specifics the behaviour is not identical; in particular:

- Any specified `Attributes` that equal the defaults are stripped out (unless required to override a previous attribute that doesn't apply here).
- Grouping of attributes (when `'groupAttributes = True'`) is much more conservative; only those node/edge attributes that are common to all nodes and edges within that cluster (and within sub-clusters) are made global.
- Sub-graphs aren't kept, only clusters.
- `ColorScheme` Attributes are removed (as all `Color` values embed any needed color scheme anyway) as the output order of attributes may change (and this matters for the Haskell side of things).

In particular, note that this function will create a single explicit definition for every node in the original graph and place it in the appropriate position in the cluster hierarchy. All edges are found in the deepest cluster that contains both nodes.

canonicalise :: DotRepr dg n => dg n -> DotGraph n #

Canonicalise with some sensible defaults.

canonicaliseOptions :: DotRepr dg n => CanonicaliseOptions -> dg n -> DotGraph n #

As with `canonicalise`, but allow custom `CanonicaliseOptions`.

# Dealing with transitive edges

In large, cluttered graphs, it can often be difficult to see what is happening due to the number of edges being drawn. As such, it is often useful to remove transitive edges from the graph before visualising it.

For example, consider the following Dot graph:

    digraph {
        a -> b;
        a -> c;
        b -> c;
    }

This graph has the transitive edge `a -> c` (as we can reach `c` from `a` via `b`).

Graphviz comes with the `tred` program to perform these transitive reductions. `transitiveReduction` and `transitiveReductionOptions` are pure Haskell re-implementations of `tred` with the following differences:

- `tred` prints a message to stderr if a cycle is detected; these functions do not.
- `tred` preserves the original structure of the graph; these functions use the canonicalisation functions above to create the new graph (rather than re-implement creation functions for each one).

When a graph contains cycles, an arbitrary edge from that cycle is ignored whilst calculating the transitive reduction. Multiple edges are also reduced (such that only the first edge between two nodes is kept).

Note that transitive reduction only makes sense for directed graphs; for undirected graphs these functions are identical to the canonicalisation functions above.

The caveats for the canonicalisation functions also apply.

transitiveReduction :: DotRepr dg n => dg n -> DotGraph n #

transitiveReductionOptions :: DotRepr dg n => CanonicaliseOptions -> dg n -> DotGraph n #