uni-graphs-2.2.1.0: Graphs

Graphs.GraphDisp

Contents

Description

In UniForM we need ways of displaying typed directed graphs. In the original UniForM, it was only possible to use the DaVinci encapsulation for displaying directed graphs. While this is very good, in the new UniForM it is intended to factor out this encapsulation so that it will not be too difficult to replace DaVinci by other graph-drawing package (or variants of DaVinci) for particular graphs. Example alternatives that might be considered: (1) some sort of text-only interface. (2) Windows-style displaying of a tree structure using clickable folders. In this module we present the classes that any such "graph-drawing package" is supposed to implement.

This module is in two parts.

The first part contains the "user-friendly" versions of the functions. For these, it is assumed (as will usually be the case) that there is only one node/nodeType/arc/arcType around for a particular graph. The whole lot is indexed by the GraphAll, which contains ALL the functionality required for accessing the graphs (apart from configuration options). For example, the only daVinci-specific thing you should need to use to write a program which calls daVinci will be the daVinciSort variable.

The second part contains the "user-hateful" versions. All the user-hateful functions have names ending in "Prim". Graph display implementations only have to implement the user-hateful versions. The user-hateful versions should only be of interest to other people if the graph display provides more than one implementation of the NodeClass, NodeTypeClass (or whatever) implementation. One disadvantage to the user of using the user-hateful versions of the functions is that because of all the overloading, you have to put in lots of explicit types, or else get the most hideous type errors.

Configuring things like graph titles, shape of node boxes, menus, and so on should also be implemented, where possible, by graph display interfaces. The various options are documented in GraphConfigure.hs. They should be applied using the Computation.HasConfig interface.

The types which are supposed in various combinations to be instances of the classes are as follows:

graph. This corresponds to one graph display. graphConfig. This is configuration information for a graph. This might be a window title or size for example. graphParms. This is a collection of graphConfig's used to construct a graph.

Nodes and arcs carry values. Thus all the following carry a type parameter. But, for ease of implementation with, for example, DaVinci, the type parameter is required to be an instance of Typeable.

  • node. A value of this type is an actual node in a graph. (Will be an instance of Typeable via Typeable1.)
  • nodeType. Nodes are created with a particular UniForM "type" which is a Haskell value of type nodetype. In fact a graph might conceivably have multiply Haskell types corresponding to node and nodeType, meaning that nodes, or their UniForM types, will be distinguished additionally by the Haskell type system.
  • nodeTypeConfig. Configuration information for a nodeType. This might include how a node with this type is to be displayed graphically. This also includes information on what to do when the node is clicked.
  • nodeTypeParms. A collection of nodeTypeConfig's used to construct a nodeType

Similar constructions for arcs . . . arc. arcType. arcTypeConfig. arcTypeParms.

There are quite a lot of classes. This is partly because of the need to have a separate class for each subset of the type variables which is actually used in the type of a function.

This file is fairly repetitive, mainly because of the need to repeat the configuration machinery over and over again.

The functionality provided in this file is inspired by that provided by DaVinci. However we extend it by allowing nodes to have labels.

This file should be read in conjunction with GraphConfigure, which contains various configuration options to be used for graph objects.

Additional Notes ----------------

  1. At the end of a program using a GraphDisp instance, shutdown should be called. For example, in the case of the DaVinci instance this is required to get rid of the DaVinci and HTk processes.
  2. It is more cumbersome writing the Graph Editor than I would like because the menu code doesn't give you direct access to the node or arc type. Unfortunately doing this would make the classes in this file even more complicated than they are now.

Synopsis

User-Friendly Interface.

You should not need any more than this for drawing graphs.

newtype GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms Source

The graph implementation will provide a value of this type to get you started. For example, for daVinci this is called daVinciSort. However you then need to use it as an argument to newGraph to construct the actual graph.

Constructors

Graph graph 

Instances

Eq graph => Eq (Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms) 
Ord graph => Ord (Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms) 
GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms => Destroyable (Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms) 
GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms => Destructible (Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms) 
GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms => HasDelayer (Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms) 

newGraph :: GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> graphParms -> IO (Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms)Source

Construct a new graph. The input value will be something like DaVinciGraph's value daVinciSort; the resulting graph will be returned.

redraw :: GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> IO ()Source

Redraw the graph. This is needed when you want to show updates.

getMultipleNodes :: GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> (Event (WrappedNode node) -> IO a) -> IO aSource

