ROOT » GRAF2D » GVIZ » TGraphStruct

class TGraphStruct: public TObject


Graph Structure class

The Graph Structure is an interface to the graphviz package.

The graphviz package is a graph visualization system. This interface consists in three classes:

  1. TGraphStruct: holds the graph structure. It uses the graphiz library to layout the graphs and the ROOT graphics to paint them.
  2. TGraphNode: Is a graph node object which can be added in a TGraphStruct.
  3. TGraphEdge: Is an edge object connecting two nodes which can be added in a TGraphStruct.
output of html600/MACRO_TGraphStruct_1.gif
// 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.
// Author: Olivier Couet
{
   TGraphStruct *gs = new TGraphStruct();

   // 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);

   n0->SetTextColor(kRed);

   n9->SetFillColor(kRed-10);
   n0->SetFillColor(kYellow-9);
   n7->SetFillColor(kViolet-9);

   // 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;
}
A graph structure can be dumped into a "dot" file using DumpAsDotFile.
 

Function Members (Methods)

public:
virtual~TGraphStruct()
voidTObject::AbstractMethod(const char* method) const
voidAddEdge(TGraphEdge* edge)
TGraphEdge*AddEdge(TGraphNode* n1, TGraphNode* n2)
voidAddNode(TGraphNode* node)
TGraphNode*AddNode(const char* name, const char* title = "")
virtual voidTObject::AppendPad(Option_t* option = "")
virtual voidTObject::Browse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTObject::Clear(Option_t* = "")
virtual TObject*TObject::Clone(const char* newname = "") const
virtual Int_tTObject::Compare(const TObject* obj) const
virtual voidTObject::Copy(TObject& object) const
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidDraw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTObject::Dump() constMENU
voidDumpAsDotFile(const char* filename)
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual const char*TObject::GetIconName() const
TList*GetListOfEdges() const
TList*GetListOfNodes() const
virtual const char*TObject::GetName() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
virtual const char*TObject::GetTitle() const
virtual UInt_tTObject::GetUniqueID() const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTObject::Hash() const
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
Bool_tTObject::IsOnHeap() const
virtual Bool_tTObject::IsSortable() const
Bool_tTObject::IsZombie() const
Int_tLayout()
virtual voidTObject::ls(Option_t* option = "") const
voidTObject::MayNotUse(const char* method) const
virtual Bool_tTObject::Notify()
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
voidTObject::operator delete(void* ptr)
voidTObject::operator delete(void* ptr, void* vp)
voidTObject::operator delete[](void* ptr)
voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
TGraphStruct&operator=(const TGraphStruct&)
virtual voidTObject::Paint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidTObject::Print(Option_t* option = "") const
virtual Int_tTObject::Read(const char* name)
virtual voidTObject::RecursiveRemove(TObject* obj)
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidSavePrimitive(ostream& out, Option_t* option = "")
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
voidSetMargin(Double_t m = 10)
static voidTObject::SetObjectStat(Bool_t stat)
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidShowMembers(TMemberInspector& insp) const
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
TGraphStruct()
TGraphStruct(const TGraphStruct&)
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
protected:
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
voidTObject::MakeZombie()

Data Members

public:
static TObject::<anonymous>TObject::kBitMask
static TObject::EStatusBitsTObject::kCanDelete
static TObject::EStatusBitsTObject::kCannotPick
static TObject::EStatusBitsTObject::kHasUUID
static TObject::EStatusBitsTObject::kInvalidObject
static TObject::<anonymous>TObject::kIsOnHeap
static TObject::EStatusBitsTObject::kIsReferenced
static TObject::EStatusBitsTObject::kMustCleanup
static TObject::EStatusBitsTObject::kNoContextMenu
static TObject::<anonymous>TObject::kNotDeleted
static TObject::EStatusBitsTObject::kObjInCanvas
static TObject::<anonymous>TObject::kOverwrite
static TObject::<anonymous>TObject::kSingleKey
static TObject::<anonymous>TObject::kWriteDelete
static TObject::<anonymous>TObject::kZombie
protected:
TList*fEdgesList of edges in this TGraphStruct
GVC_s*fGVCGraphviz context
GVizAgraph_t*fGVGraphGraphviz graph
Double_tfMarginMargin around the graph (in dots)
TList*fNodesList of nodes in this TGraphStruct

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TGraphStruct()
 Graph Structure default constructor.
~TGraphStruct()
 Graph Structure default destructor.
void AddEdge(TGraphEdge* edge)
 Add the edge "edge" in this TGraphStruct.
TGraphEdge * AddEdge(TGraphNode* n1, TGraphNode* n2)
 Create an edge between n1 and n2 and put it in this graph.

 Two edges can connect the same nodes the same way, so there
 is no need to check if an edge already exists.
void AddNode(TGraphNode* node)
 Add the node "node" in this TGraphStruct.
TGraphNode * AddNode(const char* name, const char* title = "")
 Create the node "name" if it does not exist and add it to this TGraphStruct.
void DumpAsDotFile(const char* filename)
 Dump this graph structure as a "dot" file.
void Draw(Option_t* option = "")
 Draw the graph
Int_t Layout()
 Layout the graph into a GraphViz data structure
void SavePrimitive(ostream& out, Option_t* option = "")
 Save primitive as a C++ statement(s) on output stream out
void Streamer(TBuffer& )
TGraphStruct()
TList * GetListOfNodes() const
{ return fNodes; }
TList * GetListOfEdges() const
{ return fEdges; }
void SetMargin(Double_t m = 10)
{fMargin = m;}