Logo ROOT   6.12/07
Reference Guide
graphstruct.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// \notebook
4 /// Draw a simple graph structure.
5 /// The graph layout is made using graphviz. This macro creates some
6 /// nodes and edges and change a few graphical attributes on some of them.
7 ///
8 /// \macro_image
9 /// \macro_code
10 ///
11 /// \author Olivier Couet
12 
13 TCanvas* graphstruct()
14 {
15  TGraphStruct *gs = new TGraphStruct();
16 
17  // create some nodes and put them in the graph in one go ...
18  TGraphNode *n0 = gs->AddNode("n0","Node 0");
19  TGraphNode *n1 = gs->AddNode("n1","First node");
20  TGraphNode *n2 = gs->AddNode("n2","Second node");
21  TGraphNode *n3 = gs->AddNode("n3","Third node");
22  TGraphNode *n4 = gs->AddNode("n4","Fourth node");
23  TGraphNode *n5 = gs->AddNode("n5","5th node");
24  TGraphNode *n6 = gs->AddNode("n6","Node number six");
25  TGraphNode *n7 = gs->AddNode("n7","Node 7");
26  TGraphNode *n8 = gs->AddNode("n8","Node 8");
27  TGraphNode *n9 = gs->AddNode("n9","Node 9");
28 
29  n4->SetTextSize(0.03);
30  n6->SetTextSize(0.03);
31  n2->SetTextSize(0.04);
32 
33  n3->SetTextFont(132);
34 
35  n0->SetTextColor(kRed);
36 
37  n9->SetFillColor(kRed-10);
38  n0->SetFillColor(kYellow-9);
39  n7->SetFillColor(kViolet-9);
40 
41  // some edges ...
42  gs->AddEdge(n0,n1)->SetLineColor(kRed);
43  TGraphEdge *e06 = gs->AddEdge(n0,n6);
44  e06->SetLineColor(kRed-3);
45  e06->SetLineWidth(4);
46  gs->AddEdge(n1,n7);
47  gs->AddEdge(n4,n6);
48  gs->AddEdge(n3,n9);
49  gs->AddEdge(n6,n8);
50  gs->AddEdge(n7,n2);
51  gs->AddEdge(n8,n3);
52  gs->AddEdge(n2,n3);
53  gs->AddEdge(n9,n0);
54  gs->AddEdge(n1,n4);
55  gs->AddEdge(n1,n6);
56  gs->AddEdge(n2,n5);
57  gs->AddEdge(n3,n6);
58  gs->AddEdge(n4,n5);
59 
60  TCanvas *c = new TCanvas("c","c",800,600);
61  c->SetFillColor(38);
62  gs->Draw();
63  return c;
64 }
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
Definition: Rtypes.h:59
Definition: Rtypes.h:59
The Graph Structure is an interface to the graphviz package.
Definition: TGraphStruct.h:24
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
An edge object connecting two nodes which can be added in a TGraphStruct.
Definition: TGraphEdge.h:25
void AddNode(TGraphNode *node)
Add the node "node" in this TGraphStruct.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
void AddEdge(TGraphEdge *edge)
Add the edge "edge" in this TGraphStruct.
void Draw(Option_t *option="")
Draw the graph.
The Canvas class.
Definition: TCanvas.h:31
A graph node object which can be added in a TGraphStruct.
Definition: TGraphNode.h:27
Definition: Rtypes.h:60
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46