Logo ROOT   6.08/07
Reference Guide
Go to the documentation of this file.
1 // @(#)root/graf:$Id$
2 // Author: Guido Volpi, Olivier Couet 03/11/2006
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  *************************************************************************/
12 #ifndef ROOT_TPie
13 #define ROOT_TPie
14 #ifndef ROOT_TObject
15 #include "TObject.h"
16 #endif
17 #ifndef ROOT_TNamed
18 #include <TNamed.h>
19 #endif
20 #ifndef ROOT_TString
21 #include <TString.h>
22 #endif
23 #ifndef ROOT_TAttText
24 #include <TAttText.h>
25 #endif
27 class TH1;
28 class TPieSlice;
29 class TLegend;
31 class TPie : public TNamed , public TAttText {
32 private:
33  void Init(Int_t np, Double_t ao, Double_t x, Double_t y, Double_t r);
34  void DrawGhost();
36  Float_t fSum; ///<!Sum for the slice values
37  Float_t *fSlices; ///<!Subdivisions of the slices
38  TLegend *fLegend; ///<!Legend for this piechart
40 protected:
41  Double_t fX; ///< X coordinate of the pie centre
42  Double_t fY; ///< Y coordinate of the pie centre
43  Double_t fRadius; ///< Radius Pie radius
44  Double_t fAngularOffset; ///< Offset angular offset for the first slice
45  Float_t fLabelsOffset; ///< LabelsOffset offset of label
46  TString fLabelFormat; ///< Format format of the slices' label
47  TString fValueFormat; ///< Vform numeric format for the value
48  TString fFractionFormat; ///< Rform numeric format for the fraction of a slice
49  TString fPercentFormat; ///< Pfrom numeric format for the percent of a slice
50  Int_t fNvals; ///< Number of elements
51  TPieSlice **fPieSlices; ///<[fNvals] Slice array of this pie-chart
52  Bool_t fIs3D; ///<! true if the pseudo-3d is enabled
53  Double_t fHeight; ///< Height of the slice in pixel
54  Float_t fAngle3D; ///< The angle of the pseudo-3d view
56 public:
57  TPie();
58  TPie(const char *,const char *, Int_t);
59  TPie(const char *,const char *, Int_t, Double_t *,Int_t *cols=0, const char *lbls[]=0);
60  TPie(const char *,const char *, Int_t, Float_t *,Int_t *cols=0, const char *lbls[]=0);
61  TPie(const TH1 *h);
62  TPie(const TPie&);
63  ~TPie();
65  virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
67  virtual void Draw(Option_t *option="l"); // *MENU*
68  virtual void ExecuteEvent(Int_t,Int_t,Int_t);
69  Float_t GetAngle3D() { return fAngle3D; }
73  const char* GetEntryLabel(Int_t);
79  const char *GetFractionFormat() { return fFractionFormat.Data(); }
80  Double_t GetHeight() { return fHeight; }
81  const char *GetLabelFormat() { return fLabelFormat.Data(); }
83  TLegend *GetLegend();
84  Int_t GetEntries() { return fNvals; }
85  const char *GetPercentFormat() { return fPercentFormat.Data(); }
86  Double_t GetRadius() { return fRadius;}
88  const char *GetValueFormat() { return fValueFormat.Data(); }
89  Double_t GetX() { return fX; }
90  Double_t GetY() { return fY; }
91  TLegend *MakeLegend(Double_t x1=.65,Double_t y1=.65,Double_t x2=.95, Double_t y2=.95, const char *leg_header="");
92  void MakeSlices(Bool_t force=kFALSE);
93  virtual void Paint(Option_t *);
94  void SavePrimitive(std::ostream &out, Option_t *opts="");
95  void SetAngle3D(Float_t val = 30.); // *MENU*
97  void SetCircle(Double_t x=.5, Double_t y=.5, Double_t rad=.4);
98  void SetEntryLabel(Int_t, const char *text="Slice");
105  void SetEntryVal(Int_t, Double_t);
106  void SetFillColors(Int_t*);
107  void SetFractionFormat(const char*); // *MENU*
108  void SetHeight(Double_t val=.08); // *MENU*
109  void SetLabelFormat(const char *); // *MENU*
110  void SetLabels(const char *[]);
111  void SetLabelsOffset(Float_t); // *MENU*
112  void SetPercentFormat(const char *); // *MENU*
113  void SetRadius(Double_t); // *MENU*
114  void SetValueFormat(const char *); // *MENU*
115  void SetX(Double_t); // *MENU*
116  void SetY(Double_t); // *MENU*
117  void SortSlices(Bool_t amode=kTRUE,Float_t merge_thresold=.0);
119  ClassDef(TPie,1) //Pie chart graphics class
120 };
122 #endif // ROOT_TPie
const char * GetLabelFormat()
Definition: TPie.h:81
Int_t GetEntryFillColor(Int_t)
Return the color of the slice number "i".
Definition: TPie.cxx:646
void SetPercentFormat(const char *)
Set the numeric format for the percent value of a slice, default: %3.1f.
Definition: TPie.cxx:1359
void MakeSlices(Bool_t force=kFALSE)
Make the slices.
Definition: TPie.cxx:1406
TString fFractionFormat
Rform numeric format for the fraction of a slice.
Definition: TPie.h:48
void DrawGhost()
This method is for internal use.
Definition: TPie.cxx:297
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:27
float Float_t
Definition: RtypesCore.h:53
Float_t * fSlices
!Subdivisions of the slices
Definition: TPie.h:37
const char Option_t
Definition: RtypesCore.h:62
Int_t fNvals
Number of elements.
Definition: TPie.h:50
void SavePrimitive(std::ostream &out, Option_t *opts="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TPie.cxx:1123
TH1 * h
Definition: legend2.C:5
const char * GetValueFormat()
Definition: TPie.h:88
Int_t GetEntryLineColor(Int_t)
Return the line color used to outline thi "i" slice.
Definition: TPie.cxx:662
void SetAngularOffset(Double_t)
Set the global angular offset for slices in degree [0,360].
Definition: TPie.cxx:1191
TLegend * fLegend
!Legend for this piechart
Definition: TPie.h:38
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
TPieSlice * GetSlice(Int_t i)
Return the reference to the slice of index &#39;id&#39;.
Definition: TPie.cxx:712
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
void SetEntryFillStyle(Int_t, Int_t)
Set the fill style for the "i" slice.
Definition: TPie.cxx:1260
Double_t fRadius
Radius Pie radius.
Definition: TPie.h:43
Float_t fSum
!Sum for the slice values
Definition: TPie.h:36
void SetAngle3D(Float_t val=30.)
Set the value of for the pseudo 3D view angle, in degree.
Definition: TPie.cxx:1178
void SetEntryVal(Int_t, Double_t)
Set the value of a slice.
Definition: TPie.cxx:1276
Double_t GetRadius()
Definition: TPie.h:86
Int_t GetEntryLineStyle(Int_t)
Return the style used to outline thi "i" slice.
Definition: TPie.cxx:670
static const double x2[5]
virtual void Paint(Option_t *)
Paint a Pie chart in a canvas.
Definition: TPie.cxx:802
Double_t x[n]
Definition: legend1.C:17
Int_t GetEntryFillStyle(Int_t)
Return the style use to fill the slice number "i".
Definition: TPie.cxx:654
#define ClassDef(name, id)
Definition: Rtypes.h:254
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
Double_t GetEntryRadiusOffset(Int_t)
Return the radial offset&#39;s value for the slice number "i".
Definition: TPie.cxx:686
void SetEntryRadiusOffset(Int_t, Double_t)
Set the distance, in the direction of the radius of the slice.
Definition: TPie.cxx:1268
void SetHeight(Double_t val=.08)
Set the height, in pixel, for the piechart if is drawn using the pseudo-3d mode.
Definition: TPie.cxx:1298
TString fPercentFormat
Pfrom numeric format for the percent of a slice.
Definition: TPie.h:49
A slice of a piechart, see the TPie class.
Definition: TPieSlice.h:30
Int_t GetEntries()
Definition: TPie.h:84
const char * GetEntryLabel(Int_t)
Returns the label of the entry number "i".
Definition: TPie.cxx:638
Double_t fY
Y coordinate of the pie centre.
Definition: TPie.h:42
Float_t fLabelsOffset
LabelsOffset offset of label.
Definition: TPie.h:45
Double_t GetAngularOffset()
Definition: TPie.h:70
Double_t GetEntryVal(Int_t)
Return the value associated with the slice number "i".
Definition: TPie.cxx:694
Bool_t fIs3D
! true if the pseudo-3d is enabled
Definition: TPie.h:52
Double_t GetY()
Definition: TPie.h:90
Float_t GetAngle3D()
Definition: TPie.h:69
Int_t DistancetoSlice(Int_t, Int_t)
Returns the slice number at the pixel position (px,py).
Definition: TPie.cxx:188
void SetX(Double_t)
Set X value.
Definition: TPie.cxx:1389
void SetFractionFormat(const char *)
Set numeric format in the label, is used if the label format there is the modifier frac...
Definition: TPie.cxx:1334
Definition: TPie.cxx:155
TRandom2 r(17)
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Evaluate the distance to the chart in gPad.
Definition: TPie.cxx:168
void SetLabels(const char *[])
Set the labels for all the slices.
Definition: TPie.cxx:1342
void SetY(Double_t)
Set Y value.
Definition: TPie.cxx:1397
Text Attributes class.
Definition: TAttText.h:24
void SortSlices(Bool_t amode=kTRUE, Float_t merge_thresold=.0)
This method, mainly intended for internal use, ordered the slices according their values...
Definition: TPie.cxx:1441
TString fValueFormat
Vform numeric format for the value.
Definition: TPie.h:47
void SetFillColors(Int_t *)
Set the fill colors for all the TPie&#39;s slices.
Definition: TPie.cxx:1286
void SetCircle(Double_t x=.5, Double_t y=.5, Double_t rad=.4)
Set the coordinates of the circle that describe the pie:
Definition: TPie.cxx:1208
Float_t fAngle3D
The angle of the pseudo-3d view.
Definition: TPie.h:54
virtual void ExecuteEvent(Int_t, Int_t, Int_t)
Execute the mouse events.
Definition: TPie.cxx:393
const char * GetFractionFormat()
Definition: TPie.h:79
TString fLabelFormat
Format format of the slices&#39; label.
Definition: TPie.h:46
static const double x1[5]
void SetRadius(Double_t)
Set the pie chart&#39;s radius&#39; value.
Definition: TPie.cxx:1367
double Double_t
Definition: RtypesCore.h:55
TText * text
TPieSlice ** fPieSlices
[fNvals] Slice array of this pie-chart
Definition: TPie.h:51
Default constructor.
Definition: TPie.cxx:62
Double_t y[n]
Definition: legend1.C:17
The TH1 histogram class.
Definition: TH1.h:80
Draw a Pie Chart,.
Definition: TPie.h:31
TLegend * MakeLegend(Double_t x1=.65, Double_t y1=.65, Double_t x2=.95, Double_t y2=.95, const char *leg_header="")
This method create a legend that explains the contents of the slice for this pie-chart.
Definition: TPie.cxx:768
void SetLabelsOffset(Float_t)
Set the distance between the label end the external line of the TPie.
Definition: TPie.cxx:1351
Double_t fHeight
Height of the slice in pixel.
Definition: TPie.h:53
Double_t fX
X coordinate of the pie centre.
Definition: TPie.h:41
Double_t fAngularOffset
Offset angular offset for the first slice.
Definition: TPie.h:44
void SetLabelFormat(const char *)
This method is used to customize the label format.
Definition: TPie.cxx:1314
void SetEntryFillColor(Int_t, Int_t)
Set the color for the slice "i".
Definition: TPie.cxx:1252
void SetEntryLineStyle(Int_t, Int_t)
Set the style for the slice&#39;s outline. "i" is the slice number.
Definition: TPie.cxx:1236
Double_t GetHeight()
Definition: TPie.h:80
TLegend * GetLegend()
If created before by Paint option or by MakeLegend method return the pointer to the legend...
Definition: TPie.cxx:703
Float_t GetLabelsOffset()
Definition: TPie.h:82
void SetEntryLineColor(Int_t, Int_t)
Set the color for the slice&#39;s outline. "i" is the slice number.
Definition: TPie.cxx:1228
const char * GetPercentFormat()
Definition: TPie.h:85
Int_t GetEntryLineWidth(Int_t)
Return the line width used to outline thi "i" slice.
Definition: TPie.cxx:678
void Init(Int_t np, Double_t ao, Double_t x, Double_t y, Double_t r)
Common initialization for all constructors.
Definition: TPie.cxx:721
void SetEntryLineWidth(Int_t, Int_t)
Set the width of the slice&#39;s outline. "i" is the slice number.
Definition: TPie.cxx:1244
virtual void Draw(Option_t *option="l")
Draw the pie chart.
Definition: TPie.cxx:274
const Bool_t kTRUE
Definition: Rtypes.h:91
void SetEntryLabel(Int_t, const char *text="Slice")
Set slice number "i" label.
Definition: TPie.cxx:1219
const char * Data() const
Definition: TString.h:349
Double_t GetX()
Definition: TPie.h:89
void SetValueFormat(const char *)
Set the numeric format the slices&#39; values.
Definition: TPie.cxx:1381