Open Graph Drawing Framework
current version:
v.2012.07 (Sakura)
     

Width and height of a node

Topic

Get to know GraphAttributes, run over all nodes and set the width and height of each node.

Source-Code

#include <ogdf/basic/GraphAttributes.h>
 
using namespace ogdf;
 
int main()
{
  Graph G;
  GraphAttributes GA(G, GraphAttributes::nodeGraphics);
  GA.readGML(G, "input.gml");
 
  node v;
  forall_nodes(v, G)
    GA.width(v) = GA.height(v) = 10.0;
 
  GA.writeGML("output.gml");
 
  return 0;
}

Explanation

We first declare a Graph G. The class Graph does not store any attributes, such as width and heights of nodes; this information is maintained by GraphAttributes. Therefore, we generate an instance GA of GraphAttributes associated to Graph G. The constructor of GraphAttributes allows to select which attributes shall be stored. As we just want to set the width and height of the nodes, we only include nodeGraphics.

GA.readGML(G, “input.gml”) reads a graph from file “input.gml” and stores the graph structure in Graph G while the object of class GraphAttributes GA saves any attribute information the file offers and the GraphAttributes can save. In our example, information to edge colors could not be saved in GA. If the input file does not include information to any attribute GA can store, it will be set to a default value.

forall_nodes(v, G) runs over all nodes in G and addresses them via variable v. A corresponding macro for all edges is available.

GA.width(v) = GA.height(v) = 10.0 sets the width and height of node v to 10.0.

GA.writeGML(“output.gml”) writes all information saved in G and GA to file “output.gml”.

 
tech/howto/widandhei.txt · Last modified: 2010/09/30 10:19 (external edit)
This page is driven by DokuWiki