Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
graphstruct.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Draw a simple graph structure.

The graph layout is made using graphviz. This macro creates some nodes and edges and change a few graphical attributes on some of them.

TCanvas* graphstruct()
{
#if __has_include("TGraphStruct.h") // handy check on whether gviz was installed
// create some nodes and put them in the graph in one go ...
TGraphNode *n0 = gs->AddNode("n0","Node 0");
TGraphNode *n1 = gs->AddNode("n1","First node");
TGraphNode *n2 = gs->AddNode("n2","Second node");
TGraphNode *n3 = gs->AddNode("n3","Third node");
TGraphNode *n4 = gs->AddNode("n4","Fourth node");
TGraphNode *n5 = gs->AddNode("n5","5th node");
TGraphNode *n6 = gs->AddNode("n6","Node number six");
TGraphNode *n7 = gs->AddNode("n7","Node 7");
TGraphNode *n8 = gs->AddNode("n8","Node 8");
TGraphNode *n9 = gs->AddNode("n9","Node 9");
n4->SetTextSize(0.03);
n6->SetTextSize(0.03);
n2->SetTextSize(0.04);
n3->SetTextFont(132);
n9->SetFillColor(kRed-10);
// some edges ...
gs->AddEdge(n0,n1)->SetLineColor(kRed);
TGraphEdge *e06 = gs->AddEdge(n0,n6);
e06->SetLineColor(kRed-3);
e06->SetLineWidth(4);
gs->AddEdge(n1,n7);
gs->AddEdge(n4,n6);
gs->AddEdge(n3,n9);
gs->AddEdge(n6,n8);
gs->AddEdge(n7,n2);
gs->AddEdge(n8,n3);
gs->AddEdge(n2,n3);
gs->AddEdge(n9,n0);
gs->AddEdge(n1,n4);
gs->AddEdge(n1,n6);
gs->AddEdge(n2,n5);
gs->AddEdge(n3,n6);
gs->AddEdge(n4,n5);
TCanvas *c = new TCanvas("c","c",800,600);
c->SetFillColor(38);
gs->Draw();
return c;
#else
return new TCanvas("c","c",800,600);
#endif
}
#define c(i)
Definition RSha256.hxx:101
@ kRed
Definition Rtypes.h:66
@ kYellow
Definition Rtypes.h:66
@ kViolet
Definition Rtypes.h:67
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:44
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:46
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:47
The Canvas class.
Definition TCanvas.h:23
An edge object connecting two nodes which can be added in a TGraphStruct.
Definition TGraphEdge.h:25
A graph node object which can be added in a TGraphStruct.
Definition TGraphNode.h:27
The Graph Structure is an interface to the graphviz package.
void AddNode(TGraphNode *node)
Add the node "node" in this TGraphStruct.
void Draw(Option_t *option="") override
Draw the graph.
void AddEdge(TGraphEdge *edge)
Add the edge "edge" in this TGraphStruct.
Note
For this to work, ROOT has to be compiled with gviz ON
Author
Olivier Couet

Definition in file graphstruct.C.