HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulegraphviz-2999.20.2.0Haskell2010

Data.GraphViz

This is the top-level module for the graphviz library. It provides functions to convert Graphs into the Dot language used by the Graphviz suite of programs (as well as a limited ability to perform the reverse operation).

If you wish to construct a Haskell representation of a Dot graph yourself rather than using the conversion functions here, please see the Data.GraphViz.Types module as a starting point for how to do so.

Information about Graphviz and the Dot language can be found at: http://graphviz.org/

  • 9 types
  • 15 values

Conversion from graphs to Dot format.

0 declarations

Specifying parameters.

A GraphvizParams value contains all the information necessary to manipulate Graphs with this library. As such, its components deal with:

  • Whether to treat graphs as being directed or not;

  • Which top-level GlobalAttributes values should be applied;

  • How to define (and name) clusters;

  • How to format clusters, nodes and edges.

Apart from not having to pass multiple values around, another advantage of using GraphvizParams over the previous approach is that there is no distinction between clustering and non-clustering variants of the same functions.

Example usages of GraphvizParams follow:

  • Quickly visualise a graph using the default parameters. Note the usage of nonClusteredParams over defaultParams to avoid type-checking problems with the cluster type.

defaultVis :: (Graph gr) => gr nl el -> DotGraph Node
defaultVis = graphToDot nonClusteredParams
  • As with defaultVis, but determine whether or not the graph is directed or undirected.

checkDirectednessVis :: (Graph gr, Ord el) => gr nl el -> DotGraph Node
checkDirectednessVis = setDirectedness graphToDot nonClusteredParams
  • Clustering nodes based upon whether they are even or odd. We have the option of either constructing a GraphvizParams directly, or using blankParams. Using the latter to avoid setting isDirected:

evenOdd :: (Graph gr, Ord el) => gr Int el -> DotGraph Node
evenOdd = setDirectedness graphToDot params
  where
    params = blankParams { globalAttributes = []
                         , clusterBy        = clustBy
                         , clusterID        = Num . Int
                         , fmtCluster       = clFmt
                         , fmtNode          = const []
                         , fmtEdge          = const []
                         }
    clustBy (n,l) = C (n `mod` 2) $ N (n,l)
    clFmt m = [GraphAttrs [toLabel $ "n == " ++ show m ++ " (mod 2)"]]

For more examples, see the source of dotizeGraph and preview.

datadata GraphvizParams n nl el cl l
#

Defines the parameters used to convert a Graph into a DotRepr.

A value of type GraphvizParams n nl el cl l indicates that the Graph has a node type of n, node labels of type nl, edge labels of type el, corresponding clusters of type cl and after clustering the nodes have a label of type l (which may or may not be the same as nl).

The tuples in the function types represent labelled nodes (for (n,nl) and (n,l)) and labelled edges ((n,n,el); the value (f,t,ftl) is an edge from f to l with a label of ftl). These correspond to LNode and LEdge in FGL graphs.

The clustering in clusterBy can be to arbitrary depth.

Note that the term "cluster" is slightly conflated here: in terms of GraphvizParams values, a cluster is a grouping of nodes; the isDotCluster function lets you specify whether it is a cluster in the Dot sense or just a sub-graph.

Constructors

valuequickParams :: (Labellable nl, Labellable el) => GraphvizParams n nl el () nl
#

Especially useful for quick explorations in ghci, this is a "do what I mean" set of parameters that prints the specified labels of a non-clustered graph.

valuedefaultParams :: GraphvizParams n nl el cl nl
#

A default GraphvizParams value which assumes the graph is directed, contains no clusters and has no Attributes set.

If you wish to have the labels of the nodes to have a different type after applying clusterBy from before clustering, then you will have to specify your own GraphvizParams value from scratch (or use blankParams).

If you use a custom clusterBy function (which if you actually want clusters you should) then you should also override the (nonsensical) default clusterID.

