Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGraphNode.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Olivier Couet 13/07/09
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TLatex.h"
13#include "TEllipse.h"
14#include "TGraphNode.h"
15
16#include <gvc.h>
17
18
19/** \class TGraphNode
20\ingroup gviz
21
22A graph node object which can be added in a TGraphStruct.
23*/
24
25////////////////////////////////////////////////////////////////////////////////
26/// Graph node default constructor.
27
29{
30 fGVNode = 0;
31 fX = 0;
32 fY = 0;
33 fW = 0;
34 fH = 0;
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Graph node normal constructor.
39
40TGraphNode::TGraphNode(const char *name,const char *title)
41 :TNamed(name,title), TAttText()
42{
43 fGVNode = 0;
44 fX = 0;
45 fY = 0;
46 fW = 0;
47 fH = 0;
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Graph Node default destructor.
52
56
57////////////////////////////////////////////////////////////////////////////////
58/// Create the GraphViz node into the GraphViz data structure gv.
59
61{
62 if (gv) {
63#ifdef WITH_CGRAPH
64 fGVNode = (GVizAgnode_t*)agnode((Agraph_t*)gv, (char *)GetName(), 1);
65#else
66 fGVNode = (GVizAgnode_t*)agnode((Agraph_t*)gv, (char *)GetName());
67#endif
68 } else {
69 Error("CreateGVNode","Invalid graphviz graph");
70 }
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Compute distance from point px,py to a node.
75
77{
78 Int_t dist;
79
80 // The node is drawn as an ellipse
81 TEllipse ellipse(fX, fY, fW, fH, 0., 360., 0.);
82 ellipse.SetFillColor(1); // in order to pick the ellipse "inside"
83 dist = ellipse.DistancetoPrimitive(px, py);
84
85 return dist;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Execute action corresponding to one event.
90
92{
93 TEllipse ellipse(fX, fY, fW, fH, 0., 360., 0.);
94 ellipse.ExecuteEvent(event,px, py);
95 fX = ellipse.GetX1();
96 fY = ellipse.GetY1();
97 fW = ellipse.GetR1();
98 fH = ellipse.GetR2();
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Layout this node in the GraphViz space. This is done after gvLayout
103/// has been performed.
104
106{
107#ifdef ND_coord
110#endif
111#ifdef ND_coord_i
114#endif
115 fW = ND_width((Agnode_t*)fGVNode)*36;
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Paint this node with its current attributes.
121
123{
125 TLatex text;
126 text.SetTextAlign(22);
127
128 // Draw the node shape as an ellipse
129 // ND_shape((Agnode_t*)fGVNode)->name gives the type of shape.
130 ellipse.SetFillStyle(GetFillStyle());
131 ellipse.SetFillColor(GetFillColor());
132 ellipse.SetLineColor(GetLineColor());
133 ellipse.SetLineStyle(GetLineStyle());
134 ellipse.SetLineWidth(GetLineWidth());
135 ellipse.PaintEllipse(fX, fY, fW, fH, 0., 360., 0., "");
136
137 // Draw the node title
138 text.SetTextColor(GetTextColor());
139 text.SetTextFont(GetTextFont());
140 text.PaintLatex(fX, fY, 0., GetTextSize(), (char*)GetTitle());
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Save primitive as a C++ statement(s) on output stream out
145
146void TGraphNode::SavePrimitive(std::ostream &, Option_t *)
147{
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Save attributes as a C++ statement(s) on output stream out
152/// called by TGraphStruct::SavePrimitive.
153
154void TGraphNode::SaveAttributes(std::ostream &out)
155{
156 SaveFillAttributes(out, GetName(), 0, 1001);
157 SaveLineAttributes(out, GetName(), 1, 1, 1);
158 SaveTextAttributes(out, GetName(), 0, 0, 0, 0, 0);
159}
160
161////////////////////////////////////////////////////////////////////////////////
162
164{
165}
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char text
char name[80]
Definition TGX11.cxx:110
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:31
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:32
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition TAttFill.cxx:238
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:35
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:37
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:36
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:274
Text Attributes class.
Definition TAttText.h:20
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:38
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:37
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:36
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
Save text attributes as C++ statement(s) on output stream out.
Definition TAttText.cxx:372
Buffer base class used for serializing objects.
Definition TBuffer.h:43
Draw Ellipses.
Definition TEllipse.h:23
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
GVizAgnode_t * fGVNode
Graphviz node.
Definition TGraphNode.h:33
Double_t fY
Node's center Y coordinate.
Definition TGraphNode.h:35
Double_t fW
Node width.
Definition TGraphNode.h:37
void SavePrimitive(std::ostream &, Option_t *) override
Save primitive as a C++ statement(s) on output stream out.
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a node.
Double_t fH
Node height.
Definition TGraphNode.h:36
void SaveAttributes(std::ostream &)
Save attributes as a C++ statement(s) on output stream out called by TGraphStruct::SavePrimitive.
void Paint(Option_t *option="") override
Paint this node with its current attributes.
Double_t fX
Node's center X coordinate.
Definition TGraphNode.h:34
TGraphNode()
Graph node default constructor.
void CreateGVNode(GVizAgraph_t *gv)
Create the GraphViz node into the GraphViz data structure gv.
void Streamer(TBuffer &) override
Stream an object of class TObject.
void Layout()
Layout this node in the GraphViz space.
~TGraphNode() override
Graph Node default destructor.
To draw Mathematical Formula.
Definition TLatex.h:18
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071