18.2 The Graph Formatting Protocols

Graph formatting is implemented on top of the basic output recording protocol, using with-new-output-record to specify the appropriate type of output record. For example, format-graph-from-roots first collects all the output that belongs in the graph into a collection of graph node output records by calling generate-graph-nodes. All of the graph node output records are descendents of a single graph output record. During this phase, stream-drawing-p is bound to nil and stream-recording-p is bound to t. When all the output has been generated, the graph layout code (layout-graph-nodes and layout-graph-edges) is called to compute the graph layout. Finally, the graph output record is positioned on the stream at the current text cursor position and then displayed by calling replay on the graph output record. [annotate]

graph-output-record   [Protocol Class]
          

The protocol class that represents a graph; a subclass of output-record. If you want to create a new class that behaves like a graph output record, it should be a subclass of graph-output-record. All instantiable subclasses of graph-output-record must obey the graph output record protocol. [annotate]

[annotate]

graph-output-record-p  object [Protocol Predicate]
          

Returns true if object is a graph output record, otherwise returns false. [annotate]

[annotate]

standard-graph-output-record   [Class]
          

The instantiable class of output record that represents a graph. Its children will be a sequence graph nodes. This is a subclass of graph-output-record. [annotate]

[annotate]

:orientation   [Initarg]
:center-nodes   [Initarg]
:cutoff-depth   [Initarg]
:merge-duplicates   [Initarg]
:generation-separation   [Initarg]
:within-generation-separation   [Initarg]
:hash-table   [Initarg]
          

All the graph output record must handle these seven initargs, which are used to specify, respectively, the orientation, node centering, cutoff depth, merge duplicates, generation and within-generation spacing, and the node hash table of a graph output record. [annotate]

Note: I wonder what the hash table is doing here. [edit]-- Gilbert Baumann 2004-03-19 19:07Z
 

[annotate]

Note:

It seems that these initargs are intended to be passed through from the top-level call to format-graph-from-roots, but I don't see that this is ever stated explicitly.

If that is what is intended, it also seems that FORMAT-GRAPH-FROM-ROOTS should be specified as a function with &allow-other-keys (as is the case in McCLIM), but this is not the case. Is this an omission in the specification, or was that intended?

I have only experimented a little with defining my own graph class, but the current framework does not seem to be well set-up to support colored graphs ("colored" not meant literally, but in the sense of there being different classes of edges and nodes). It seems reasonably easy to specialize how graph nodes could be indicated as of different classes, through the drawing function. But arcs are not so easy, since the only piece of information the drawer has access to is the nodes on either end. This makes it difficult if there can be multiple edges (of different types) between a single pair of vertices.

[edit]-- Robert Goldman (rpgoldman AT real dash time dot com) 2005-05-11 01:59Z
 

define-graph-type  graph-type class [Macro]
          

Defines a new graph type named by the symbol graph-type that is implemented by the class class. class must be a subclass of graph-output-record. Neither of the arguments is evaluated. [annotate]

All CLIM implementations must support graphs of type :tree, :directed-graph (and its synonym :digraph), and :directed-acyclic-graph (and its synonym :dag). [annotate]

[annotate]

graph-root-nodes  graph-record [Generic Function]
          

Returns a sequence of the graph node output records corresponding to the root objects for the graph output record graph-record. [annotate]

[annotate]

(setf graph-root-nodes)  roots graph-record [Generic Function]
          

Sets the root nodes of graph-record to roots. [annotate]

[annotate]

generate-graph-nodes  graph-record stream root-objects object-printer inferior-producer &key duplicate-key duplicate-test [Generic Function]
          

This function is responsible for generating all of the graph node output records of the graph. graph-record is the graph output record, and stream is the output stream. The graph node output records are generating by calling the object printer on the root objects, then (recursively) calling the inferior producer on the root objects and calling the object printer on all inferiors. After all of the graph node output records have been generated, the value of graph-root-nodes of graph-record must be set to be a sequence of the those graph node output records that correspond to the root objects. [annotate]

root-objects, object-printer, inferior-producer, duplicate-key, and duplicate-test are as for format-graph-from-roots. [annotate]

[annotate]

layout-graph-nodes  graph-record stream arc-drawer arc-drawing-options [Generic Function]
          

This function is responsible for laying out the nodes in the graph contained in the output record graph-record. It is called after the graph output has been collected, but before the graph record has been displayed. The method on standard-graph-output-record implements the usual graph layout constraint solver. stream is the stream on which the graph is displayed. [annotate]

Note: Is there a reference somewhere to indicate what "the usual graph layout constraint solver," is? [edit]-- Robert Goldman rpgoldman at real dash time dot com 2005-05-11 02:03Z
 

[annotate]

layout-graph-edges  graph-record stream arc-drawer arc-drawing-options [Generic Function]
          

This function is responsible for laying out the edges in the graph. It is called after the graph nodes have been layed out, but before the graph record has been displayed. The method on standard-graph-output-record simply causes thin lines to be drawn from each node to all of its children. graph-record and stream are as for layout-graph-nodes. [annotate]

[annotate]

graph-node-output-record   [Protocol Class]
          

The protocol class that represents a node in graph; a subclass of output-record. If you want to create a new class that behaves like a graph node output record, it should be a subclass of graph-node-output-record. All instantiable subclasses of graph-node-output-record must obey the graph node output record protocol. [annotate]

[annotate]

graph-node-output-record-p  object [Protocol Predicate]
          

Returns true if object is a graph node output record, otherwise returns false. [annotate]

[annotate]

standard-graph-node-output-record   [Class]
          

The instantiable class of output record that represents a graph node. Its parent will be a graph output record. This is a subclass of graph-node-output-record. [annotate]

[annotate]

graph-node-parents  graph-node-record [Generic Function]
          

Returns a sequence of the graph node output records whose objects are "parents" of the object corresponding to the graph node output record graph-node-record. Note that this is not the same as output-record-parent, since graph-node-parents can return output records that are not the parent records of graph-node-record. [annotate]

[annotate]

(setf graph-node-parents)  parents graph-node-record [Generic Function]
          

Sets the parents of graph-node-record to be parents. parents must be a list of graph node records. [annotate]

[annotate]

graph-node-children  graph-node-record [Generic Function]
          

Returns a sequence of the graph node output records whose objects are "children" of the object corresponding to the graph node output record graph-node-record. Note that this is not the same as output-record-children, since graph-node-children can return output records that are not child records of graph-node-record. [annotate]

[annotate]

(setf graph-node-children)  children graph-node-record [Generic Function]
          

Sets the children of graph-node-record to be children. children must be a list of graph node records. [annotate]

[annotate]

graph-node-object  graph-node-record [Generic Function]
          

Returns the object that corresponds to the graph node output record graph-node-record. It is permissible for this function to work correctly only while inside of the call to format-graph-from-roots. It is unspecified what result will be returned outside of format-graph-from-roots. This restriction is permitted so that CLIM is not required to capture application objects that might have dynamic extent. [annotate]

[annotate]