An object containing a libgraph graph and its associated nodes and edges.
.
More...
#include <graph_wrapper.h>
Public Member Functions | |
void | addEdge (const string &source, const string &target) |
Add a new edge. | |
void | addNode (const string &name) |
Add a new node to the graph. | |
void | addNodes (vector< string > &names) |
Add several nodes. | |
void | applyLayout () |
Apply a new layout. | |
void | clearNodes () |
Clear the whole graph. | |
void | freeLayout () |
Free the layout This function should be called before any modifications to the current graph, and the function applyLayout should be called after all modifications are done. | |
GVC_t * | getGVCcontext (void) |
Get the current GVC context. | |
GVGraph (string name, double node_size=50) | |
Construct a Graphviz graph object. | |
void | removeEdge (const pair< string, string > &key) |
Remove a edge. | |
void | removeEdge (const string &source, const string &target) |
Remove a edge. | |
void | removeNode (const string &name) |
Remove a node. | |
Agedge_t * | selectEdge (string &source, string &target) |
Agnode_t * | selectNode (string &name) |
Selects a node. | |
int | setEdgeAttribute (string source, string target, string attribute, string value) |
int | setNodeAttribute (string name, string attribute, string value) |
Sets node attributes. | |
void | setRootNode (const string &name) |
Set a root node for the graph. | |
void | startRender () |
Start render. | |
~GVGraph () | |
Graphviz graph destructor. | |
Static Public Attributes | |
static const double | DotDefaultDPI |
Default DPI value used by dot (which uses points instead of pixels for coordinates). | |
Private Member Functions | |
Agsym_t * | _agedgeattr (string name, string value) |
Set edge attributes. | |
string | _agget (void *object, string attr, string alt=string()) |
Get graph attribute. | |
Agnode_t * | _agnode (string name) |
Low level function to add new nodes. | |
Agsym_t * | _agnodeattr (string name, string value) |
Set node attributes. | |
Agraph_t * | _agopen (string name, int kind) |
Open the graph. | |
int | _agset (void *object, string attr, string value) |
Set attribute. | |
int | _gvLayout (GVC_t *gvc, graph_t *graph, string engine) |
Layout wrapper function. | |
Private Attributes | |
GVC_t * | _context |
GV context main variable. | |
map< pair< string, string > , Agedge_t * > | _edges |
Edge map, used for edge tracking. | |
Agraph_t * | _graph |
Agraph main object. | |
map< string, Agnode_t * > | _nodes |
Node map, used for node tracking. |
An object containing a libgraph graph and its associated nodes and edges.
.
This class is based around the Libgraph and STL containers, maps, vectors and pairs (their applications is a bit crazy and complicated but works fine, try to use a double pair inside a map and check yourself).
For additional information obviously check the Libgraph documentation (i wish you luck, seriously you will need it!).
Definition at line 54 of file graph_wrapper.h.
GVGraph::GVGraph | ( | string | name, | |
double | node_size = 50 | |||
) |
Construct a Graphviz graph object.
name | The name of the graph, must be unique in the application | |
node_size | The size in pixels of each node |
Definition at line 116 of file graph_wrapper.cpp.
GVGraph::~GVGraph | ( | ) |
Graphviz graph destructor.
This function calls gvFreeLayout
, agclose
and gvFreeContext
.
Definition at line 153 of file graph_wrapper.cpp.
Agsym_t * GVGraph::_agedgeattr | ( | string | name, | |
string | value | |||
) | [private] |
Set edge attributes.
Set attributes for all edge
name | name of the attribute | |
value | value of the attribute |
Definition at line 102 of file graph_wrapper.cpp.
string GVGraph::_agget | ( | void * | object, | |
string | attr, | |||
string | alt = string() | |||
) | [private] |
Get graph attribute.
Add an alternative value parameter to the method for getting an object's attribute
object | graph object, this should not be necessary but it is | |
attr | name of the attribute | |
alt | alternative value |
Definition at line 82 of file graph_wrapper.cpp.
Agnode_t * GVGraph::_agnode | ( | string | name | ) | [private] |
Low level function to add new nodes.
Low level function to add new nodes, directly calls agnode
.
name | name of the new node |
Agnode
pointer object Definition at line 106 of file graph_wrapper.cpp.
Agsym_t * GVGraph::_agnodeattr | ( | string | name, | |
string | value | |||
) | [private] |
Set node attributes.
Set attributes for all nodes
name | name of the attribute | |
value | value of the attribute |
Definition at line 97 of file graph_wrapper.cpp.
Agraph_t * GVGraph::_agopen | ( | string | name, | |
int | kind | |||
) | [private] |
Open the graph.
Open the graph by calling agopen
.
name | name of the graph. | |
kind | kind of graph, see the libgraph documentation for details. |
Definition at line 77 of file graph_wrapper.cpp.
int GVGraph::_agset | ( | void * | object, | |
string | attr, | |||
string | value | |||
) | [private] |
Set attribute.
Directly use agsafeset which always works, contrarily to agset.
object | graph, node or edge object | |
attr | name of the attribute | |
value | value of the attribute |
agsafeset
return Definition at line 92 of file graph_wrapper.cpp.
int GVGraph::_gvLayout | ( | GVC_t * | gvc, | |
graph_t * | graph, | |||
string | engine | |||
) | [private] |
Layout wrapper function.
Wrapper for the layout function.
gvc | gv context pointer object | |
graph | graph pointer | |
engine | layout engine |
gvLayout
return value Definition at line 111 of file graph_wrapper.cpp.
void GVGraph::addEdge | ( | const string & | source, | |
const string & | target | |||
) |
Add a new edge.
Add a new edge between source and target if it does not exist.
source | source node for the new edge | |
target | target node for the new edge |
Definition at line 212 of file graph_wrapper.cpp.
void GVGraph::addNode | ( | const string & | name | ) |
Add a new node to the graph.
This function adds a new node to the graph, if a node with the same name already exits it will remove it first.
name | the name of the new node |
Definition at line 160 of file graph_wrapper.cpp.
void GVGraph::addNodes | ( | vector< string > & | names | ) |
Add several nodes.
This function adds a vector of nodes, it will call addNode
on each vector element.
names | stl vector with the names to add |
Definition at line 168 of file graph_wrapper.cpp.
void GVGraph::applyLayout | ( | ) |
Apply a new layout.
This function applies a new layout, for now it will only use the dot
layout algorithm.
Definition at line 242 of file graph_wrapper.cpp.
void GVGraph::clearNodes | ( | ) |
Clear the whole graph.
Clears the whole graph of nodes and edges using the removeNode
function.
Definition at line 193 of file graph_wrapper.cpp.
void GVGraph::freeLayout | ( | ) |
Free the layout This function should be called before any modifications to the current graph, and the function applyLayout should be called after all modifications are done.
Definition at line 237 of file graph_wrapper.cpp.
GVC_t * GVGraph::getGVCcontext | ( | void | ) |
Get the current GVC context.
Obtain the current GVC
context pointer.
Definition at line 72 of file graph_wrapper.cpp.
void GVGraph::removeEdge | ( | const pair< string, string > & | key | ) |
Remove a edge.
Remove the edge between the source and target. This function should not be called directly.
key | pair key for the edge map |
Definition at line 228 of file graph_wrapper.cpp.
void GVGraph::removeEdge | ( | const string & | source, | |
const string & | target | |||
) |
Remove a edge.
Remove the edge between the source and target. This function calls the other removeEdge
function.
source | source node of the edge | |
target | target node of the edge |
Definition at line 223 of file graph_wrapper.cpp.
void GVGraph::removeNode | ( | const string & | name | ) |
Remove a node.
This function will remove a node and all the edges attached to it using the removeEdge
function. This function will change the _nodes map, so don't use it inside a loop using a _nodes iterator, it will change at each iteration.
name | name of the node to remove |
Definition at line 174 of file graph_wrapper.cpp.
Agedge_t * GVGraph::selectEdge | ( | string & | source, | |
string & | target | |||
) |
Definition at line 43 of file graph_wrapper.cpp.
Agnode_t * GVGraph::selectNode | ( | string & | name | ) |
Selects a node.
This function returns the Agnode_t
pointer to a specific node. It is useful when functions require the node pointer for example attribute setting functions.
name | name of the node to select |
Definition at line 34 of file graph_wrapper.cpp.
int GVGraph::setEdgeAttribute | ( | string | source, | |
string | target, | |||
string | attribute, | |||
string | value | |||
) |
Definition at line 60 of file graph_wrapper.cpp.
int GVGraph::setNodeAttribute | ( | string | name, | |
string | attribute, | |||
string | value | |||
) |
Sets node attributes.
Set the value of a node attribute using agsafeset
.
name | name of the node | |
attribute | name of the attribute | |
value | value of the attribute |
Definition at line 53 of file graph_wrapper.cpp.
void GVGraph::setRootNode | ( | const string & | name | ) |
Set a root node for the graph.
Set a root node to start the drawing.
name | name of the node |
Definition at line 206 of file graph_wrapper.cpp.
void GVGraph::startRender | ( | ) |
Start render.
This function starts the render engine using the magnificent xgtk
plug-in. It calls gvRender
.
Definition at line 67 of file graph_wrapper.cpp.
GVC_t* GVGraph::_context [private] |
GV context main variable.
Definition at line 271 of file graph_wrapper.h.
map<pair<string,string>, Agedge_t*> GVGraph::_edges [private] |
Edge map, used for edge tracking.
Definition at line 280 of file graph_wrapper.h.
Agraph_t* GVGraph::_graph [private] |
Agraph main object.
Definition at line 274 of file graph_wrapper.h.
map<string, Agnode_t*> GVGraph::_nodes [private] |
Node map, used for node tracking.
Definition at line 277 of file graph_wrapper.h.
const double GVGraph::DotDefaultDPI [static] |
Default DPI value used by dot (which uses points instead of pixels for coordinates).
Definition at line 58 of file graph_wrapper.h.