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
59 if (fIsActive) {
60 dist = 0;
62 gPad->SetCursor(kHand);
63 }
64
65 return dist;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// return the value of the offset in radial direction for this slice.
70
72{
73 return fRadiusOffset;
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// Return the value of this slice.
78
80{
81 return fValue;
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Save as C++ macro, used directly from TPie
86
87void TPieSlice::SavePrimitive(std::ostream &out, Option_t *opts)
88{
89 const char *name = opts;
90 if (!name || !*name || strncmp(name, "pie->", 5))
91 return;
92
93 out << " " << name << "->SetTitle(\"" << GetTitle() << "\");" << std::endl;
94 out << " " << name << "->SetValue(" << GetValue() << ");" << std::endl;
95 out << " " << name << "->SetRadiusOffset(" << GetRadiusOffset() << ");" << std::endl;
96
97 SaveFillAttributes(out, name, 0, 1001);
98 SaveLineAttributes(out, name, 1, 1, 1);
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Set the radial offset of this slice.
103
105{
106 fRadiusOffset = val;
107 if (fRadiusOffset<.0) fRadiusOffset = .0;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Set the value for this slice.
112/// Negative values are changed with its absolute value.
113
115{
116 fValue = val;
117 if (fValue<.0) {
118 Warning("SetValue","Invalid negative value. Absolute value taken");
119 fValue *= -1;
120 }
121
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Copy TPieSlice
127
128void TPieSlice::Copy(TObject &obj) const
129{
130 auto &slice = (TPieSlice&)obj;
131
132 TNamed::Copy(slice);
133 TAttLine::Copy(slice);
134 TAttFill::Copy(slice);
135
136 slice.SetValue(GetValue());
137 slice.SetRadiusOffset(GetRadiusOffset());
138}
139
@ kHand
Definition GuiTypes.h:374
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
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:204
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:236
Line Attributes class.
Definition TAttLine.h:18
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition TAttLine.cxx:175
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:273
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:956
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:71
void Copy(TObject &slice) const override
Copy TPieSlice.
Double_t GetValue() const
Return the value of this slice.
Definition TPieSlice.cxx:79
void SavePrimitive(std::ostream &out, Option_t *opts="") override
Save as C++ macro, used directly from TPie.
Definition TPieSlice.cxx:87
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:1379