Logo ROOT  
Reference Guide
TPie.cxx
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-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  *************************************************************************/
11 
12 #include "TPie.h"
13 #include "TPieSlice.h"
14 
15 #include <iostream>
16 #include <TROOT.h>
17 #include <TVirtualPad.h>
18 #include <TVirtualX.h>
19 #include <TArc.h>
20 #include <TLegend.h>
21 #include <TMath.h>
22 #include <TStyle.h>
23 #include <TLatex.h>
24 #include <TPaveText.h>
25 #include <TH1.h>
26 #include <TColor.h>
27 #include <TLine.h>
28 
29 ClassImp(TPie);
30 
31 /** \class TPie
32 \ingroup BasicGraphics
33 
34 Draw a Pie Chart,
35 
36 Example:
37 
38 Begin_Macro(source)
39 ../../../tutorials/graphics/piechart.C
40 End_Macro
41 */
42 
43 Double_t gX = 0; // Temporary pie X position.
44 Double_t gY = 0; // Temporary pie Y position.
45 Double_t gRadius = 0; // Temporary pie Radius of the TPie.
46 Double_t gRadiusOffset = 0; // Temporary slice's radial offset.
47 Double_t gAngularOffset = 0; // Temporary slice's angular offset.
48 Bool_t gIsUptSlice = kFALSE; // True if a slice in the TPie should
49  // be updated.
50 Int_t gCurrent_slice = -1;// Current slice under mouse.
51 Double_t gCurrent_phi1 = 0; // Phimin of the current slice.
52 Double_t gCurrent_phi2 = 0; // Phimax of the current slice.
53 Double_t gCurrent_rad = 0; // Current distance from the vertex of the
54  // current slice.
55 Double_t gCurrent_x = 0; // Current x in the pad metric.
56 Double_t gCurrent_y = 0; // Current y in the pad metric.
57 Double_t gCurrent_ang = 0; // Current angular, within current_phi1
58  // and current_phi2.
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Default constructor.
62 
64 {
65  Init(1, 0, 0.5, 0.5, 0.4);
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// This constructor creates a pie chart when only the number of
70 /// the slices is known. The number of slices is fixed.
71 
72 TPie::TPie(const char *name, const char *title, Int_t npoints) :
73  TNamed(name,title)
74 {
75  Init(npoints, 0, 0.5, 0.5, 0.4);
76 }
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Normal constructor. The 1st and 2nd parameters are the name of the object
80 /// and its title.
81 ///
82 /// The number of points passed at this point is used to allocate the memory.
83 ///
84 /// Slices values are given as Double_t.
85 ///
86 /// The 4th elements is an array containing, in double precision format,
87 /// the value of each slice. It is also possible to specify the filled color
88 /// of each slice. If the color array is not specified the slices are colored
89 /// using a color sequence in the standard palette.
90 
91 TPie::TPie(const char *name, const char *title,
92  Int_t npoints, Double_t *vals,
93  Int_t *colors, const char *lbls[]) : TNamed(name,title)
94 {
95  Init(npoints, 0, 0.5, 0.5, 0.4);
96  for (Int_t i=0; i<fNvals; ++i) fPieSlices[i]->SetValue(vals[i]);
97 
99  SetLabels(lbls);
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Normal constructor (Float_t).
104 
105 TPie::TPie(const char *name,
106  const char *title,
107  Int_t npoints, Float_t *vals,
108  Int_t *colors, const char *lbls[]) : TNamed(name,title)
109 {
110  Init(npoints, 0, 0.5, 0.5, 0.4);
111  for (Int_t i=0; i<fNvals; ++i) fPieSlices[i]->SetValue(vals[i]);
112 
114  SetLabels(lbls);
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Constructor from a TH1
119 
120 TPie::TPie(const TH1 *h) : TNamed(h->GetName(),h->GetTitle())
121 {
122  Int_t i;
123 
124  const TAxis *axis = h->GetXaxis();
125  Int_t first = axis->GetFirst();
126  Int_t last = axis->GetLast();
127  Int_t np = last-first+1;
128  Init(np, 0, 0.5, 0.5, 0.4);
129 
130  for (i=first; i<=last; ++i) fPieSlices[i-first]->SetValue(h->GetBinContent(i));
131  if (axis->GetLabels()) {
132  for (i=first; i<=last; ++i) fPieSlices[i-first]->SetTitle(axis->GetBinLabel(i));
133  } else {
134  SetLabelFormat("%val");
135  }
136  SetTextSize(axis->GetLabelSize());
137  SetTextColor(axis->GetLabelColor());
138  SetTextFont(axis->GetLabelFont());
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// Copy constructor.
143 
144 TPie::TPie(const TPie &cpy) : TNamed(cpy), TAttText(cpy)
145 {
146  Init(cpy.fNvals, cpy.fAngularOffset, cpy.fX, cpy.fY, cpy.fRadius);
147 
148  for (Int_t i=0;i<fNvals;++i) {
149  fPieSlices[i] = cpy.fPieSlices[i];
150  }
151 }
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// Destructor.
155 
157 {
158  if (fNvals>0) {
159  for (int i=0; i<fNvals; ++i) delete fPieSlices[i];
160  delete [] fPieSlices;
161  }
162 
163  if (fSlices) delete [] fSlices;
164  if (fLegend) delete fLegend;
165 }
166 
167 ////////////////////////////////////////////////////////////////////////////////
168 /// Evaluate the distance to the chart in gPad.
169 
171 {
172  Int_t dist = 9999;
173 
175  if ( gCurrent_slice>=0 ) {
176  if (gCurrent_rad<=fRadius) {
177  dist = 0;
178  }
179  }
180 
181  return dist;
182 }
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// Returns the slice number at the pixel position (px,py).
186 /// Returns -1 if no slice is picked.
187 ///
188 /// Used by DistancetoPrimitive.
189 
191 {
192  MakeSlices();
193 
194  Int_t result(-1);
195 
196  // coordinates
197  Double_t xx = gPad->AbsPixeltoX(px); //gPad->PadtoX(gPad->AbsPixeltoX(px));
198  Double_t yy = gPad->AbsPixeltoY(py); //gPad->PadtoY(gPad->AbsPixeltoY(py));
199 
200  // XY metric
201  Double_t radX = fRadius;
202  Double_t radY = fRadius;
203  Double_t radXY = 1.;
204  if (fIs3D==kTRUE) {
205  radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
206  radY = radXY*radX;
207  }
208 
209  Double_t phimin;
210  Double_t cphi;
211  Double_t phimax;
212 
213  Float_t dPxl = (gPad->PixeltoY(0)-gPad->PixeltoY(1))/radY;
214  for (Int_t i=0;i<fNvals;++i) {
216 
217  if (gIsUptSlice && gCurrent_slice!=i) continue;
218 
219  // Angles' values for this slice
220  phimin = fSlices[2*i ]*TMath::Pi()/180.;
221  cphi = fSlices[2*i+1]*TMath::Pi()/180.;
222  phimax = fSlices[2*i+2]*TMath::Pi()/180.;
223 
224  Double_t radOffset = fPieSlices[i]->GetRadiusOffset();
225 
226  Double_t dx = (xx-fX-radOffset*TMath::Cos(cphi))/radX;
227  Double_t dy = (yy-fY-radOffset*TMath::Sin(cphi)*radXY)/radY;
228 
229  if (TMath::Abs(dy)<dPxl) dy = dPxl;
230 
231  Double_t ang = TMath::ATan2(dy,dx);
232  if (ang<0) ang += TMath::TwoPi();
233 
234  Double_t dist = TMath::Sqrt(dx*dx+dy*dy);
235 
236  if ( ((ang>=phimin && ang <= phimax) || (phimax>TMath::TwoPi() &&
237  ang+TMath::TwoPi()>=phimin && ang+TMath::TwoPi()<phimax)) &&
238  dist<=1.) { // if true the pointer is in the slice region
239 
240  gCurrent_x = dx;
241  gCurrent_y = dy;
242  gCurrent_ang = ang;
243  gCurrent_phi1 = phimin;
244  gCurrent_phi2 = phimax;
246 
247  if (dist<.95 && dist>.65) {
248  Double_t range = phimax-phimin;
249  Double_t lang = ang-phimin;
250  Double_t rang = phimax-ang;
251  if (lang<0) lang += TMath::TwoPi();
252  else if (lang>=TMath::TwoPi()) lang -= TMath::TwoPi();
253  if (rang<0) rang += TMath::TwoPi();
254  else if (rang>=TMath::TwoPi()) rang -= TMath::TwoPi();
255 
256  if (lang/range<.25 || rang/range<.25) {
258  result = -1;
259  }
260  else result = i;
261  } else {
262  result = i;
263  }
264 
265  break;
266  }
267  }
268  return result;
269 }
270 
271 ////////////////////////////////////////////////////////////////////////////////
272 /// Draw the pie chart.
273 ///
274 /// The possible options are listed in the TPie::Paint() method.
275 
276 void TPie::Draw(Option_t *option)
277 {
278  TString soption(option);
279  soption.ToLower();
280 
281  if (soption.Length()==0) soption = "l";
282 
283  if (gPad) {
284  if (!gPad->IsEditable()) gROOT->MakeDefCanvas();
285  if (!soption.Contains("same")) {
286  gPad->Clear();
287  gPad->Range(0.,0.,1.,1.);
288  }
289  }
290 
291  for (Int_t i=0;i<fNvals;++i) fPieSlices[i]->AppendPad();
292  AppendPad(soption.Data());
293 }
294 
295 ////////////////////////////////////////////////////////////////////////////////
296 /// This method is for internal use. It is used by Execute event to draw the
297 /// outline of "this" TPie. Used when the opaque movements are not permitted.
298 
300 {
301  MakeSlices();
302 
303  // XY metric
304  Double_t radXY = 1.;
305  if (fIs3D) {
306  radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
307  }
308 
309  for (Int_t i=0;i<fNvals&&fIs3D==kTRUE;++i) {
310  Float_t minphi = (fSlices[i*2]+gAngularOffset+.5)*TMath::Pi()/180.;
311  Float_t avgphi = (fSlices[i*2+1]+gAngularOffset)*TMath::Pi()/180.;
312  Float_t maxphi = (fSlices[i*2+2]+gAngularOffset-.5)*TMath::Pi()/180.;
313 
314  Double_t radOffset = (i == gCurrent_slice ? gRadiusOffset : fPieSlices[i]->GetRadiusOffset());
315  Double_t x0 = gX+radOffset*TMath::Cos(avgphi);
316  Double_t y0 = gY+radOffset*TMath::Sin(avgphi)*radXY-fHeight;
317 
318  gVirtualX->DrawLine( gPad->XtoAbsPixel(x0), gPad->YtoAbsPixel(y0),
319  gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(minphi)),
320  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(minphi)*radXY) );
321 
322  Int_t ndiv = 10;
323  Double_t dphi = (maxphi-minphi)/ndiv;
324 
325  if (dphi>.15) ndiv = (Int_t) ((maxphi-minphi)/.15);
326  dphi = (maxphi-minphi)/ndiv;
327 
328  // Loop to draw the arc
329  for (Int_t j=0;j<ndiv;++j) {
330  Double_t phi = minphi+dphi*j;
331  gVirtualX->DrawLine( gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(phi)),
332  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(phi)*radXY),
333  gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(phi+dphi)),
334  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(phi+dphi)*radXY));
335  }
336 
337  gVirtualX->DrawLine( gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(maxphi)),
338  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(maxphi)*radXY),
339  gPad->XtoAbsPixel(x0), gPad->YtoAbsPixel(y0) );
340 
341  gVirtualX->DrawLine(gPad->XtoAbsPixel(x0),
342  gPad->YtoAbsPixel(y0),
343  gPad->XtoAbsPixel(x0),
344  gPad->YtoAbsPixel(y0+fHeight));
345  gVirtualX->DrawLine(gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(minphi)),
346  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(minphi)*radXY),
347  gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(minphi)),
348  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(minphi)*radXY+fHeight));
349  gVirtualX->DrawLine(gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(maxphi)),
350  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(maxphi)*radXY),
351  gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(maxphi)),
352  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(maxphi)*radXY+fHeight));
353  }
354 
355 
356  // Loop over slices
357  for (Int_t i=0;i<fNvals;++i) {
358  Float_t minphi = (fSlices[i*2]+gAngularOffset+.5)*TMath::Pi()/180.;
359  Float_t avgphi = (fSlices[i*2+1]+gAngularOffset)*TMath::Pi()/180.;
360  Float_t maxphi = (fSlices[i*2+2]+gAngularOffset-.5)*TMath::Pi()/180.;
361 
362  Double_t radOffset = (i == gCurrent_slice ? gRadiusOffset : fPieSlices[i]->GetRadiusOffset());
363  Double_t x0 = gX+radOffset*TMath::Cos(avgphi);
364  Double_t y0 = gY+radOffset*TMath::Sin(avgphi)*radXY;
365 
366  gVirtualX->DrawLine( gPad->XtoAbsPixel(x0), gPad->YtoAbsPixel(y0),
367  gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(minphi)),
368  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(minphi)*radXY) );
369 
370 
371  Int_t ndiv = 10;
372  Double_t dphi = (maxphi-minphi)/ndiv;
373 
374  if (dphi>.15) ndiv = (Int_t) ((maxphi-minphi)/.15);
375  dphi = (maxphi-minphi)/ndiv;
376 
377  // Loop to draw the arc
378  for (Int_t j=0;j<ndiv;++j) {
379  Double_t phi = minphi+dphi*j;
380  gVirtualX->DrawLine( gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(phi)),
381  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(phi)*radXY),
382  gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(phi+dphi)),
383  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(phi+dphi)*radXY));
384  }
385 
386  gVirtualX->DrawLine( gPad->XtoAbsPixel(x0+gRadius*TMath::Cos(maxphi)),
387  gPad->YtoAbsPixel(y0+gRadius*TMath::Sin(maxphi)*radXY),
388  gPad->XtoAbsPixel(x0), gPad->YtoAbsPixel(y0) );
389  }
390 }
391 
392 ////////////////////////////////////////////////////////////////////////////////
393 /// Execute the mouse events.
394 
395 void TPie::ExecuteEvent(Int_t event, Int_t px, Int_t py)
396 {
397  if (!gPad) return;
398  if (!gPad->IsEditable() && event != kMouseEnter) return;
399 
400  if (gCurrent_slice<=-10) {
401  gPad->SetCursor(kCross);
402  return;
403  }
404 
405  MakeSlices();
406 
407  static bool isMovingPie(kFALSE);
408  static bool isMovingSlice(kFALSE);
409  static bool isResizing(kFALSE);
410  static bool isRotating(kFALSE);
411  static bool onBorder(kFALSE);
412  bool isRedrawing(kFALSE);
413  static Int_t prev_event(-1);
414  static Int_t oldpx, oldpy;
415 
416  // Portion of pie considered as "border"
417  const Double_t dr = gPad->PixeltoX(3);
418  const Double_t minRad = gPad->PixeltoX(10);
419 
420  // Angular divisions in radial direction
421  const Double_t angstep1 = 0.5*TMath::PiOver4();
422  const Double_t angstep2 = 1.5*TMath::PiOver4();
423  const Double_t angstep3 = 2.5*TMath::PiOver4();
424  const Double_t angstep4 = 3.5*TMath::PiOver4();
425  const Double_t angstep5 = 4.5*TMath::PiOver4();
426  const Double_t angstep6 = 5.5*TMath::PiOver4();
427  const Double_t angstep7 = 6.5*TMath::PiOver4();
428  const Double_t angstep8 = 7.5*TMath::PiOver4();
429 
430  // XY metric
431  Double_t radXY = 1.;
432  if (fIs3D==kTRUE) {
433  radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
434  }
435 
436  Int_t dx, dy;
437  Double_t mdx, mdy;
438 
439  switch(event) {
440  case kArrowKeyPress:
441  case kButton1Down:
442  // Change cursor to show pie's movement.
443  gVirtualX->SetLineColor(1);
444  gVirtualX->SetLineWidth(2);
445 
446  // Current center and radius.
447  gX = fX;
448  gY = fY;
449  gRadius = fRadius;
451  gAngularOffset = 0;
452  gIsUptSlice = kTRUE;
453 
454  prev_event = kButton1Down;
455 
456  case kMouseMotion:
457  if (gCurrent_rad>=fRadius-2.*dr && gCurrent_rad<=fRadius+dr
458  && !isMovingPie && !isMovingSlice && !isResizing) {
459  if (gCurrent_ang>=angstep8 || gCurrent_ang<angstep1)
460  gPad->SetCursor(kRightSide);
461  else if (gCurrent_ang>=angstep1 && gCurrent_ang<angstep2)
462  gPad->SetCursor(kTopRight);
463  else if (gCurrent_ang>=angstep2 && gCurrent_ang<angstep3)
464  gPad->SetCursor(kTopSide);
465  else if (gCurrent_ang>=angstep3 && gCurrent_ang<angstep4)
466  gPad->SetCursor(kTopLeft);
467  else if (gCurrent_ang>=angstep4 && gCurrent_ang<=angstep5)
468  gPad->SetCursor(kLeftSide);
469  else if (gCurrent_ang>=angstep5 && gCurrent_ang<angstep6)
470  gPad->SetCursor(kBottomLeft);
471  else if (gCurrent_ang>=angstep6 && gCurrent_ang<angstep7)
472  gPad->SetCursor(kBottomSide);
473  else if (gCurrent_ang>=angstep7 && gCurrent_ang<angstep8)
474  gPad->SetCursor(kBottomRight);
475  onBorder = kTRUE;
476  } else {
477  onBorder = kFALSE;
478  if (gCurrent_rad>fRadius*.6) {
479  gPad->SetCursor(kPointer);
480  } else if (gCurrent_rad<=fRadius*.3) {
481  gPad->SetCursor(kHand);
482  } else if (gCurrent_rad<=fRadius*.6 && gCurrent_rad>=fRadius*.3) {
483  gPad->SetCursor(kRotate);
484  }
485  }
486  oldpx = px;
487  oldpy = py;
488  if (isMovingPie || isMovingSlice) gPad->SetCursor(kMove);
489  break;
490 
491  case kArrowKeyRelease:
492  case kButton1Motion:
493  if (!isMovingSlice || !isMovingPie || !isResizing || !isRotating) {
494  if (prev_event==kButton1Down) {
495  if (onBorder) {
496  isResizing = kTRUE;
497  } else if (gCurrent_rad>=fRadius*.6 && gCurrent_slice>=0) {
498  isMovingSlice = kTRUE;
499  } else if (gCurrent_rad<=fRadius*.3) {
500  isMovingPie = kTRUE;
501  } else if (gCurrent_rad<fRadius*.6 && gCurrent_rad>fRadius*.3) {
502  isRotating = kTRUE;
503  }
504  }
505  }
506 
507  dx = px-oldpx;
508  dy = py-oldpy;
509 
510  mdx = gPad->PixeltoX(dx);
511  mdy = gPad->PixeltoY(dy);
512 
513  if (isMovingPie || isMovingSlice) {
514  gPad->SetCursor(kMove);
515  if (isMovingSlice) {
516  Float_t avgphi = fSlices[gCurrent_slice*2+1]*TMath::Pi()/180.;
517 
518  if (!gPad->OpaqueMoving()) DrawGhost();
519 
520  gRadiusOffset += TMath::Cos(avgphi)*mdx +TMath::Sin(avgphi)*mdy/radXY;
521  if (gRadiusOffset<0) gRadiusOffset = .0;
522  gIsUptSlice = kTRUE;
523 
524  if (!gPad->OpaqueMoving()) DrawGhost();
525  } else {
526  if (!gPad->OpaqueMoving()) DrawGhost();
527 
528  gX += mdx;
529  gY += mdy;
530 
531  if (!gPad->OpaqueMoving()) DrawGhost();
532  }
533  } else if (isResizing) {
534  if (!gPad->OpaqueResizing()) DrawGhost();
535 
536  Float_t dr1 = mdx*TMath::Cos(gCurrent_ang)+mdy*TMath::Sin(gCurrent_ang)/radXY;
537  if (gRadius+dr1>=minRad) {
538  gRadius += dr1;
539  } else {
540  gRadius = minRad;
541  }
542 
543  if (!gPad->OpaqueResizing()) DrawGhost();
544  } else if (isRotating) {
545  if (!gPad->OpaqueMoving()) DrawGhost();
546 
547  Double_t xx = gPad->AbsPixeltoX(px);
548  Double_t yy = gPad->AbsPixeltoY(py);
549 
550  Double_t dx1 = xx-gX;
551  Double_t dy1 = yy-gY;
552 
553  Double_t ang = TMath::ATan2(dy1,dx1);
554  if (ang<0) ang += TMath::TwoPi();
555 
556  gAngularOffset = (ang-gCurrent_ang)*180/TMath::Pi();
557 
558  if (!gPad->OpaqueMoving()) DrawGhost();
559  }
560 
561  oldpx = px;
562  oldpy = py;
563 
564  if ( ((isMovingPie || isMovingSlice || isRotating) && gPad->OpaqueMoving()) ||
565  (isResizing && gPad->OpaqueResizing()) ) {
566  isRedrawing = kTRUE;
567  event = kButton1Up;
568  }
569  else break;
570 
571  case kButton1Up:
572  if (!isRedrawing) {
573  prev_event = kButton1Up;
575  }
576 
577  if (gROOT->IsEscaped()) {
578  gROOT->SetEscape(kFALSE);
580  isRedrawing = kFALSE;
581  break;
582  }
583 
584  fX = gX;
585  fY = gY;
586  fRadius = gRadius;
589 
590  if (isRedrawing && (isMovingPie || isMovingSlice)) gPad->SetCursor(kMove);
591 
592  if (isMovingPie) isMovingPie = kFALSE;
593  if (isMovingSlice) isMovingSlice = kFALSE;
594  if (isResizing) isResizing = kFALSE;
595  if (isRotating) {
596  isRotating = kFALSE;
597  // this is important mainly when OpaqueMoving==kTRUE
599  }
600 
601  gPad->Modified(kTRUE);
602 
603 
604  isRedrawing = kFALSE;
606 
607  gVirtualX->SetLineColor(-1);
608  gVirtualX->SetLineWidth(-1);
609 
610  break;
611  case kButton1Locate:
612 
613  ExecuteEvent(kButton1Down, px, py);
614 
615  while (1) {
616  px = py = 0;
617  event = gVirtualX->RequestLocator(1, 1, px, py);
618 
619  ExecuteEvent(kButton1Motion, px, py);
620 
621  if (event != -1) { // button is released
622  ExecuteEvent(kButton1Up, px, py);
623  return;
624  }
625  }
626  break;
627 
628  case kMouseEnter:
629  break;
630 
631  default:
632  // unknown event
633  break;
634  }
635 }
636 
637 ////////////////////////////////////////////////////////////////////////////////
638 /// Returns the label of the entry number "i".
639 
641 {
642  return GetSlice(i)->GetTitle();
643 }
644 
645 ////////////////////////////////////////////////////////////////////////////////
646 /// Return the color of the slice number "i".
647 
649 {
650  return GetSlice(i)->GetFillColor();
651 }
652 
653 ////////////////////////////////////////////////////////////////////////////////
654 /// Return the style use to fill the slice number "i".
655 
657 {
658  return GetSlice(i)->GetFillStyle();
659 }
660 
661 ////////////////////////////////////////////////////////////////////////////////
662 /// Return the line color used to outline thi "i" slice
663 
665 {
666  return GetSlice(i)->GetLineColor();
667 }
668 
669 ////////////////////////////////////////////////////////////////////////////////
670 /// Return the style used to outline thi "i" slice
671 
673 {
674  return GetSlice(i)->GetLineStyle();
675 }
676 
677 ////////////////////////////////////////////////////////////////////////////////
678 /// Return the line width used to outline thi "i" slice
679 
681 {
682  return GetSlice(i)->GetLineWidth();
683 }
684 
685 ////////////////////////////////////////////////////////////////////////////////
686 /// Return the radial offset's value for the slice number "i".
687 
689 {
690  return GetSlice(i)->GetRadiusOffset();
691 }
692 
693 ////////////////////////////////////////////////////////////////////////////////
694 /// Return the value associated with the slice number "i".
695 
697 {
698  return GetSlice(i)->GetValue();
699 }
700 
701 ////////////////////////////////////////////////////////////////////////////////
702 /// If created before by Paint option or by MakeLegend method return
703 /// the pointer to the legend, otherwise return 0;
704 
706 {
707  return fLegend;
708 }
709 
710 ////////////////////////////////////////////////////////////////////////////////
711 /// Return the reference to the slice of index 'id'. There are no controls
712 /// of memory corruption, be carefull.
713 
715 {
716  return fPieSlices[id];
717 }
718 
719 ////////////////////////////////////////////////////////////////////////////////
720 /// Common initialization for all constructors.
721 /// This is a private function called to allocate the memory.
722 
724 {
726 
727  fAngularOffset = ao;
728  fX = x;
729  fY = y;
730  fRadius = r;
731  fNvals = np;
732  fSum = 0.;
733  fSlices = 0;
734  fLegend = 0;
735  fHeight = 0.08;
736  fAngle3D = 30;
737  fIs3D = kFALSE;
738 
740 
741  fPieSlices = new TPieSlice*[fNvals];
742 
743  for (Int_t i=0;i<fNvals;++i) {
744  TString tmplbl = "Slice";
745  tmplbl += i;
746  fPieSlices[i] = new TPieSlice(tmplbl.Data(), tmplbl.Data(), this);
747  fPieSlices[i]->SetRadiusOffset(0.);
748  fPieSlices[i]->SetLineColor(1);
749  fPieSlices[i]->SetLineStyle(1);
750  fPieSlices[i]->SetLineWidth(1);
751  fPieSlices[i]->SetFillColor(gStyle->GetColorPalette(i));
752  fPieSlices[i]->SetFillStyle(1001);
753  }
754 
755  fLabelFormat = "%txt";
756  fFractionFormat = "%3.2f";
757  fValueFormat = "%4.2f";
758  fPercentFormat = "%3.1f";
759 }
760 
761 ////////////////////////////////////////////////////////////////////////////////
762 /// This method create a legend that explains the contents
763 /// of the slice for this pie-chart.
764 ///
765 /// The parameter passed reppresents the option passed to shown the slices,
766 /// see TLegend::AddEntry() for further details.
767 ///
768 /// The pointer of the TLegend is returned.
769 
770 TLegend* TPie::MakeLegend(Double_t x1, Double_t y1, Double_t x2, Double_t y2, const char *leg_header)
771 {
772  if (!fLegend) fLegend = new TLegend(x1,y1,x2,y2,leg_header);
773  else fLegend->Clear();
774 
775  for (Int_t i=0;i<fNvals;++i) {
776  fLegend->AddEntry(*(fPieSlices+i),fPieSlices[i]->GetTitle(),"f");
777  }
778 
779  if (gPad) fLegend->Draw();
780 
781  return fLegend;
782 }
783 
784 ////////////////////////////////////////////////////////////////////////////////
785 /// Paint a Pie chart in a canvas.
786 /// The possible option are:
787 ///
788 /// - "R" Print the labels along the central "R"adius of slices.
789 /// - "T" Print the label in a direction "T"angent to circle that describes
790 /// the TPie.
791 /// - "SC" Paint the the labels with the "S"ame "C"olor as the slices.
792 /// - "3D" Draw the pie-chart with a pseudo 3D effect.
793 /// - "NOL" No OutLine: Don't draw the slices' outlines, any property over the
794 /// slices' line is ignored.
795 /// - ">" Sort the slices in increasing order.
796 /// - "<" Sort the slices in decreasing order.
797 ///
798 /// After the use of > or < options the internal order of the TPieSlices
799 /// is changed.
800 ///
801 /// Other options changing the labels' format are described in
802 /// TPie::SetLabelFormat().
803 
804 void TPie::Paint(Option_t *option)
805 {
806  MakeSlices();
807 
808  TString soption(option);
809 
810  bool optionSame(kFALSE);
811 
812  // if true the lines around the slices are drawn, if false not
813  Bool_t optionLine(kTRUE);
814 
815  // if true the labels' colors are the same as the slices' colors
816  Bool_t optionSameColor(kFALSE);
817 
818  // For the label orientation there are 3 possibilities:
819  // 0: horizontal
820  // 1: radial
821  // 2: tangent
822  Int_t lblor(0);
823 
824  // Parse the options
825  Int_t idx;
826  // Paint the TPie in an existing canvas
827  if ( (idx=soption.Index("same"))>=0 ) {
828  optionSame = kTRUE;
829  soption.Remove(idx,4);
830  }
831 
832  if ( (idx=soption.Index("nol"))>=0 ) {
833  optionLine = kFALSE;
834  soption.Remove(idx,3);
835  }
836 
837  if ( (idx=soption.Index("sc"))>=0 ) {
838  optionSameColor = kTRUE;
839  soption.Remove(idx,2);
840  }
841 
842  // check if is active the pseudo-3d
843  if ( (idx=soption.Index("3d"))>=0 ) {
844  fIs3D = kTRUE;
845  soption.Remove(idx,2);
846  } else {
847  fIs3D = kFALSE;
848  }
849 
850  // seek if have to draw the labels around the pie chart
851  if ( (idx=soption.Index("t"))>=0 ) {
852  lblor = 2;
853  soption.Remove(idx,1);
854  }
855 
856  // Seek if have to paint the labels along the radii
857  if ( (idx=soption.Index("r"))>=0 ) {
858  lblor = 1;
859  soption.Remove(idx,1);
860  }
861 
862  // Seeks if has to paint sort the slices in increasing mode
863  if ( (idx=soption.Index(">"))>=0 ) {
864  SortSlices(kTRUE);
865  soption.Remove(idx,1);
866  }
867 
868  // Seeks if has to paint sort the slices in decreasing mode
869  if ( (idx=soption.Index("<"))>=0 ) {
871  soption.Remove(idx,1);
872  }
873 
874  if (fNvals<=0) {
875  Warning("Paint","No vals");
876  return;
877  }
878 
879  if (!fPieSlices) {
880  Warning("Paint","No valid arrays of values");
881  return;
882  }
883 
884  // Check if gPad exists and define the drawing range.
885  if (!gPad) return;
886 
887  // Objects useful to draw labels and slices
888  TLatex *textlabel = new TLatex();
889  TArc *arc = new TArc();
890  TLine *line = new TLine();
891 
892  // XY metric
893  Double_t radX = fRadius;
894  Double_t radY = fRadius;
895  Double_t radXY = 1.;
896 
897  if (fIs3D) {
898  radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
899  radY = fRadius*radXY;
900  }
901 
902  // Draw the slices.
903  Int_t pixelHeight = gPad->YtoPixel(0)-gPad->YtoPixel(fHeight);
904  for (Int_t pi=0;pi<pixelHeight&&fIs3D==kTRUE; ++pi) { // loop for pseudo-3d effect
905  for (Int_t i=0;i<fNvals;++i) {
906  // draw the arc
907  // set the color of the next slice
908  if (pi>0) {
909  arc->SetFillStyle(0);
910  arc->SetLineColor(TColor::GetColorDark((fPieSlices[i]->GetFillColor())));
911  } else {
912  arc->SetFillStyle(0);
913  if (optionLine==kTRUE) {
914  arc->SetLineColor(fPieSlices[i]->GetLineColor());
915  arc->SetLineStyle(fPieSlices[i]->GetLineStyle());
916  arc->SetLineWidth(fPieSlices[i]->GetLineWidth());
917  } else {
918  arc->SetLineWidth(1);
919  arc->SetLineColor(TColor::GetColorDark((fPieSlices[i]->GetFillColor())));
920  }
921  }
922  // Paint the slice
923  Float_t aphi = fSlices[2*i+1]*TMath::Pi()/180.;
924 
926  Double_t ay = fY+TMath::Sin(aphi)*fPieSlices[i]->GetRadiusOffset()*radXY+gPad->PixeltoY(pixelHeight-pi);
927 
928  arc->PaintEllipse(ax, ay, radX, radY, fSlices[2*i],
929  fSlices[2*i+2], 0.);
930 
931  if (optionLine==kTRUE) {
932  line->SetLineColor(fPieSlices[i]->GetLineColor());
933  line->SetLineStyle(fPieSlices[i]->GetLineStyle());
934  line->SetLineWidth(fPieSlices[i]->GetLineWidth());
935  line->PaintLine(ax,ay,ax,ay);
936 
937  Double_t x0, y0;
938  x0 = ax+radX*TMath::Cos(fSlices[2*i]/180.*TMath::Pi());
939  y0 = ay+radY*TMath::Sin(fSlices[2*i]/180.*TMath::Pi());
940  line->PaintLine(x0,y0,x0,y0);
941 
942  x0 = ax+radX*TMath::Cos(fSlices[2*i+2]/180.*TMath::Pi());
943  y0 = ay+radY*TMath::Sin(fSlices[2*i+2]/180.*TMath::Pi());
944  line->PaintLine(x0,y0,x0,y0);
945  }
946  }
947  } // end loop for pseudo-3d effect
948 
949  for (Int_t i=0;i<fNvals;++i) { // loop for the piechart
950  // Set the color of the next slice
951  arc->SetFillColor(fPieSlices[i]->GetFillColor());
952  arc->SetFillStyle(fPieSlices[i]->GetFillStyle());
953  if (optionLine==kTRUE) {
954  arc->SetLineColor(fPieSlices[i]->GetLineColor());
955  arc->SetLineStyle(fPieSlices[i]->GetLineStyle());
956  arc->SetLineWidth(fPieSlices[i]->GetLineWidth());
957  } else {
958  arc->SetLineWidth(1);
959  arc->SetLineColor(fPieSlices[i]->GetFillColor());
960  }
961 
962  // Paint the slice
963  Float_t aphi = fSlices[2*i+1]*TMath::Pi()/180.;
964 
966  Double_t ay = fY+TMath::Sin(aphi)*fPieSlices[i]->GetRadiusOffset()*radXY;
967  arc->PaintEllipse(ax, ay, radX, radY, fSlices[2*i],
968  fSlices[2*i+2], 0.);
969 
970  } // end loop to draw the slices
971 
972 
973  // Set the font
974  textlabel->SetTextFont(GetTextFont());
975  textlabel->SetTextSize(GetTextSize());
976  textlabel->SetTextColor(GetTextColor());
977 
978  // Loop to place the labels.
979  for (Int_t i=0;i<fNvals;++i) {
980  Float_t aphi = fSlices[2*i+1]*TMath::Pi()/180.;
981  //aphi = TMath::ATan2(TMath::Sin(aphi)*radXY,TMath::Cos(aphi));
982 
983  Float_t label_off = fLabelsOffset;
984 
985 
986  // Paint the text in the pad
987  TString tmptxt = fLabelFormat;
988 
989  tmptxt.ReplaceAll("%txt",fPieSlices[i]->GetTitle());
990  tmptxt.ReplaceAll("%val",Form(fValueFormat.Data(),fPieSlices[i]->GetValue()));
991  tmptxt.ReplaceAll("%frac",Form(fFractionFormat.Data(),fPieSlices[i]->GetValue()/fSum));
992  tmptxt.ReplaceAll("%perc",Form(Form("%s %s",fPercentFormat.Data(),"%s"),(fPieSlices[i]->GetValue()/fSum)*100,"%"));
993 
994  textlabel->SetTitle(tmptxt.Data());
995  Double_t h = textlabel->GetYsize();
996  Double_t w = textlabel->GetXsize();
997 
998  Float_t lx = fX+(fRadius+fPieSlices[i]->GetRadiusOffset()+label_off)*TMath::Cos(aphi);
999  Float_t ly = fY+(fRadius+fPieSlices[i]->GetRadiusOffset()+label_off)*TMath::Sin(aphi)*radXY;
1000 
1001  Double_t lblang = 0;
1002 
1003  if (lblor==1) { // radial direction for the label
1004  aphi = TMath::ATan2(TMath::Sin(aphi)*radXY,TMath::Cos(aphi));
1005  lblang += aphi;
1006  if (lblang<=0) lblang += TMath::TwoPi();
1007  if (lblang>TMath::TwoPi()) lblang-= TMath::TwoPi();
1008 
1009  lx += h/2.*TMath::Sin(lblang);
1010  ly -= h/2.*TMath::Cos(lblang);
1011 
1012  // This control prevent text up-side
1013  if (lblang>TMath::PiOver2() && lblang<=3.*TMath::PiOver2()) {
1014  lx += w*TMath::Cos(lblang)-h*TMath::Sin(lblang);
1015  ly += w*TMath::Sin(lblang)+h*TMath::Cos(lblang);
1016  lblang -= TMath::Pi();
1017  }
1018  } else if (lblor==2) { // tangential direction of the labels
1019  aphi -=TMath::PiOver2();
1020  aphi = TMath::ATan2(TMath::Sin(aphi)*radXY,TMath::Cos(aphi));
1021  lblang += aphi;//-TMath::PiOver2();
1022  if (lblang<0) lblang+=TMath::TwoPi();
1023 
1024  lx -= w/2.*TMath::Cos(lblang);
1025  ly -= w/2.*TMath::Sin(lblang);
1026 
1027  if (lblang>TMath::PiOver2() && lblang<3.*TMath::PiOver2()) {
1028  lx += w*TMath::Cos(lblang)-h*TMath::Sin(lblang);
1029  ly += w*TMath::Sin(lblang)+h*TMath::Cos(lblang);
1030  lblang -= TMath::Pi();
1031  }
1032  } else { // horizontal labels (default direction)
1033  aphi = TMath::ATan2(TMath::Sin(aphi)*radXY,TMath::Cos(aphi));
1034  if (aphi>TMath::PiOver2() || aphi<=-TMath::PiOver2()) lx -= w;
1035  if (aphi<0) ly -= h;
1036  }
1037 
1038  Float_t rphi = TMath::ATan2((ly-fY)*radXY,lx-fX);
1039  if (rphi < 0 && fIs3D && label_off>=0.)
1040  ly -= fHeight;
1041 
1042  if (optionSameColor) textlabel->SetTextColor((fPieSlices[i]->GetFillColor()));
1043  textlabel->PaintLatex(lx,ly,
1044  lblang*180/TMath::Pi()+GetTextAngle(),
1045  GetTextSize(), tmptxt.Data());
1046  }
1047 
1048  delete arc;
1049  delete line;
1050  delete textlabel;
1051 
1052  if (optionSame) return;
1053 
1054  // Draw title
1055  TPaveText *title = 0;
1056  TObject *obj;
1057  if ((obj = gPad->GetListOfPrimitives()->FindObject("title"))) {
1058  title = dynamic_cast<TPaveText*>(obj);
1059  }
1060 
1061  // Check the OptTitle option
1062  if (strlen(GetTitle()) == 0 || gStyle->GetOptTitle() <= 0) {
1063  if (title) delete title;
1064  return;
1065  }
1066 
1067  // Height and width of the title
1068  Double_t ht = gStyle->GetTitleH();
1069  Double_t wt = gStyle->GetTitleW();
1070  if (ht<=0) ht = 1.1*gStyle->GetTitleFontSize();
1071  if (ht<=0) ht = 0.05; // minum height
1072  if (wt<=0) { // eval the width of the title
1073  TLatex l;
1074  l.SetTextSize(ht);
1075  l.SetTitle(GetTitle());
1076  // adjustment in case the title has several lines (#splitline)
1077  ht = TMath::Max(ht, 1.2*l.GetYsize()/(gPad->GetY2() - gPad->GetY1()));
1078  Double_t wndc = l.GetXsize()/(gPad->GetX2() - gPad->GetX1());
1079  wt = TMath::Min(0.7, 0.02+wndc);
1080  }
1081 
1082  if (title) {
1083  TText *t0 = (TText*)title->GetLine(0);
1084  if (t0) {
1085  if (!strcmp(t0->GetTitle(),GetTitle())) return;
1086  t0->SetTitle(GetTitle());
1087  if (wt > 0) title->SetX2NDC(title->GetX1NDC()+wt);
1088  }
1089  return;
1090  }
1091 
1092  Int_t talh = gStyle->GetTitleAlign()/10;
1093  if (talh < 1) talh = 1; else if (talh > 3) talh = 3;
1094  Int_t talv = gStyle->GetTitleAlign()%10;
1095  if (talv < 1) talv = 1; else if (talv > 3) talv = 3;
1096  Double_t xpos, ypos;
1097  xpos = gStyle->GetTitleX();
1098  ypos = gStyle->GetTitleY();
1099  if (talh == 2) xpos = xpos-wt/2.;
1100  if (talh == 3) xpos = xpos-wt;
1101  if (talv == 2) ypos = ypos+ht/2.;
1102  if (talv == 1) ypos = ypos+ht;
1103 
1104  title = new TPaveText(xpos,ypos-ht,xpos+wt,ypos,"blNDC");
1105  title->SetFillColor(gStyle->GetTitleFillColor());
1106  title->SetFillStyle(gStyle->GetTitleStyle());
1107  title->SetName("title");
1108 
1110  title->SetTextColor(gStyle->GetTitleTextColor());
1111  title->SetTextFont(gStyle->GetTitleFont(""));
1112  if (gStyle->GetTitleFont("")%10 > 2)
1113  title->SetTextSize(gStyle->GetTitleFontSize());
1114  title->AddText(GetTitle());
1115 
1116  title->SetBit(kCanDelete);
1117 
1118  title->Draw();
1119  title->Paint();
1120 }
1121 
1122 ////////////////////////////////////////////////////////////////////////////////
1123 /// Save primitive as a C++ statement(s) on output stream out
1124 
1125 void TPie::SavePrimitive(std::ostream &out, Option_t *option)
1126 {
1127  out << " " << std::endl;
1128  if (gROOT->ClassSaved(TPie::Class())) {
1129  out << " ";
1130  } else {
1131  out << " TPie *";
1132  }
1133  out << GetName() << " = new TPie(\"" << GetName() << "\", \"" << GetTitle()
1134  << "\", " << fNvals << ");" << std::endl;
1135  out << " " << GetName() << "->SetCircle(" << fX << ", " << fY << ", "
1136  << fRadius << ");" << std::endl;
1137  out << " " << GetName() << "->SetValueFormat(\"" << GetValueFormat()
1138  << "\");" << std::endl;
1139  out << " " << GetName() << "->SetLabelFormat(\"" << GetLabelFormat()
1140  << "\");" << std::endl;
1141  out << " " << GetName() << "->SetPercentFormat(\"" << GetPercentFormat()
1142  << "\");" << std::endl;
1143  out << " " << GetName() << "->SetLabelsOffset(" << GetLabelsOffset()
1144  << ");" << std::endl;
1145  out << " " << GetName() << "->SetAngularOffset(" << GetAngularOffset()
1146  << ");" << std::endl;
1147  out << " " << GetName() << "->SetTextAngle(" << GetTextAngle() << ");" << std::endl;
1148  out << " " << GetName() << "->SetTextColor(" << GetTextColor() << ");" << std::endl;
1149  out << " " << GetName() << "->SetTextFont(" << GetTextFont() << ");" << std::endl;
1150  out << " " << GetName() << "->SetTextSize(" << GetTextSize() << ");" << std::endl;
1151 
1152 
1153  // Save the values for the slices
1154  for (Int_t i=0;i<fNvals;++i) {
1155  out << " " << GetName() << "->GetSlice(" << i << ")->SetTitle(\""
1156  << fPieSlices[i]->GetTitle() << "\");" << std::endl;
1157  out << " " << GetName() << "->GetSlice(" << i << ")->SetValue("
1158  << fPieSlices[i]->GetValue() << ");" << std::endl;
1159  out << " " << GetName() << "->GetSlice(" << i << ")->SetRadiusOffset("
1160  << fPieSlices[i]->GetRadiusOffset() << ");" << std::endl;
1161  out << " " << GetName() << "->GetSlice(" << i << ")->SetFillColor("
1162  << fPieSlices[i]->GetFillColor() << ");" << std::endl;
1163  out << " " << GetName() << "->GetSlice(" << i << ")->SetFillStyle("
1164  << fPieSlices[i]->GetFillStyle() << ");" << std::endl;
1165  out << " " << GetName() << "->GetSlice(" << i << ")->SetLineColor("
1166  << fPieSlices[i]->GetLineColor() << ");" << std::endl;
1167  out << " " << GetName() << "->GetSlice(" << i << ")->SetLineStyle("
1168  << fPieSlices[i]->GetLineStyle() << ");" << std::endl;
1169  out << " " << GetName() << "->GetSlice(" << i << ")->SetLineWidth("
1170  << fPieSlices[i]->GetLineWidth() << ");" << std::endl;
1171  }
1172 
1173  out << " " << GetName() << "->Draw(\"" << option << "\");" << std::endl;
1174 }
1175 
1176 ////////////////////////////////////////////////////////////////////////////////
1177 /// Set the value of for the pseudo 3D view angle, in degree.
1178 /// The range of the permitted values is: [0,90]
1179 
1181  // check if val is in the permitted range
1182  while (val>360.) val -= 360.;
1183  while (val<0) val += 360.;
1184  if (val>=90 && val<180) val = 180-val;
1185  else if (val>=180 && val<=360) val = 360-val;
1186 
1187  fAngle3D = val;
1188 }
1189 
1190 ////////////////////////////////////////////////////////////////////////////////
1191 /// Set the global angular offset for slices in degree [0,360]
1192 
1194 {
1195  fAngularOffset = offset;
1196 
1197  while (fAngularOffset>=360.) fAngularOffset -= 360.;
1198  while (fAngularOffset<0.) fAngularOffset += 360.;
1199 
1200  MakeSlices(kTRUE);
1201 }
1202 
1203 ////////////////////////////////////////////////////////////////////////////////
1204 /// Set the coordinates of the circle that describe the pie:
1205 /// - the 1st and the 2nd arguments are the x and y center's coordinates.
1206 /// - the 3rd value is the pie-chart's radius.
1207 ///
1208 /// All the coordinates are in NDC space.
1209 
1211 {
1212  fX = x;
1213  fY = y;
1214  fRadius = rad;
1215 }
1216 
1217 ////////////////////////////////////////////////////////////////////////////////
1218 /// Set slice number "i" label. The first parameter is the index of the slice,
1219 /// the other is the label text.
1220 
1221 void TPie::SetEntryLabel(Int_t i, const char *text)
1222 {
1223  // Set the Label of a single slice
1224  if (i>=0 && i<fNvals) fPieSlices[i]->SetTitle(text);
1225 }
1226 
1227 ////////////////////////////////////////////////////////////////////////////////
1228 /// Set the color for the slice's outline. "i" is the slice number.
1229 
1231 {
1232  if (i>=0 && i<fNvals) fPieSlices[i]->SetLineColor(color);
1233 }
1234 
1235 ////////////////////////////////////////////////////////////////////////////////
1236 /// Set the style for the slice's outline. "i" is the slice number.
1237 
1239 {
1240  if (i>=0 && i<fNvals) fPieSlices[i]->SetLineStyle(style);
1241 }
1242 
1243 ////////////////////////////////////////////////////////////////////////////////
1244 /// Set the width of the slice's outline. "i" is the slice number.
1245 
1247 {
1248  if (i>=0 && i<fNvals) fPieSlices[i]->SetLineWidth(width);
1249 }
1250 
1251 ////////////////////////////////////////////////////////////////////////////////
1252 /// Set the color for the slice "i".
1253 
1255 {
1256  if (i>=0 && i<fNvals) fPieSlices[i]->SetFillColor(color);
1257 }
1258 
1259 ////////////////////////////////////////////////////////////////////////////////
1260 /// Set the fill style for the "i" slice
1261 
1263 {
1264  if (i>=0 && i<fNvals) fPieSlices[i]->SetFillStyle(style);
1265 }
1266 
1267 ////////////////////////////////////////////////////////////////////////////////
1268 /// Set the distance, in the direction of the radius of the slice.
1269 
1271 {
1272  if (i>=0 && i<fNvals) fPieSlices[i]->SetRadiusOffset(shift);
1273 }
1274 
1275 ////////////////////////////////////////////////////////////////////////////////
1276 /// Set the value of a slice
1277 
1279 {
1280  if (i>=0 && i<fNvals) fPieSlices[i]->SetValue(val);
1281 
1282  MakeSlices(kTRUE);
1283 }
1284 
1285 ////////////////////////////////////////////////////////////////////////////////
1286 /// Set the fill colors for all the TPie's slices.
1287 
1289 {
1290  if (!colors) return;
1291  for (Int_t i=0;i<fNvals;++i) fPieSlices[i]->SetFillColor(colors[i]);
1292 }
1293 
1294 ////////////////////////////////////////////////////////////////////////////////
1295 /// Set the height, in pixel, for the piechart if is drawn using
1296 /// the pseudo-3d mode.
1297 ///
1298 /// The default value is 20 pixel.
1299 
1300 void TPie::SetHeight(Double_t val/*=20*/)
1301 {
1302  fHeight = val;
1303 }
1304 
1305 ////////////////////////////////////////////////////////////////////////////////
1306 /// This method is used to customize the label format. The format string
1307 /// must contain one of these modifiers:
1308 ///
1309 /// - %txt : to print the text label associated with the slice
1310 /// - %val : to print the numeric value of the slice
1311 /// - %frac : to print the relative fraction of this slice
1312 /// - %perc : to print the % of this slice
1313 ///
1314 /// ex. : mypie->SetLabelFormat("%txt (%frac)");
1315 
1316 void TPie::SetLabelFormat(const char *fmt)
1317 {
1318  fLabelFormat = fmt;
1319 }
1320 
1321 ////////////////////////////////////////////////////////////////////////////////
1322 /// Set numeric format in the label, is used if the label format
1323 /// there is the modifier %frac, in this case the value is printed
1324 /// using this format.
1325 ///
1326 /// The numeric format use the standard C modifier used in stdio library:
1327 /// %f, %2.1$, %e... for further documentation you can use the printf
1328 /// man page ("man 3 printf" on linux)
1329 ///
1330 /// Example:
1331 /// ~~~ {.cpp}
1332 /// mypie->SetLabelFormat("%txt (%frac)");
1333 /// mypie->SetFractionFormat("2.1f");
1334 /// ~~~
1335 
1336 void TPie::SetFractionFormat(const char *fmt)
1337 {
1338  fFractionFormat = fmt;
1339 }
1340 
1341 ////////////////////////////////////////////////////////////////////////////////
1342 /// Set the labels for all the slices.
1343 
1344 void TPie::SetLabels(const char *lbls[])
1345 {
1346  if (!lbls) return;
1347  for (Int_t i=0;i<fNvals;++i) fPieSlices[i]->SetTitle(lbls[i]);
1348 }
1349 
1350 ////////////////////////////////////////////////////////////////////////////////
1351 /// Set the distance between the label end the external line of the TPie.
1352 
1353 void TPie::SetLabelsOffset(Float_t labelsoffset)
1354 {
1355  fLabelsOffset = labelsoffset;
1356 }
1357 
1358 ////////////////////////////////////////////////////////////////////////////////
1359 /// Set the numeric format for the percent value of a slice, default: %3.1f
1360 
1361 void TPie::SetPercentFormat(const char *fmt)
1362 {
1363  fPercentFormat = fmt;
1364 }
1365 
1366 ////////////////////////////////////////////////////////////////////////////////
1367 /// Set the pie chart's radius' value.
1368 
1370 {
1371  if (rad>0) {
1372  fRadius = rad;
1373  } else {
1374  Warning("SetRadius",
1375  "It's not possible set the radius to a negative value");
1376  }
1377 }
1378 
1379 ////////////////////////////////////////////////////////////////////////////////
1380 /// Set the numeric format the slices' values.
1381 /// Used by %val (see SetLabelFormat()).
1382 
1383 void TPie::SetValueFormat(const char *fmt)
1384 {
1385  fValueFormat = fmt;
1386 }
1387 
1388 ////////////////////////////////////////////////////////////////////////////////
1389 /// Set X value.
1390 
1392 {
1393  fX = x;
1394 }
1395 
1396 ////////////////////////////////////////////////////////////////////////////////
1397 /// Set Y value.
1398 
1400 {
1401  fY = y;
1402 }
1403 
1404 ////////////////////////////////////////////////////////////////////////////////
1405 /// Make the slices.
1406 /// If they already exist it does nothing unless force=kTRUE.
1407 
1409 {
1410  if (fSlices && !force) return;
1411 
1412  fSum = .0;
1413 
1414  for (Int_t i=0;i<fNvals;++i) {
1415  if (fPieSlices[i]->GetValue()<0) {
1416  Warning("MakeSlices",
1417  "Negative values in TPie, absolute value will be used");
1418  fPieSlices[i]->SetValue(-1.*fPieSlices[i]->GetValue());
1419  }
1420  fSum += fPieSlices[i]->GetValue();
1421  }
1422 
1423  if (fSum<=.0) return;
1424 
1425  if (!fSlices) fSlices = new Float_t[2*fNvals+1];
1426 
1427  // Compute the slices size and position (2 angles for each slice)
1428  fSlices[0] = fAngularOffset;
1429  for (Int_t i=0;i<fNvals;++i) {
1430  Float_t dphi = fPieSlices[i]->GetValue()/fSum*360.;
1431  fSlices[2*i+1] = fSlices[2*i]+dphi/2.;
1432  fSlices[2*i+2] = fSlices[2*i]+dphi;
1433  }
1434 }
1435 
1436 ////////////////////////////////////////////////////////////////////////////////
1437 /// This method, mainly intended for internal use, ordered the slices according their values.
1438 /// The default (amode=kTRUE) is increasing order, but is also possible in decreasing order (amode=kFALSE).
1439 ///
1440 /// If the merge_threshold>0 the slice that contains a quantity smaller than merge_threshold are merged
1441 /// together
1442 
1443 void TPie::SortSlices(Bool_t amode, Float_t merge_threshold)
1444 {
1445 
1446  // main loop to order, bubble sort, the array
1447  Bool_t isDone = kFALSE;
1448 
1449  while (isDone==kFALSE) {
1450  isDone = kTRUE;
1451 
1452  for (Int_t i=0;i<fNvals-1;++i) { // loop over the values
1453  if ( (amode && (fPieSlices[i]->GetValue()>fPieSlices[i+1]->GetValue())) ||
1454  (!amode && (fPieSlices[i]->GetValue()<fPieSlices[i+1]->GetValue()))
1455  )
1456  {
1457  // exchange the order
1458  TPieSlice *tmpcpy = fPieSlices[i];
1459  fPieSlices[i] = fPieSlices[i+1];
1460  fPieSlices[i+1] = tmpcpy;
1461 
1462  isDone = kFALSE;
1463  }
1464  } // end loop the values
1465  } // end main ordering loop
1466 
1467  if (merge_threshold>0) {
1468  // merge smallest slices
1469  TPieSlice *merged_slice = new TPieSlice("merged","other",this);
1470  merged_slice->SetRadiusOffset(0.);
1471  merged_slice->SetLineColor(1);
1472  merged_slice->SetLineStyle(1);
1473  merged_slice->SetLineWidth(1);
1474  merged_slice->SetFillColor(gStyle->GetColorPalette( (amode ? 0 : fNvals-1) ));
1475  merged_slice->SetFillStyle(1001);
1476 
1477  if (amode) {
1478  // search slices under the threshold
1479  Int_t iMerged = 0;
1480  for (;iMerged<fNvals&&fPieSlices[iMerged]->GetValue()<merge_threshold;++iMerged) {
1481  merged_slice->SetValue( merged_slice->GetValue()+fPieSlices[iMerged]->GetValue() );
1482  }
1483 
1484  // evaluate number of valid slices
1485  if (iMerged<=1) { // no slices to merge
1486  delete merged_slice;
1487  }
1488  else { // write a new array with the right dimension
1489  Int_t old_fNvals = fNvals;
1490  fNvals = fNvals-iMerged+1;
1491  TPieSlice **new_array = new TPieSlice*[fNvals];
1492  new_array[0] = merged_slice;
1493  for (Int_t i=0;i<old_fNvals;++i) {
1494  if (i<iMerged) delete fPieSlices[i];
1495  else new_array[i-iMerged+1] = fPieSlices[i];
1496  }
1497  delete [] fPieSlices;
1498  fPieSlices = new_array;
1499  }
1500  }
1501  else {
1502  Int_t iMerged = fNvals-1;
1503  for (;iMerged>=0&&fPieSlices[iMerged]->GetValue()<merge_threshold;--iMerged) {
1504  merged_slice->SetValue( merged_slice->GetValue()+fPieSlices[iMerged]->GetValue() );
1505  }
1506 
1507  // evaluate number of valid slices
1508  Int_t nMerged = fNvals-1-iMerged;
1509  if (nMerged<=1) { // no slices to merge
1510  delete merged_slice;
1511  }
1512  else { // write a new array with the right dimension
1513  Int_t old_fNvals = fNvals;
1514  fNvals = fNvals-nMerged+1;
1515  TPieSlice **new_array = new TPieSlice*[fNvals];
1516  new_array[fNvals-1] = merged_slice;
1517  for (Int_t i=old_fNvals-1;i>=0;--i) {
1518  if (i>iMerged) delete fPieSlices[i];
1519  else new_array[i-nMerged-1] = fPieSlices[i];
1520  }
1521  delete [] fPieSlices;
1522  fPieSlices = new_array;
1523  }
1524 
1525  }
1526  }
1527 
1528  MakeSlices(kTRUE);
1529 }
1530 
TAxis::GetBinLabel
const char * GetBinLabel(Int_t bin) const
Return label for bin.
Definition: TAxis.cxx:440
TPie::fIs3D
Bool_t fIs3D
! true if the pseudo-3d is enabled
Definition: TPie.h:44
l
auto * l
Definition: textangle.C:4
TPieSlice::GetValue
Double_t GetValue()
Return the value of this slice.
Definition: TPieSlice.cxx:76
TAttText
Definition: TAttText.h:18
TPie::SetY
void SetY(Double_t)
Set Y value.
Definition: TPie.cxx:1399
TPie.h
TPave::SetBorderSize
virtual void SetBorderSize(Int_t bordersize=4)
Definition: TPave.h:79
TPie::SetX
void SetX(Double_t)
Set X value.
Definition: TPie.cxx:1391
TAxis
Class to manage histogram axis.
Definition: TAxis.h:30
kLeftSide
@ kLeftSide
Definition: GuiTypes.h:372
first
Definition: first.py:1
TPaveText::Paint
virtual void Paint(Option_t *option="")
Paint this pavetext with its current attributes.
Definition: TPaveText.cxx:411
TPie::SortSlices
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:1443
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TLine.h
TArc
Definition: TArc.h:26
TMath::ATan2
Double_t ATan2(Double_t y, Double_t x)
Definition: TMath.h:668
kTopSide
@ kTopSide
Definition: GuiTypes.h:372
TPie::fValueFormat
TString fValueFormat
Vform numeric format for the value.
Definition: TPie.h:39
kRightSide
@ kRightSide
Definition: GuiTypes.h:372
TLine
Definition: TLine.h:22
TPieSlice::GetRadiusOffset
Double_t GetRadiusOffset()
return the value of the offset in radial direction for this slice.
Definition: TPieSlice.cxx:68
TStyle::GetTitleY
Float_t GetTitleY() const
Definition: TStyle.h:272
TMath::Max
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
TPie::SetLabels
void SetLabels(const char *[])
Set the labels for all the slices.
Definition: TPie.cxx:1344
TPie::SetCircle
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:1210
kButton1Motion
@ kButton1Motion
Definition: Buttons.h:26
TPie::ExecuteEvent
virtual void ExecuteEvent(Int_t, Int_t, Int_t)
Execute the mouse events.
Definition: TPie.cxx:395
TMath::Cos
Double_t Cos(Double_t)
Definition: TMath.h:630
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
TString::Data
const char * Data() const
Definition: TString.h:369
kBottomLeft
@ kBottomLeft
Definition: GuiTypes.h:371
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:54
TPie::SetRadius
void SetRadius(Double_t)
Set the pie chart's radius' value.
Definition: TPie.cxx:1369
r
ROOT::R::TRInterface & r
Definition: Object.C:4
TPie::TPie
TPie()
Default constructor.
Definition: TPie.cxx:63
TPie::fPieSlices
TPieSlice ** fPieSlices
[fNvals] Slice array of this pie-chart
Definition: TPie.h:43
colors
Color * colors
Definition: X3DBuffer.c:21
TStyle::GetTitleFontSize
Float_t GetTitleFontSize() const
Definition: TStyle.h:265
TPie::SetFillColors
void SetFillColors(Int_t *)
Set the fill colors for all the TPie's slices.
Definition: TPie.cxx:1288
kButton1Up
@ kButton1Up
Definition: Buttons.h:25
TLegend.h
TMath::Sqrt
Double_t Sqrt(Double_t x)
Definition: TMath.h:680
TAttAxis::GetLabelSize
virtual Float_t GetLabelSize() const
Definition: TAttAxis.h:47
TPie::MakeLegend
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:770
TArc.h
TPie::SetLabelsOffset
void SetLabelsOffset(Float_t)
Set the distance between the label end the external line of the TPie.
Definition: TPie.cxx:1353
TAxis::GetFirst
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:458
TPie::fAngle3D
Float_t fAngle3D
The angle of the pseudo-3d view.
Definition: TPie.h:46
Float_t
float Float_t
Definition: RtypesCore.h:57
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
TPie::fAngularOffset
Double_t fAngularOffset
Offset angular offset for the first slice.
Definition: TPie.h:36
TStyle.h
TMath::PiOver2
constexpr Double_t PiOver2()
Definition: TMath.h:57
Int_t
int Int_t
Definition: RtypesCore.h:45
TPie::SetLabelFormat
void SetLabelFormat(const char *)
This method is used to customize the label format.
Definition: TPie.cxx:1316
TPie::fLabelFormat
TString fLabelFormat
Format format of the slices' label.
Definition: TPie.h:38
TObject::AppendPad
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:107
TPie::SetEntryFillColor
void SetEntryFillColor(Int_t, Int_t)
Set the color for the slice "i".
Definition: TPie.cxx:1254
TString::Contains
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
x
Double_t x[n]
Definition: legend1.C:17
TString::Length
Ssiz_t Length() const
Definition: TString.h:410
TPave::SetX2NDC
virtual void SetX2NDC(Double_t x2)
Definition: TPave.h:85
TPie
Definition: TPie.h:23
TLatex
Definition: TLatex.h:18
TColor.h
TVirtualX.h
TMath::Abs
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
kBottomSide
@ kBottomSide
Definition: GuiTypes.h:372
TPie::GetLegend
TLegend * GetLegend()
If created before by Paint option or by MakeLegend method return the pointer to the legend,...
Definition: TPie.cxx:705
kMove
@ kMove
Definition: GuiTypes.h:373
gCurrent_x
Double_t gCurrent_x
Definition: TPie.cxx:55
kMouseMotion
@ kMouseMotion
Definition: Buttons.h:29
TLatex::GetXsize
Double_t GetXsize()
Return size of the formula along X in pad coordinates.
Definition: TLatex.cxx:2522
TPie::SetEntryLineColor
void SetEntryLineColor(Int_t, Int_t)
Set the color for the slice's outline. "i" is the slice number.
Definition: TPie.cxx:1230
gCurrent_ang
Double_t gCurrent_ang
Definition: TPie.cxx:57
TPie::fX
Double_t fX
X coordinate of the pie centre.
Definition: TPie.h:33
TPie::GetPercentFormat
const char * GetPercentFormat()
Definition: TPie.h:77
TString
Definition: TString.h:136
TPaveText::GetLine
virtual TText * GetLine(Int_t number) const
Get Pointer to line number in this pavetext.
Definition: TPaveText.cxx:275
gRadius
Double_t gRadius
Definition: TPie.cxx:45
TPie::Init
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:723
TPie::fHeight
Double_t fHeight
Height of the slice in pixel.
Definition: TPie.h:45
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
text
TText * text
Definition: entrylist_figure1.C:10
kBottomRight
@ kBottomRight
Definition: GuiTypes.h:371
TPie::SetEntryLineStyle
void SetEntryLineStyle(Int_t, Int_t)
Set the style for the slice's outline. "i" is the slice number.
Definition: TPie.cxx:1238
TPie::Draw
virtual void Draw(Option_t *option="l")
Draw the pie chart.
Definition: TPie.cxx:276
bool
TString::ReplaceAll
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
TStyle::GetTitleStyle
Style_t GetTitleStyle() const
Definition: TStyle.h:264
TPaveText.h
TPie::SetEntryLineWidth
void SetEntryLineWidth(Int_t, Int_t)
Set the width of the slice's outline. "i" is the slice number.
Definition: TPie.cxx:1246
id
XFontStruct * id
Definition: TGX11.cxx:109
TStyle::GetLabelOffset
Float_t GetLabelOffset(Option_t *axis="X") const
Return label offset.
Definition: TStyle.cxx:1090
x1
static const double x1[5]
Definition: RooGaussKronrodIntegrator1D.cxx:346
TROOT.h
gIsUptSlice
Bool_t gIsUptSlice
Definition: TPie.cxx:48
TPie::GetLabelsOffset
Float_t GetLabelsOffset()
Definition: TPie.h:74
TPaveText::Draw
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:234
TPie::GetEntryLineWidth
Int_t GetEntryLineWidth(Int_t)
Return the line width used to outline thi "i" slice.
Definition: TPie.cxx:680
style
TCanvas * style()
Definition: style.C:1
TAxis::GetLabels
THashList * GetLabels() const
Definition: TAxis.h:117
ROOT::Math::gv_detail::dist
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:63
gCurrent_rad
Double_t gCurrent_rad
Definition: TPie.cxx:53
TPie::SetValueFormat
void SetValueFormat(const char *)
Set the numeric format the slices' values.
Definition: TPie.cxx:1383
TPave::GetX1NDC
Double_t GetX1NDC() const
Definition: TPave.h:65
TMath::Pi
constexpr Double_t Pi()
Definition: TMath.h:43
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
kRotate
@ kRotate
Definition: GuiTypes.h:373
TLine::PaintLine
virtual void PaintLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this line with new coordinates.
Definition: TLine.cxx:384
TStyle::GetTitleBorderSize
Width_t GetTitleBorderSize() const
Definition: TStyle.h:266
TPie::SetPercentFormat
void SetPercentFormat(const char *)
Set the numeric format for the percent value of a slice, default: %3.1f.
Definition: TPie.cxx:1361
TPie::GetLabelFormat
const char * GetLabelFormat()
Definition: TPie.h:73
TStyle::GetTitleAlign
Int_t GetTitleAlign()
Definition: TStyle.h:261
TLegend::Clear
virtual void Clear(Option_t *option="")
Clear all entries in this legend, including the header.
Definition: TLegend.cxx:390
TLatex::GetYsize
Double_t GetYsize()
Return size of the formula along Y in pad coordinates.
Definition: TLatex.cxx:2609
kTopLeft
@ kTopLeft
Definition: GuiTypes.h:371
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
SetFillColor
h1 SetFillColor(kGreen)
TPie::MakeSlices
void MakeSlices(Bool_t force=kFALSE)
Make the slices.
Definition: TPie.cxx:1408
TPie::SetEntryLabel
void SetEntryLabel(Int_t, const char *text="Slice")
Set slice number "i" label.
Definition: TPie.cxx:1221
TStyle::GetTitleFillColor
Color_t GetTitleFillColor() const
Definition: TStyle.h:262
gCurrent_phi2
Double_t gCurrent_phi2
Definition: TPie.cxx:52
TPie::DrawGhost
void DrawGhost()
This method is for internal use.
Definition: TPie.cxx:299
TStyle::GetOptTitle
Int_t GetOptTitle() const
Definition: TStyle.h:237
h
#define h(i)
Definition: RSha256.hxx:124
TPie::fFractionFormat
TString fFractionFormat
Rform numeric format for the fraction of a slice.
Definition: TPie.h:40
TPieSlice.h
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
TAttAxis::GetLabelColor
virtual Color_t GetLabelColor() const
Definition: TAttAxis.h:44
TString::Remove
TString & Remove(Ssiz_t pos)
Definition: TString.h:673
TNamed
Definition: TNamed.h:29
TPieSlice
Definition: TPieSlice.h:18
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
kCross
@ kCross
Definition: GuiTypes.h:373
gY
Double_t gY
Definition: TPie.cxx:44
TPie::fSlices
Float_t * fSlices
!Subdivisions of the slices
Definition: TPie.h:29
SetTextColor
pt SetTextColor(4)
TLegend::AddEntry
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:330
TStyle::GetTitleTextColor
Color_t GetTitleTextColor() const
Definition: TStyle.h:263
TPie::GetEntryFillColor
Int_t GetEntryFillColor(Int_t)
Return the color of the slice number "i".
Definition: TPie.cxx:648
TPieSlice::SetValue
void SetValue(Double_t)
Set the value for this slice.
Definition: TPieSlice.cxx:101
TAxis::GetLast
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:469
TPie::SavePrimitive
void SavePrimitive(std::ostream &out, Option_t *opts="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TPie.cxx:1125
TStyle::GetColorPalette
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
Definition: TStyle.cxx:1058
TPie::fNvals
Int_t fNvals
Number of elements.
Definition: TPie.h:42
TMath::PiOver4
constexpr Double_t PiOver4()
Definition: TMath.h:64
TMath::Sin
Double_t Sin(Double_t)
Definition: TMath.h:626
TPie::GetValueFormat
const char * GetValueFormat()
Definition: TPie.h:80
TVirtualPad.h
y
Double_t y[n]
Definition: legend1.C:17
kButton1Locate
@ kButton1Locate
Definition: Buttons.h:28
gCurrent_phi1
Double_t gCurrent_phi1
Definition: TPie.cxx:51
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
line
TLine * line
Definition: entrylistblock_figure1.C:235
TGeant4Unit::rad
static constexpr double rad
Definition: TGeant4SystemOfUnits.h:148
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:876
kPointer
@ kPointer
Definition: GuiTypes.h:374
gX
Double_t gX
Definition: TPie.cxx:43
TObject::kCanDelete
@ kCanDelete
if object in a list can be deleted
Definition: TObject.h:58
gCurrent_y
Double_t gCurrent_y
Definition: TPie.cxx:56
gCurrent_slice
Int_t gCurrent_slice
Definition: TPie.cxx:50
TMath::Min
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
kHand
@ kHand
Definition: GuiTypes.h:373
TPie::GetSlice
TPieSlice * GetSlice(Int_t i)
Return the reference to the slice of index 'id'.
Definition: TPie.cxx:714
TMath::TwoPi
constexpr Double_t TwoPi()
Definition: TMath.h:50
kTopRight
@ kTopRight
Definition: GuiTypes.h:371
TPaveText::AddText
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
Definition: TPaveText.cxx:183
TPieSlice::SetRadiusOffset
void SetRadiusOffset(Double_t)
Set the radial offset of this slice.
Definition: TPieSlice.cxx:91
TString::Index
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:639
kArrowKeyPress
@ kArrowKeyPress
Definition: Buttons.h:27
TStyle::GetTitleH
Float_t GetTitleH() const
Definition: TStyle.h:274
TPie::GetEntryLineColor
Int_t GetEntryLineColor(Int_t)
Return the line color used to outline thi "i" slice.
Definition: TPie.cxx:664
TPie::SetEntryFillStyle
void SetEntryFillStyle(Int_t, Int_t)
Set the fill style for the "i" slice.
Definition: TPie.cxx:1262
TEllipse::PaintEllipse
virtual void PaintEllipse(Double_t x1, Double_t y1, Double_t r1, Double_t r2, Double_t phimin, Double_t phimax, Double_t theta, Option_t *option="")
Draw this ellipse with new coordinates.
Definition: TEllipse.cxx:528
TText
Definition: TText.h:22
kButton1Down
@ kButton1Down
Definition: Buttons.h:23
TPie::fLegend
TLegend * fLegend
!Legend for this piechart
Definition: TPie.h:30
TPie::fRadius
Double_t fRadius
Radius Pie radius.
Definition: TPie.h:35
Double_t
double Double_t
Definition: RtypesCore.h:59
TPie::SetAngularOffset
void SetAngularOffset(Double_t)
Set the global angular offset for slices in degree [0,360].
Definition: TPie.cxx:1193
TPie::fSum
Float_t fSum
!Sum for the slice values
Definition: TPie.h:28
TGeant4Unit::pi
static constexpr double pi
Definition: TGeant4SystemOfUnits.h:73
TLatex.h
TPie::SetEntryVal
void SetEntryVal(Int_t, Double_t)
Set the value of a slice.
Definition: TPie.cxx:1278
TPie::GetEntryLineStyle
Int_t GetEntryLineStyle(Int_t)
Return the style used to outline thi "i" slice.
Definition: TPie.cxx:672
TLatex::PaintLatex
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition: TLatex.cxx:2051
TPie::Paint
virtual void Paint(Option_t *)
Paint a Pie chart in a canvas.
Definition: TPie.cxx:804
TObject
Definition: TObject.h:37
TH1
Definition: TH1.h:57
TColor::GetColorDark
static Int_t GetColorDark(Int_t color)
Static function: Returns the dark color number corresponding to n If the TColor object does not exist...
Definition: TColor.cxx:1945
TPie::GetEntryFillStyle
Int_t GetEntryFillStyle(Int_t)
Return the style use to fill the slice number "i".
Definition: TPie.cxx:656
name
char name[80]
Definition: TGX11.cxx:110
gRadiusOffset
Double_t gRadiusOffset
Definition: TPie.cxx:46
TPie::GetEntryRadiusOffset
Double_t GetEntryRadiusOffset(Int_t)
Return the radial offset's value for the slice number "i".
Definition: TPie.cxx:688
TStyle::GetTitleFont
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition: TStyle.cxx:1166
TPie::fPercentFormat
TString fPercentFormat
Pfrom numeric format for the percent of a slice.
Definition: TPie.h:41
x2
static const double x2[5]
Definition: RooGaussKronrodIntegrator1D.cxx:364
gPad
#define gPad
Definition: TVirtualPad.h:287
TLegend::Draw
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:423
TPaveText
Definition: TPaveText.h:21
TPie::SetAngle3D
void SetAngle3D(Float_t val=30.)
Set the value of for the pseudo 3D view angle, in degree.
Definition: TPie.cxx:1180
TPie::GetEntryLabel
const char * GetEntryLabel(Int_t)
Returns the label of the entry number "i".
Definition: TPie.cxx:640
kMouseEnter
@ kMouseEnter
Definition: Buttons.h:29
TAttAxis::GetLabelFont
virtual Style_t GetLabelFont() const
Definition: TAttAxis.h:45
gAngularOffset
Double_t gAngularOffset
Definition: TPie.cxx:47
TLegend
Definition: TLegend.h:23
TPie::fY
Double_t fY
Y coordinate of the pie centre.
Definition: TPie.h:34
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
TStyle::GetTitleW
Float_t GetTitleW() const
Definition: TStyle.h:273
SetTextFont
pt SetTextFont(42)
TPave::SetName
virtual void SetName(const char *name="")
Definition: TPave.h:81
TPieSlice::SetIsActive
void SetIsActive(Bool_t is)
Definition: TPieSlice.h:37
TStyle::GetTitleX
Float_t GetTitleX() const
Definition: TStyle.h:271
Class
void Class()
Definition: Class.C:29
TString::ToLower
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
TPie::GetEntryVal
Double_t GetEntryVal(Int_t)
Return the value associated with the slice number "i".
Definition: TPie.cxx:696
kArrowKeyRelease
@ kArrowKeyRelease
Definition: Buttons.h:27
TPie::SetEntryRadiusOffset
void SetEntryRadiusOffset(Int_t, Double_t)
Set the distance, in the direction of the radius of the slice.
Definition: TPie.cxx:1270
TPie::SetHeight
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:1300
TH1.h
TPie::DistancetoSlice
Int_t DistancetoSlice(Int_t, Int_t)
Returns the slice number at the pixel position (px,py).
Definition: TPie.cxx:190
SetTextSize
th1 SetTextSize(0.12)
TPie::SetFractionFormat
void SetFractionFormat(const char *)
Set numeric format in the label, is used if the label format there is the modifier frac,...
Definition: TPie.cxx:1336
TPie::fLabelsOffset
Float_t fLabelsOffset
LabelsOffset offset of label.
Definition: TPie.h:37
TMath.h
TPie::GetAngularOffset
Double_t GetAngularOffset()
Definition: TPie.h:62
gROOT
#define gROOT
Definition: TROOT.h:406
int
TPie::~TPie
~TPie()
Destructor.
Definition: TPie.cxx:156
TPie::DistancetoPrimitive
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Evaluate the distance to the chart in gPad.
Definition: TPie.cxx:170