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.Types.Graph

It is sometimes useful to be able to manipulate a Dot graph as an actual graph. This representation lets you do so, using an inductive approach based upon that from FGL (note that DotGraph is not an instance of the FGL classes due to having the wrong kind). Note, however, that the API is not as complete as proper graph implementations.

For purposes of manipulation, all edges are found in the root graph and not in a cluster; as such, having EdgeAttrs in a cluster's GlobalAttributes is redundant.

Printing is achieved via Data.GraphViz.Types.Canonical (using toCanonical) and parsing via Data.GraphViz.Types.Generalised (so any piece of Dot code can be parsed in).

This representation doesn't allow non-cluster sub-graphs. Also, all clusters must have a unique identifier. For those functions (with the exception of DotRepr methods) that take or return a "Maybe GraphID", a value of "Nothing" refers to the root graph; "Just clust" refers to the cluster with the identifier "clust".

You would not typically explicitly create these values, instead converting existing Dot graphs (via fromDotRepr). However, one way of constructing the sample graph would be:

setID (Str "G")
. setStrictness False
. setIsDirected True
. setClusterAttributes (Int 0) [GraphAttrs [style filled, color LightGray, textLabel "process #1"], NodeAttrs [style filled, color White]]
. setClusterAttributes (Int 1) [GraphAttrs [textLabel "process #2", color Blue], NodeAttrs [style filled]]
$ composeList [ Cntxt "a0"    (Just $ Int 0)   []               [("a3",[]),("start",[])] [("a1",[])]
              , Cntxt "a1"    (Just $ Int 0)   []               []                       [("a2",[]),("b3",[])]
              , Cntxt "a2"    (Just $ Int 0)   []               []                       [("a3",[])]
              , Cntxt "a3"    (Just $ Int 0)   []               [("b2",[])]              [("end",[])]
              , Cntxt "b0"    (Just $ Int 1)   []               [("start",[])]           [("b1",[])]
              , Cntxt "b1"    (Just $ Int 1)   []               []                       [("b2",[])]
              , Cntxt "b2"    (Just $ Int 1)   []               []                       [("b3",[])]
              , Cntxt "b3"    (Just $ Int 1)   []               []                       [("end",[])]
              , Cntxt "end"   Nothing          [shape MSquare]  []                       []
              , Cntxt "start" Nothing          [shape MDiamond] []                       []]
  • 5 types
  • 35 values
datadata DotGraph n
#

A Dot graph that allows graph operations on it.

Instances11DotRepr, PPDotRepr, ParseDotRepr, PrintDotRepr, FromGeneralisedDot, Eq, …
datadata 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

Instances6Eq, Ord, Read, Show, ParseDot, PrintDot
  • Eq GraphIDDefined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • Ord GraphIDDefined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • Read GraphIDDefined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • Show GraphIDDefined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • ParseDot GraphIDDefined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • PrintDot GraphIDDefined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
datadata Context n
#

The decomposition of a node from a dot graph. Any loops should be found in successors rather than predecessors. Note also that these are created/consumed as if for directed graphs.

Constructors

Instances4Eq, Ord, Read, Show
  • Eq n => Eq (Context n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Graph
  • Ord n => Ord (Context n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Graph
  • Read n => Read (Context n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Graph
  • Show n => Show (Context n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Graph

Conversions

3 declarations
valuetoCanonical :: DotGraph n -> DotGraph n
#

Convert this DotGraph into canonical form. All edges are found in the outer graph rather than in clusters.

valueunsafeFromCanonical :: Ord n => DotGraph n -> DotGraph n
#

Convert a canonical Dot graph to a graph-based one. This assumes that the canonical graph is the same format as returned by toCanonical. The "unsafeness" is that:

  • All clusters must have a unique identifier (unAnonymise can be used to make sure all clusters have an identifier, but it doesn't ensure uniqueness).

  • All nodes are assumed to be explicitly listed precisely once.

  • Only edges found in the root graph are considered.

If this isn't the case, use fromCanonical instead.

The graphToDot function from Data.GraphViz produces output suitable for this function (assuming all clusters are provided with a unique identifier); graphElemsToDot is suitable if all nodes are specified in the input list (rather than just the edges).

Graph information

12 declarations

Graph construction

13 declarations
value(&) :: Ord n => Context n -> DotGraph n -> DotGraph n
#

Merge the Context into the graph. Assumes that the specified node is not in the graph but that all endpoints in the successors and predecessors (with the exception of loops) are. If the cluster is not present in the graph, then it will be added with no attributes with a parent of the root graph.

Note that & and decompose are not quite inverses, as this function will add in the cluster if it does not yet exist in the graph, but decompose will not delete it.

valueaddNode
  1. :: Ord n
  2. => n
  3. -> Maybe GraphID

    The cluster the node can be found in (Nothing refers to the root graph).

  4. -> Attributes
  5. -> DotGraph n
  6. -> DotGraph n
#

Add a node to the current graph. Merges attributes and edges if the node already exists in the graph.

If the specified cluster does not yet exist in the graph, then it will be added (as a sub-graph of the overall graph and no attributes).

datadata DotNode n
#

A node in DotGraph.

Instances7Functor, Eq, Ord, Read, Show, ParseDot, …
  • Functor DotNodeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • Eq n => Eq (DotNode n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • Ord n => Ord (DotNode n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • Read n => Read (DotNode n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • Show n => Show (DotNode n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • ParseDot n => ParseDot (DotNode n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • PrintDot n => PrintDot (DotNode n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
valueaddEdge :: Ord n => n -> n -> Attributes -> DotGraph n -> DotGraph n
#

Add the specified edge to the graph; assumes both node values are already present in the graph. If the graph is undirected then the order of nodes doesn't matter.

datadata DotEdge n
#

An edge in DotGraph.

Instances7Functor, Eq, Ord, Read, Show, ParseDot, …
  • Functor DotEdgeDefined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • Eq n => Eq (DotEdge n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • Ord n => Ord (DotEdge n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • Read n => Read (DotEdge n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • Show n => Show (DotEdge n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • ParseDot n => ParseDot (DotEdge n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
  • PrintDot n => PrintDot (DotEdge n)Defined in graphviz-2999.20.2.0 · Data.GraphViz.Types.Internal.Common
valueaddCluster
  1. :: GraphID

    The identifier for this cluster.

  2. -> Maybe GraphID

    The parent of this cluster (Nothing refers to the root graph)

  3. -> [GlobalAttributes]
  4. -> DotGraph n
  5. -> DotGraph n
#

Add a new cluster to the graph; throws an error if the cluster already exists. Assumes that it doesn't match the identifier of the overall graph. If the parent cluster doesn't already exist in the graph then it will be added.

Graph deconstruction

9 declarations
valuedecompose :: Ord n => n -> DotGraph n -> Maybe (Context n, DotGraph n)
#

A partial inverse of &, in that if a node exists in a graph then it will be decomposed, but will not remove the cluster that it was in even if it was the only node in that cluster.

valuedecomposeList :: Ord n => DotGraph n -> [Context n]
#

Recursively decompose the Dot graph into a list of contexts such that if (c:cs) = decomposeList dg, then dg = c & composeList cs.

Note that all global attributes are lost, so this is not suitable for representing a Dot graph on its own.

valuedeleteNode :: Ord n => n -> DotGraph n -> DotGraph n
#

Delete the specified node from the graph; returns the original graph if that node isn't present.

valuedeleteCluster :: GraphID -> DotGraph n -> DotGraph n
#

Delete the specified cluster, and makes any clusters or nodes within it be in its root cluster (or the overall graph if required).