Take over all interaction on the graph, and perform the given action, supplying it with an event which is activated when the user double-clicks a node. This is helpful when you need an interaction selecting several nodes.

class GraphParms graphParms whereSource

Methods

emptyGraphParms :: graphParmsSource

Instances

GraphParms EmptyGraphParms 

newNode :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> nodeType value -> value -> IO (node value)Source

construct a new node.

setNodeType :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> node value -> nodeType value -> IO ()Source

set a node's type

deleteNode :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> node value -> IO ()Source

delete a node

setNodeFocus :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> node value -> IO ()Source

getNodeValue :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> node value -> IO valueSource

get the value associated with a node

setNodeValue :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> node value -> value -> IO ()Source

set the value associated with a node.

newNodeType :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> nodeTypeParms value -> IO (nodeType value)Source

construct a node type.

class NodeTypeParms nodeTypeParms whereSource

Methods

emptyNodeTypeParms :: Typeable value => nodeTypeParms valueSource

coMapNodeTypeParms :: (Typeable value1, Typeable value2) => (value2 -> value1) -> nodeTypeParms value1 -> nodeTypeParms value2Source

Instances

NodeTypeParms EmptyNodeTypeParms 

newArc :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value, Typeable nodeFromValue, Typeable nodeToValue) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> arcType value -> value -> node nodeFromValue -> node nodeToValue -> IO (arc value)Source

construct a new arc.

data WrappedNode node Source

Constructors

forall value . Typeable value => WrappedNode (node value) 

newArcListDrawer :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value, Typeable nodeFromValue) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> node nodeFromValue -> ListDrawer (arcType value, value, WrappedNode node) (arc value)Source

