Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPieSlice.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#include "TPieSlice.h"
10
11#include "TError.h"
12#include "TVirtualPad.h"
13#include "TPie.h"
14
15#include <iostream>
16#include <cstring>
17
19
20/** \class TPieSlice
21\ingroup BasicGraphics
22
23A slice of a piechart, see the TPie class.
24
25This class describe the property of single
26*/
27
28////////////////////////////////////////////////////////////////////////////////
29/// This is the default constructor, used to create the standard.
30
32{
33 fPie = nullptr;
34 fValue = 1;
35 fRadiusOffset = 0;
37}
38
39////////////////////////////////////////////////////////////////////////////////
40/// This constructor create a slice with a particular value.
41
42TPieSlice::TPieSlice(const char *name, const char *title,
43 TPie *pie, Double_t val) :
44 TNamed(name, title), TAttFill(), TAttLine()
45{
46 fPie = pie;
47 fValue = val;
48 fRadiusOffset = 0;
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Eval if the mouse is over the area associated with this slice.
54
56{
57 Int_t dist = 9999;
58 if (!gPad) return dist;
59
60 if (fIsActive) {
61 dist = 0;
63 gPad->SetCursor(kHand);
64 }
65
66 return dist;
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// return the value of the offset in radial direction for this slice.
71
73{
74 return fRadiusOffset;
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Return the value of this slice.
79
81{
82 return fValue;
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Save as C++ macro, used directly from TPie
87
88void TPieSlice::SavePrimitive(std::ostream &out, Option_t *opts)
89{
90 const char *name = opts;
91 if (!name || !*name || strncmp(name, "pie->", 5))
92 return;
93
94 out << " " << name << "->SetTitle(\"" << GetTitle() << "\");" << std::endl;
95 out << " " << name << "->SetValue(" << GetValue() << ");" << std::endl;
96 out << " " << name << "->SetRadiusOffset(" << GetRadiusOffset() << ");" << std::endl;
97
98 SaveFillAttributes(out, name, 0, 1001);
99 SaveLineAttributes(out, name, 1, 1, 1);
100}
101
102////////////////////////////////////////////////////////////////////////////////
103/// Set the radial offset of this slice.
104
106{
107 fRadiusOffset = val;
108 if (fRadiusOffset<.0) fRadiusOffset = .0;
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Set the value for this slice.
113/// Negative values are changed with its absolute value.
114
116{
117 fValue = val;
118 if (fValue<.0) {
119 Warning("SetValue","Invalid negative value. Absolute value taken");
120 fValue *= -1;
121 }
122
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// Copy TPieSlice
128
129void TPieSlice::Copy(TObject &obj) const
130{
131 auto &slice = (TPieSlice&)obj;
132
133 TNamed::Copy(slice);
134 TAttLine::Copy(slice);
135 TAttFill::Copy(slice);
136
137 slice.SetValue(GetValue());
138 slice.SetRadiusOffset(GetRadiusOffset());
139}
140
@ kHand
Definition GuiTypes.h:374
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
char name[80]
Definition TGX11.cxx:110
#define gPad
Fill Area Attributes class.
Definition TAttFill.h:19
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition TAttFill.cxx:207
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:239
Line Attributes class.
Definition TAttLine.h:18
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition TAttLine.cxx:177
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:275
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
void Copy(TObject &named) const override
Copy this to obj.
Definition TNamed.cxx:94
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:991
A slice of a piechart, see the TPie class.
Definition TPieSlice.h:18
Int_t DistancetoPrimitive(Int_t, Int_t) override
Eval if the mouse is over the area associated with this slice.
Definition TPieSlice.cxx:55
Double_t fRadiusOffset
offset from the center of the pie
Definition TPieSlice.h:28
Double_t fValue
value value of this slice
Definition TPieSlice.h:27
void SetValue(Double_t)
Set the value for this slice.
Bool_t fIsActive
! True if is the slice under the mouse pointer
Definition TPieSlice.h:23
Double_t GetRadiusOffset() const
return the value of the offset in radial direction for this slice.
Definition TPieSlice.cxx:72
void Copy(TObject &slice) const override
Copy TPieSlice.
Double_t GetValue() const
Return the value of this slice.
Definition TPieSlice.cxx:80
void SavePrimitive(std::ostream &out, Option_t *opts="") override
Save as C++ macro, used directly from TPie.
Definition TPieSlice.cxx:88
void SetRadiusOffset(Double_t)
Set the radial offset of this slice.
TPieSlice()
This is the default constructor, used to create the standard.
Definition TPieSlice.cxx:31
TPie * fPie
The TPie object that contain this slice.
Definition TPieSlice.h:26
Draw a Pie Chart,.
Definition TPie.h:23
void MakeSlices(Bool_t force=kFALSE)
Make the slices.
Definition TPie.cxx:1380