Agar

<-- Back to AG_Intro.3

SYNOPSIS

#include <agar/core.h>
#include <agar/gui.h>

DESCRIPTION

The AG_Graph widget displays a graph. A graph is composed of vertices (or nodes) and edges that connect pairs of vertices.

Edges may be either directed or undirected. Labels and colors can be associated with edges or vertices.

The AG_Graph widget will attempt to position the vertices in the view in order to minimize the number of edges crossing each other, but this is a NP-complete problem. The user can also move vertices manually, or they can be placed programmatically.

INHERITANCE HIERARCHY

AG_Object(3)-> AG_Widget(3)-> AG_Graph.

INITIALIZATION


AG_Graph * AG_GraphNew (AG_Widget *parent, Uint flags)

void AG_GraphSizeHint (AG_Graph *graph, Uint width, Uint height)


The AG_GraphNew() function allocates, initializes, and attaches a new AG_Graph widget. Acceptable flags include:
AG_GRAPH_NO_MOVEUser cannot move vertices.
AG_GRAPH_NO_SELECTUser cannot select vertices.
AG_GRAPH_NO_MENUSDisable popup menus.
AG_GRAPH_READONLYImplies AG_GRAPH_NO_MOVE, AG_GRAPH_NO_SELECT and AG_GRAPH_NO_MENUS.
AG_GRAPH_HFILLExpand horizontally in parent (equivalent to invoking AG_ExpandHoriz(3)).
AG_GRAPH_VFILLExpand vertically in parent (equivalent to invoking AG_ExpandVert(3)).
AG_GRAPH_EXPANDShorthand for AG_GRAPH_HFILL|AG_GRAPH_VFILL.

The AG_GraphSizeHint() function requests an initial widget size in pixels.

VERTICES


AG_GraphVertex * AG_GraphVertexNew (AG_Graph *graph, void *userPtr)

AG_GraphVertex * AG_GraphVertexFind (AG_Graph *graph, void *userPtr)

void AG_GraphVertexLabel (AG_GraphVertex *vertex, const char *format, ...)

void AG_GraphVertexLabelS (AG_GraphVertex *vertex, const char *text)

void AG_GraphVertexColorLabel (AG_GraphVertex *vertex, Uint8 r, Uint8 g, Uint8 b)

void AG_GraphVertexColorBG (AG_GraphVertex *vertex, Uint8 r, Uint8 g, Uint8 b)

void AG_GraphVertexSize (AG_GraphVertex *vertex, Uint width, Uint height)

void AG_GraphVertexPosition (AG_GraphVertex *vertex, int x, int y)

void AG_GraphVertexPopupMenu (AG_GraphVertex *vertex, AG_PopupMenu *pm)


The AG_GraphVertexNew() function creates a new vertex in the specified graph. userPtr is an optional user pointer to associate with the vertex.

AG_GraphVertexFind() returns the vertex matching the specified user pointer, or NULL if no match exists.

AG_GraphVertexLabel() sets the text label associated with a vertex.

AG_GraphVertexColorLabel() sets the color of the text label. AG_GraphVertexColorBG() sets the background color for the node item.

AG_GraphVertexSize() changes the default size of the node item.

AG_GraphVertexPosition() moves the node item to the given position in the view.

AG_GraphVertexPopupMenu() arranges for the given popup menu to be displayed when the user right clicks on the vertex.

EDGES


AG_GraphEdge * AG_GraphEdgeNew (AG_Graph *graph, AG_GraphVertex *v1, AG_GraphVertex *v2, void *userPtr)

AG_GraphEdge * AG_GraphEdgeFind (AG_Graph *graph, void *userPtr)

void AG_GraphEdgeLabel (AG_GraphEdge *edge, const char *format, ...)

void AG_GraphEdgeLabelS (AG_GraphEdge *edge, const char *text)

void AG_GraphEdgeColorLabel (AG_GraphEdge *edge, Uint8 r, Uint8 g, Uint8 b)

void AG_GraphEdgeColor (AG_GraphEdge *edge, Uint8 r, Uint8 g, Uint8 b)

void AG_GraphEdgePopupMenu (AG_GraphEdge *edge, AG_PopupMenu *menu)


The AG_GraphEdgeNew() function creates a new edge connecting vertices v1 and v2. If the two vertices are already connected by an edge, the function fails and returns NULL. userPtr is an optional user pointer to associated with the edge.

AG_GraphEdgeFind() returns the vertex matching the specified user pointer, or NULL if no match exists.

The AG_GraphEdgeLabel() sets the text label to display along the given edge.

AG_GraphEdgeColorLabel() sets the color of the text label. AG_GraphEdgeColor() sets the color of the line representing the edge. AG_GraphEdgePopupMenu() arranges for the given popup menu to be displayed when the user right clicks on the edge.

EVENTS

The AG_Graph widget generates the following events:
graph-vertex-selected (AG_GraphVertex *vtx)
The specified vertex is now selected.
graph-vertex-unselected (AG_GraphVertex *vtx)
The specified vertex is no longer selected.
graph-edge-selected (AG_GraphEdge *edge)
The specified edge is now selected.
graph-edge-unselected (AG_GraphEdge *edge)
The specified edge is no longer selected.

STRUCTURE DATA

For the AG_Graph object:
int xOffs, yOffs Display offset in pixels.
Uint nvertices Vertex count (read-only).
Uint nedges Edge count (read-only)
TAILQ vertices List of AG_GraphVertex items (read-only)
TAILQ edges List of AG_GraphEdge items (read-only).

For the AG_GraphVertex structure:
int x, y Pixel coordinates of vertex in the graph.
Uint w, h Bounding box for graphical representation of the vertex.
void *userPtr Generic user pointer.
TAILQ edges List of AG_GraphEdge(3) objects connected to this vertex.

For the AG_GraphEdge structure:
AG_GraphVertex *v1, *v2 Vertices connected by edge
void *userPtr User pointer

SEE ALSO

AG_Intro(3), AG_Menu(3), AG_Widget(3), AG_Window(3)

HISTORY

The AG_Graph widget first appeared in Agar 1.3.

Csoft.net ElectronTubeStore.com