valueblankParams :: GraphvizParams n nl el cl l
#

A GraphvizParams value where every field is set to undefined. This is useful when you have a function that will set some of the values for you (e.g. setDirectedness) but you don't want to bother thinking of default values to set in the meantime. This is especially useful when you are programmatically setting the clustering function (and as such do not know what the types might be).

Specifying clusters.

datadata NodeCluster c a
#

Define into which cluster a particular node belongs. Clusters can be nested to arbitrary depth.

Constructors

Instances1Show

Converting graphs.

valuegraphElemsToDot
  1. :: (Ord cl, Ord n)
  2. => GraphvizParams n nl el cl l
  3. -> [(n, nl)]
  4. -> [(n, n, el)]
  5. -> DotGraph n
#

As with graphToDot, but this allows you to easily convert other graph-like formats to a Dot graph as long as you can get a list of nodes and edges from it.

Pseudo-inverse conversion.

Graph augmentation.

2 declarations

The following functions provide support for passing a Graph through the appropriate GraphvizCommand to augment the Graph by adding positional information, etc.

A CustomAttribute is used to distinguish multiple edges between two nodes from each other.

Note that the reason that most of these functions do not have unsafePerformIO applied to them is because if you set a global Attribute of:

   Start (StartStyle RandomStyle)
  

then it will not necessarily be referentially transparent (ideally, no matter what the seed is, it will still eventually be drawn to the same optimum, but this can't be guaranteed). As such, if you are sure that you're not using such an Attribute, then you should be able to use unsafePerformIO directly in your own code.

Customisable augmentation.

Quick augmentation.

Manual augmentation.

This section allows you to manually augment graphs by providing fine-grained control over the augmentation process (the standard augmentation functions compose these together). Possible reasons for manual augmentation are:

Note that whilst these functions provide you with more control, you must be careful how you use them: if you use the wrong DotRepr for a Graph, then the behaviour of augmentGraph (and all functions that use it) is undefined. The main point is to make sure that the defined DotNode and DotEdge values aren't removed (or their ID values - or the Attributes for the DotEdges - altered) to ensure that it is possible to match up the nodes and edges in the Graph with those in the DotRepr.

datadata EdgeID el
#

Used to augment an edge label with a unique identifier.

Instances3Eq, Ord, Show
  • Eq el => Eq (EdgeID el)Defined in graphviz-2999.20.2.0 · Data.GraphViz
  • Ord el => Ord (EdgeID el)Defined in graphviz-2999.20.2.0 · Data.GraphViz
  • Show el => Show (EdgeID el)Defined in graphviz-2999.20.2.0 · Data.GraphViz
valueaddEdgeIDs :: Graph gr => gr nl el -> gr nl (EdgeID el)
#

Add unique edge identifiers to each label. This is useful for when multiple edges between two nodes need to be distinguished.

valueaugmentGraph
  1. :: (Graph gr, DotRepr dg Node)
  2. => gr nl (EdgeID el)
  3. -> dg Node
  4. -> gr (AttributeNode nl) (AttributeEdge el)
#

Use the Attributes in the provided DotGraph to augment the node and edge labels in the provided Graph. The unique identifiers on the edges are also stripped off.

Please note that the behaviour for this function is undefined if the DotGraph does not come from the original Graph (either by using a conversion function or by passing the result of a conversion function through a GraphvizCommand via the DotOutput or similar).

Utility functions

1 declaration

Re-exporting other modules.

3 declarations
datadata DotGraph n
#

A Dot graph in canonical form.

Constructors

Instances12Functor, DotRepr, PPDotRepr, ParseDotRepr, PrintDotRepr, FromGeneralisedDot, …
datadata DotStatements n
#
Instances7Functor, Eq, Ord, Read, Show, ParseDot, …
datadata DotSubGraph n
#
Instances7Functor, Eq, Ord, Read, Show, ParseDot, …