Given a node, construct a ListDrawer which can be used as a way of drawing ordered sets of out-arcs from that node. (NB. At the moment daVinci does not do this properly, but that is daVinci's fault, not mine.)

deleteArc :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> arc value -> IO ()Source

delete an arc

setArcValue :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> arc value -> value -> IO ()Source

set the value associated with an arc

setArcType :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> arc value -> arcType value -> IO ()Source

getArcValue :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> arc value -> IO valueSource

get the value associated with an arc

newArcType :: (GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms, Typeable value) => Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms -> arcTypeParms value -> IO (arcType value)Source

create a new arc type

class ArcTypeParms arcTypeParms whereSource

Methods

emptyArcTypeParms :: Typeable value => arcTypeParms valueSource

invisibleArcTypeParms :: Typeable value => arcTypeParms valueSource

coMapArcTypeParms :: (Typeable value1, Typeable value2) => (value2 -> value1) -> arcTypeParms value1 -> arcTypeParms value2Source

Instances

ArcTypeParms EmptyArcTypeParms 

class Eq1 takesParm whereSource

Methods

eq1 :: takesParm value1 -> takesParm value1 -> BoolSource

Instances

Eq1 EmptyArcType 
Eq1 EmptyArc 
Eq1 EmptyNode 

class Eq1 takesParm => Ord1 takesParm whereSource

Methods

compare1 :: takesParm value1 -> takesParm value1 -> OrderingSource

Instances

Ord1 EmptyArcType 
Ord1 EmptyArc 
Ord1 EmptyNode 

User-Hateful Interface

This is only needed by people wanting to implement new implementations of the interface.

class (GraphClass graph, NewGraph graph graphParms, GraphParms graphParms, NewNode graph node nodeType, DeleteNode graph node, SetNodeFocus graph node, NodeClass node, Typeable1 node, NodeTypeClass nodeType, NewNodeType graph nodeType nodeTypeParms, NodeTypeParms nodeTypeParms, NewArc graph node node arc arcType, SetArcType graph arc arcType, DeleteArc graph arc, ArcClass arc, Typeable1 arc, ArcTypeClass arcType, NewArcType graph arcType arcTypeParms) => GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms whereSource

Methods

displaySort :: Graph graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParmsSource

Instances

(GraphClass graph, NewGraph graph graphParms, GraphParms graphParms, NewNode graph node nodeType, DeleteNode graph node, SetNodeFocus graph node, NodeClass node, NodeTypeClass nodeType, NewNodeType graph nodeType nodeTypeParms, NodeTypeParms nodeTypeParms, NewArc graph node node arc arcType, SetArcType graph arc arcType, DeleteArc graph arc, ArcClass arc, ArcTypeClass arcType, NewArcType graph arcType arcTypeParms) => GraphAll graph graphParms node nodeType nodeTypeParms arc arcType arcTypeParms 

class (Destructible graph, Ord graph, Typeable graph, HasDelayer graph) => GraphClass graph whereSource

Methods

redrawPrim :: graph -> IO ()Source

Instances

GraphClass EmptyGraph 

class (GraphClass graph, GraphParms graphParms) => NewGraph graph graphParms whereSource

Methods

newGraphPrim :: graphParms -> IO graphSource

Instances

NewGraph EmptyGraph EmptyGraphParms 

class (GraphClass graph, NodeClass node, NodeTypeClass nodeType) => NewNode graph node nodeType whereSource

Methods

newNodePrim :: Typeable value => graph -> nodeType value -> value -> IO (node value)Source

setNodeTypePrim :: Typeable value => graph -> node value -> nodeType value -> IO ()Source

Instances

NewNode EmptyGraph EmptyNode EmptyNodeType 

class (GraphClass graph, NodeClass node) => DeleteNode graph node whereSource

Methods

deleteNodePrim :: Typeable value => graph -> node value -> IO ()Source

getNodeValuePrim :: Typeable value => graph -> node value -> IO valueSource

setNodeValuePrim :: Typeable value => graph -> node value -> value -> IO ()Source

getMultipleNodesPrim :: graph -> (Event (WrappedNode node) -> IO a) -> IO aSource

Instances

DeleteNode EmptyGraph EmptyNode 

class (GraphClass graph, NodeClass node) => SetNodeFocus graph node whereSource

Methods

setNodeFocusPrim :: Typeable value => graph -> node value -> IO ()Source

Instances

SetNodeFocus EmptyGraph EmptyNode 

class (Typeable1 node, Ord1 node) => NodeClass node Source

Instances

NodeClass EmptyNode 

class Typeable1 nodeType => NodeTypeClass nodeType Source

Instances

NodeTypeClass EmptyNodeType 

class (GraphClass graph, NodeTypeClass nodeType, NodeTypeParms nodeTypeParms) => NewNodeType graph nodeType nodeTypeParms whereSource

Methods

newNodeTypePrim :: Typeable value => graph -> nodeTypeParms value -> IO (nodeType value)Source

Instances

NewNodeType EmptyGraph EmptyNodeType EmptyNodeTypeParms 

class (GraphClass graph, NodeClass nodeFrom, NodeClass nodeTo, ArcClass arc, ArcTypeClass arcType) => NewArc graph nodeFrom nodeTo arc arcType whereSource

Methods

newArcPrim :: (Typeable value, Typeable nodeFromValue, Typeable nodeToValue) => graph -> arcType value -> value -> nodeFrom nodeFromValue -> nodeTo nodeToValue -> IO (arc value)Source

newArcListDrawerPrim :: (Typeable value, Typeable nodeFromValue) => graph -> nodeFrom nodeFromValue -> ListDrawer (arcType value, value, WrappedNode nodeTo) (arc value)Source

Instances

NewArc EmptyGraph EmptyNode EmptyNode EmptyArc EmptyArcType 

class (ArcClass arc, ArcTypeClass arcType) => SetArcType graph arc arcType whereSource

Methods

setArcTypePrim :: Typeable value => graph -> arc value -> arcType value -> IO ()Source

Instances

SetArcType EmptyGraph EmptyArc EmptyArcType 

class (GraphClass graph, ArcClass arc) => DeleteArc graph arc whereSource

Methods

deleteArcPrim :: Typeable value => graph -> arc value -> IO ()Source

setArcValuePrim :: Typeable value => graph -> arc value -> value -> IO ()Source

getArcValuePrim :: Typeable value => graph -> arc value -> IO valueSource

Instances

DeleteArc EmptyGraph EmptyArc 

class (Typeable1 arc, Ord1 arc) => ArcClass arc Source

Instances

ArcClass EmptyArc 

class (Typeable1 arcType, Ord1 arcType) => ArcTypeClass arcType whereSource

Methods

invisibleArcType :: Typeable value => arcType valueSource

Instances

ArcTypeClass EmptyArcType 

class (GraphClass graph, ArcTypeClass arcType, ArcTypeParms arcTypeParms) => NewArcType graph arcType arcTypeParms whereSource

Methods

newArcTypePrim :: Typeable value => graph -> arcTypeParms value -> IO (arcType value)Source

Instances

NewArcType EmptyGraph EmptyArcType EmptyArcTypeParms