Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPieSlice.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Guido Volpi, Olivier Couet 03/11/2006
3// Author: Sergey Linev 09/2026
4
5/*************************************************************************
6 * Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include "TPieSlice.h"
14
15#include "TError.h"
16#include "TMath.h"
17#include "TVirtualPad.h"
18#include "TPie.h"
19
20#include <iostream>
21#include <cstring>
22
23
24/** \class TPieSlice
25\ingroup BasicGraphics
26
27A slice of a piechart, see the TPie class.
28
29This class describe the property of single
30*/
31
32////////////////////////////////////////////////////////////////////////////////
33/// This is the default constructor, used to create the standard.
34
36{
37 fPie = nullptr;
38 fValue = 1;
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// This constructor create a slice with a particular value.
43
44TPieSlice::TPieSlice(const char *name, const char *title,
45 TPie *pie, Double_t val) :
46 TNamed(name, title)
47{
48 fPie = pie;
49 fValue = val;
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Eval if the mouse is over the area associated with this slice.
54/// Return 0 only when mouse over the outer part of the slice to let activate context menu
55
57{
58 Int_t dist = 9999;
59
60 if (gPad && fPie) {
61 auto info = fPie->FindSlice(*gPad, px, py);
62 if ((info.num >= 0) && (fPie->GetSlice(info.num) == this) && (info.rad > 0.6) && (info.rad <= 1))
63 dist = 0;
64 }
65
66 return dist;
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Execute event,
71/// redirect to TPie object
72
74{
75 if (fPie)
76 fPie->ExecuteEvent(event, px, py);
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// return the value of the offset in radial direction for this slice.
81
86
87////////////////////////////////////////////////////////////////////////////////
88/// Return the value of this slice.
89
91{
92 return fValue;
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Save as C++ macro, used directly from TPie
97
98void TPieSlice::SavePrimitive(std::ostream &out, Option_t *opts)
99{
100 const char *name = opts;
101 if (!name || !*name || strncmp(name, "pie->", 5))
102 return;
103
104 out << " " << name << "->SetTitle(\"" << GetTitle() << "\");\n";
105 out << " " << name << "->SetValue(" << GetValue() << ");\n";
106 out << " " << name << "->SetRadiusOffset(" << GetRadiusOffset() << ");\n";
107
108 SaveFillAttributes(out, name, -1, -1);
109 SaveLineAttributes(out, name, 1, 1, 1);
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Set the radial offset of this slice.
114
115void TPieSlice::SetRadiusOffset(Double_t val)
116{
117 fRadiusOffset = TMath::Max(val, 0.);
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Set the value for this slice.
122/// Negative values are changed with its absolute value.
123
125{
126 fValue = val;
127 if (fValue < .0) {
128 Warning("SetValue","Invalid negative value. Absolute value taken");
129 fValue *= -1;
130 }
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Copy TPieSlice
135
136void TPieSlice::Copy(TObject &obj) const
137{
138 auto &slice = (TPieSlice&)obj;
139
140 TNamed::Copy(slice);
141 TAttLine::Copy(slice);
142 TAttFill::Copy(slice);
143
144 slice.SetValue(GetValue());
145 slice.SetRadiusOffset(GetRadiusOffset());
146}
147
cudaEvent_t event
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:142
#define gPad
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition TAttFill.cxx:203
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:240
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition TAttLine.cxx:176
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:289
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:93
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
Mother of all ROOT objects.
Definition TObject.h:42
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1082
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:56
Double_t fRadiusOffset
offset from the center of the pie
Definition TPieSlice.h:23
Double_t fValue
value value of this slice
Definition TPieSlice.h:22
void SetValue(Double_t)
Set the value for this slice.
void ExecuteEvent(Int_t, Int_t, Int_t) override
Execute event, redirect to TPie object.
Definition TPieSlice.cxx:73
Double_t GetRadiusOffset() const
return the value of the offset in radial direction for this slice.
Definition TPieSlice.cxx:82
void Copy(TObject &slice) const override
Copy TPieSlice.
Double_t GetValue() const
Return the value of this slice.
Definition TPieSlice.cxx:90
void SavePrimitive(std::ostream &out, Option_t *opts="") override
Save as C++ macro, used directly from TPie.
Definition TPieSlice.cxx:98
TPieSlice()
This is the default constructor, used to create the standard.
Definition TPieSlice.cxx:35
TPie * fPie
The TPie object that contain this slice.
Definition TPieSlice.h:21
Define a Pie Chart.
Definition TPie.h:26
TPieSlice * GetSlice(Int_t i) const
Return the reference to the slice of index 'id'.
Definition TPie.cxx:669
void ExecuteEvent(Int_t, Int_t, Int_t) override
Execute the mouse events.
Definition TPie.cxx:404
SliceInfo_t FindSlice(TVirtualPad &, Int_t, Int_t)
Find slice at given position.
Definition TPie.cxx:223
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249