The GLG Graph Layout Library is a collection of functions implementing the spring embedder graph layout algorithm used for automatic layout of graphs containing nodes connected with edges. The spring embedder algorithm performs a number of iterations optimizing the graph layout and minimizing the number of node intersections. The GLG Graph Layout Demo is an example of an application that creates and automatically lays out a graph containing the connected nodes of a network. The demo's source code may be used as an example of using the Graph Layout module.
As seen in the demo, GLG Graph Layout may be used together with the GLG graphical engine, using GLG to display the graph and its nodes. In this case, the GLG Graphics Builder may be used to define a palette of graphical objects containing icons for the graph's nodes.
The Graph Layout may also be used to lay out non-GLG objects, for example, widgets or controls representing an application's objects. In this case, the application uses the Graph Layout's relative node position output (in the range of 0 to 1) to position an application's objects on the page.
The Graph Layout Component is provided with the GLG Extended API. A Java version of the Graph Layout is provided in the Java version of the Toolkit. This chapter describes the C/C++ version of the Graph Layout Component. The Java version of the GraphLayout class is described in Using the Java version of the GLG Toolkit.
The following macros are defined in the GlgGraphLayout.h file and can be used to access or change data stored in the GlgGraphLayout, GlgGraphNode and GlgGraphEdge structures.
Returns the node type (0-based index used to associate the node with the node icon from the palette).
Returns a pointer to the GlgPoint structure containing the node's display position in GLG coordinates (in the range from -1000 to 1000).
Returns a pointer to the GlgPoint structure containing the node's position in normalized coordinates (in the range from 0 to 1).
Returns a custom GlgObject used to display the node. If the template is NULL, an icon from the palette is used.
Returns the edge type (0-based index used to associate the node with the edge icon from the palette). It is 0 in the current implementation.
Returns a pointer to the GlgCube structure that defines the extent of the graph's drawing, [-800;800] by default.
Returns a group (GlgObject) containing all graph nodes (GlgGraphNode).
Returns a group (GlgObject) containing all graph edges (GlgGraphEdge).
The final "temperature" of the graph (in the range from 0 to 1) defining the end of the layout process, 0.2 by default. A higher value will result in the process finishing faster but with less precision. A lower value will cause the layout process to last longer, trying to produce a finer layout.
To use any of the functions described in this chapter, the application program must include the function definitions from the GLG Graph Layout header file. Use the following line to include these definitions:
#include "GlgGraphLayout.h"The following section describes the interfaces of the GLG Graph Layout Library:
Destroys all internal structures used by the instance of the graph:
void GlgGraphDestroy( GlgGraphLayout graph )Destroys all internal structures used by the Graph Layout module:
void GlgGraphTerminate()Sets the graph's icon palette:
void GlgGraphSetPalette( GlgGraphLayout graph, GlgObject palette_drawing )Specifies the palette to use for the graph.
The palette drawing must contain node icons named Node0, Node1, Node2, etc. Each node must contain a G-type resource named Position, which is used by the graph layout to position the node. The palette must also contain an edge icon (a polygon named Edge), which is used to define the edges' attributes.
Sets the default palette to be used by all graphs:
void GlgGraphSetDefPalette( GlgObject palette_drawing )Resets the default palette to NULL and destroys any stored objects:
void GlgGraphUnloadDefPalette()Loads icons from the palette and creates a GLG drawing to render the graph:
void GlgGraphCreateGraphics( GlgGraphLayout graph, GlgObject viewport)Destroys the graph's drawing and all graphical objects used to render nodes and edges:
void GlgGraphDestroyGraphics( GlgGraphLayout graph )Returns the viewport of the graph's drawing:
GlgObject GlgGraphGetViewport( GlgGraphLayout graph )Performs one iteration of the sprint embedder layout:
GlgBoolean GlgGraphSpringIterate( GlgGraphLayout graph )Updates the display to show the results of the spring layout:
void GlgGraphUpdate( GlgGraphLayout graph )Creates a new node and adds it to the graph:
GlgGraphNode GlgGraphAddNode( GlgGraphLayout graph, GlgObject graphics, long node_type, void * data )Creates a new edge and adds it to the graph:
GlgGraphEdge GlgGraphAddEdge( GlgGraphLayout graph, GlgGraphNode start_node, GlgGraphNode end_node, GlgObject graphics, long edge_type, void * data )Deletes a node from the graph:
void GlgGraphDeleteNode( GlgGraphLayout graph, GlgGraphNode node )Deletes an edge from the graph:
void GlgGraphDeleteEdge( GlgGraphLayout graph, GlgGraphEdge edge )Returns the node position in GLG coordinates (in the range from -1000 to 1000):
void GlgGraphGetNodePosition( GlgGraphLayout graph, GlgGraphNode node, double * x, double * y, double * z );Sets the node position in GLG coordinates (in the range from -1000 to 1000):
void GlgGraphSetNodePosition( GlgGraphLayout graph, GlgGraphNode node, double x, double y, double z );Finds the node object by its graphics:
GlgGraphNode GlgGraphFindNode( GlgGraphLayout graph, GlgObject node_graphics )Finds the edge object by its graphics:
GlgGraphNode GlgGraphFindEdge( GlgGraphLayout graph, GlgObject edge_graphics )A connectivity test which returns True if there is an edge connecting the two specified nodes:
GlgBoolean GlgGraphNodesConnected( GlgGraphNode node1, GlgGraphNode node2 )Forces the graph to continue the layout after it is finished by increasing the temperature of the graph by a small increment:
void GlgGraphIncreaseTemperature( GlgGraphLayout graph, GlgBoolean init )Returns True if the untangling algorithm is enabled:
GlgBoolean GlgGraphGetUntangle( GlgGraphLayout graph )Enables or disables the untangling algorithm:
void GlgGraphGetUntangle( GlgGraphLayout graph, GlgBoolean untangle )Randomly scrambles the graph's nodes:
void GlgGraphScramble( GlgGraphLayout graph )