Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPie.h
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Guido Volpi, Olivier Couet 03/11/2006
3
4/*************************************************************************
5 * Copyright (C) 1995-2026, 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#ifndef ROOT_TPie
13#define ROOT_TPie
14
15#include "TNamed.h"
16#include "TAttText.h"
17#include "TString.h"
18
19#include <vector>
20
21class TH1;
22class TPieSlice;
23class TLegend;
24class TPieInteractive;
25
26class TPie : public TNamed , public TAttText {
27private:
28
29 friend class TPieSlice;
30
32 void DrawGhost(TVirtualPad &);
33
34 struct SliceInfo_t {
36 Double_t ang = 0; // angle to mouse position
37 Double_t cphi = 0; // central angle of the slice
38 Double_t rad = 0; // relative radius
39 };
40
42
43 std::vector<Float_t> GetSlicesAngles() const;
44
45 TLegend *fLegend{nullptr}; ///<!Legend for this piechart
46
47protected:
48 Double_t fX; ///< X coordinate of the pie centre
49 Double_t fY; ///< Y coordinate of the pie centre
50 Double_t fRadius; ///< Radius Pie radius
51 Double_t fAngularOffset; ///< Offset angular offset for the first slice
52 Float_t fLabelsOffset; ///< LabelsOffset offset of label
53 TString fLabelFormat; ///< Format format of the slices' label
54 TString fValueFormat; ///< Vform numeric format for the value
55 TString fFractionFormat; ///< Rform numeric format for the fraction of a slice
56 TString fPercentFormat; ///< Pfrom numeric format for the percent of a slice
57 Int_t fNvals; ///< Number of elements
58 TPieSlice **fPieSlices{nullptr}; ///<[fNvals] Slice array of this pie-chart
59 Bool_t fIs3D; ///<! true if the pseudo-3d is enabled
60 Double_t fHeight; ///< Height of the slice in pixel
61 Float_t fAngle3D; ///< The angle of the pseudo-3d view
62
63public:
64 TPie();
65 TPie(const char *,const char *, Int_t);
66 TPie(const char *,const char *, Int_t, Double_t *, Int_t *cols = nullptr, const char *lbls[] = nullptr);
67 TPie(const char *,const char *, Int_t, Float_t *, Int_t *cols = nullptr, const char *lbls[] = nullptr);
68 TPie(const TH1 *h);
69 TPie(const TPie&);
70 ~TPie() override;
71
72 Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
73 Int_t DistancetoSlice(Int_t,Int_t) R__DEPRECATED(6, 46, "No longer used.");
74 void Draw(Option_t *option="l") override; // *MENU*
75 void ExecuteEvent(Int_t,Int_t,Int_t) override;
76 Float_t GetAngle3D() const { return fAngle3D; }
80 const char* GetEntryLabel(Int_t) const;
87 const char *GetFractionFormat() const { return fFractionFormat.Data(); }
88 Double_t GetHeight() const { return fHeight; }
89 const char *GetLabelFormat() const { return fLabelFormat.Data(); }
91 TLegend *GetLegend() const;
92 Int_t GetEntries() const { return fNvals; }
93 const char *GetPercentFormat() const { return fPercentFormat.Data(); }
94 Double_t GetRadius() const { return fRadius;}
95 TPieSlice *GetSlice(Int_t i) const;
96 const char *GetValueFormat() const { return fValueFormat.Data(); }
97 Double_t GetX() const { return fX; }
98 Double_t GetY() const { return fY; }
99 TLegend *MakeLegend(Double_t x1=.65,Double_t y1=.65,Double_t x2=.95, Double_t y2=.95, const char *leg_header="");
100 void MakeSlices(Bool_t force = kFALSE) R__DEPRECATED(6, 46, "No longer necessary.");
101 void Paint(Option_t *) override;
102 void SavePrimitive(std::ostream &out, Option_t *opts="") override;
103 void SetAngle3D(Float_t val = 30.); // *MENU*
105 void SetCircle(Double_t x=.5, Double_t y=.5, Double_t rad=.4);
106 void SetEntryLabel(Int_t, const char *text="Slice");
114 void SetFillColors(Int_t*);
115 void SetFractionFormat(const char*); // *MENU*
116 void SetHeight(Double_t val=.08); // *MENU*
117 void SetLabelFormat(const char *); // *MENU*
118 void SetLabels(const char *[]);
119 void SetLabelsOffset(Float_t); // *MENU*
120 void SetPercentFormat(const char *); // *MENU*
121 void SetRadius(Double_t); // *MENU*
122 void SetValueFormat(const char *); // *MENU*
123 void SetX(Double_t); // *MENU*
124 void SetY(Double_t); // *MENU*
126
127 ClassDefOverride(TPie,1) //Pie chart graphics class
128};
129
130#endif // ROOT_TPie
#define R__DEPRECATED(MAJOR, MINOR, REASON)
Definition RConfig.hxx:486
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
#define ClassDefOverride(name, id)
Definition Rtypes.h:347
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
Text Attributes class.
Definition TAttText.h:21
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
A slice of a piechart, see the TPie class.
Definition TPieSlice.h:18
Define a Pie Chart.
Definition TPie.h:26
void SetEntryVal(Int_t, Double_t)
Set the value of a slice.
Definition TPie.cxx:1181
Float_t fLabelsOffset
LabelsOffset offset of label.
Definition TPie.h:52
Double_t GetEntryVal(Int_t) const
Return the value associated with the slice number "i".
Definition TPie.cxx:639
void SetAngularOffset(Double_t)
Set the global angular offset for slices in degree [0,360].
Definition TPie.cxx:1096
void Paint(Option_t *) override
Paint a Pie chart in a canvas.
Definition TPie.cxx:742
const char * GetLabelFormat() const
Definition TPie.h:89
const char * GetEntryLabel(Int_t) const
Returns the label of the entry number "i".
Definition TPie.cxx:583
TString fLabelFormat
Format format of the slices' label.
Definition TPie.h:53
Int_t GetEntryLineColor(Int_t) const
Return the line color used to outline thi "i" slice.
Definition TPie.cxx:607
void SetX(Double_t)
Set X value.
Definition TPie.cxx:1285
Double_t fAngularOffset
Offset angular offset for the first slice.
Definition TPie.h:51
Double_t GetHeight() const
Definition TPie.h:88
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:1343
void SetEntryFillStyle(Int_t, Int_t)
Set the fill style for the "i" slice.
Definition TPie.cxx:1165
TPie()
Default constructor.
Definition TPie.cxx:103
~TPie() override
Destructor.
Definition TPie.cxx:195
TPieSlice * GetSlice(Int_t i) const
Return the reference to the slice of index 'id'.
Definition TPie.cxx:669
Double_t GetSumOfEntriesValues() const
Return sum of all entries.
Definition TPie.cxx:648
void SetFractionFormat(const char *)
Set numeric format in the label, is used if the label format there is the modifier frac,...
Definition TPie.cxx:1230
Float_t fAngle3D
The angle of the pseudo-3d view.
Definition TPie.h:61
Double_t fHeight
Height of the slice in pixel.
Definition TPie.h:60
Float_t GetLabelsOffset() const
Definition TPie.h:90
Int_t GetEntryLineStyle(Int_t) const
Return the style used to outline thi "i" slice.
Definition TPie.cxx:615
void SetPercentFormat(const char *)
Set the numeric format for the percent value of a slice, default: %3.1f.
Definition TPie.cxx:1255
Double_t GetX() const
Definition TPie.h:97
void SetLabels(const char *[])
Set the labels for all the slices.
Definition TPie.cxx:1238
Double_t GetAngularOffset() const
Definition TPie.h:77
void SetY(Double_t)
Set Y value.
Definition TPie.cxx:1293
Int_t DistancetoSlice(Int_t, Int_t) R__DEPRECATED(6
Returns the slice number at the pixel position (px,py).
Definition TPie.cxx:281
Bool_t fIs3D
! true if the pseudo-3d is enabled
Definition TPie.h:59
Int_t GetEntryFillStyle(Int_t) const
Return the style use to fill the slice number "i".
Definition TPie.cxx:599
Int_t GetEntryFillColor(Int_t) const
Return the color of the slice number "i".
Definition TPie.cxx:591
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:678
void SetLabelsOffset(Float_t)
Set the distance between the label end the external line of the TPie.
Definition TPie.cxx:1247
Double_t GetRadius() const
Definition TPie.h:94
Int_t GetEntries() const
Definition TPie.h:92
void SetEntryRadiusOffset(Int_t, Double_t)
Set the distance, in the direction of the radius of the slice.
Definition TPie.cxx:1173
void DrawGhost(TVirtualPad &)
This method is for internal use.
Definition TPie.cxx:336
TLegend * fLegend
!Legend for this piechart
Definition TPie.h:45
void SetLabelFormat(const char *)
This method is used to customize the label format.
Definition TPie.cxx:1210
Double_t fRadius
Radius Pie radius.
Definition TPie.h:50
TPieSlice ** fPieSlices
[fNvals] Slice array of this pie-chart
Definition TPie.h:58
void ExecuteEvent(Int_t, Int_t, Int_t) override
Execute the mouse events.
Definition TPie.cxx:404
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Evaluate the distance to the chart in gPad.
Definition TPie.cxx:208
void SetEntryLineStyle(Int_t, Int_t)
Set the style for the slice's outline. "i" is the slice number.
Definition TPie.cxx:1141
void SetEntryFillColor(Int_t, Int_t)
Set the color for the slice "i".
Definition TPie.cxx:1157
void SetEntryLineWidth(Int_t, Int_t)
Set the width of the slice's outline. "i" is the slice number.
Definition TPie.cxx:1149
TLegend * GetLegend() const
If created before by Paint option or by MakeLegend method return the pointer to the legend,...
Definition TPie.cxx:661
std::vector< Float_t > GetSlicesAngles() const
Return calculated angle for all slices Only for internal use.
Definition TPie.cxx:1302
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:1113
TString fValueFormat
Vform numeric format for the value.
Definition TPie.h:54
Double_t GetY() const
Definition TPie.h:98
const char * GetPercentFormat() const
Definition TPie.h:93
TString fFractionFormat
Rform numeric format for the fraction of a slice.
Definition TPie.h:55
void SetAngle3D(Float_t val=30.)
Set the value of for the pseudo 3D view angle, in degree.
Definition TPie.cxx:1083
const char * GetValueFormat() const
Definition TPie.h:96
Float_t GetAngle3D() const
Definition TPie.h:76
Int_t GetEntryLineWidth(Int_t) const
Return the line width used to outline thi "i" slice.
Definition TPie.cxx:623
void SetRadius(Double_t)
Set the pie chart's radius' value.
Definition TPie.cxx:1263
void SavePrimitive(std::ostream &out, Option_t *opts="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TPie.cxx:1057
TString fPercentFormat
Pfrom numeric format for the percent of a slice.
Definition TPie.h:56
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:724
Int_t fNvals
Number of elements.
Definition TPie.h:57
void MakeSlices(Bool_t force=kFALSE) R__DEPRECATED(6
Make the slices.
Definition TPie.cxx:1332
Double_t fY
Y coordinate of the pie centre.
Definition TPie.h:49
void SetEntryLabel(Int_t, const char *text="Slice")
Set slice number "i" label.
Definition TPie.cxx:1124
Double_t fX
X coordinate of the pie centre.
Definition TPie.h:48
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:1201
void SetValueFormat(const char *)
Set the numeric format the slices' values.
Definition TPie.cxx:1277
Double_t GetEntryRadiusOffset(Int_t) const
Return the radial offset's value for the slice number "i".
Definition TPie.cxx:631
SliceInfo_t FindSlice(TVirtualPad &, Int_t, Int_t)
Find slice at given position.
Definition TPie.cxx:223
void SetEntryLineColor(Int_t, Int_t)
Set the color for the slice's outline. "i" is the slice number.
Definition TPie.cxx:1133
void SetFillColors(Int_t *)
Set the fill colors for all the TPie's slices.
Definition TPie.cxx:1189
const char * GetFractionFormat() const
Definition TPie.h:87
Basic string class.
Definition TString.h:137
const char * Data() const
Definition TString.h:385
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Double_t rad
Definition TPie.h:38
Double_t cphi
Definition TPie.h:37
Double_t ang
Definition TPie.h:36
th1 Draw()