Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPie.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 "TPie.h"
14#include "TPieSlice.h"
15
16#include "TROOT.h"
17#include "TVirtualPad.h"
18#include "TCanvasImp.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#include <iostream>
30
31
32/** \class TPie
33\ingroup BasicGraphics
34
35Define a Pie Chart
36
37\anchor PIE00
38#### The possible drawing options are:
39
40| Option | Description |
41|--------|-------------------------------------------------------------------|
42| "R" | Print the labels along the central "R"adius of slices. |
43| "T" | Print the label in a direction "T"angent to circle that describes the TPie. |
44| "SC" | Paint the labels with the "S"ame "C"olor as the slices. |
45| "3D" | Draw the pie-chart with a pseudo 3D effect. |
46| "NOL" | No OutLine: Don't draw the slices' outlines, any property over the slices' line is ignored. |
47| ">" | Sort the slices in increasing order. |
48| "<" | Sort the slices in decreasing order. |
49
50After the use of > or < options the internal order of the TPieSlices is changed.
51
52\anchor PIE01
53#### Labels format
54The labels' format can be changed with TPie::SetLabelFormat().
55
56The format string must contain one of these modifiers:
57
58| Modifier | Description |
59|----------|-------------------------------------------------------------------|
60| "%txt" | to print the text label associated with the slice |
61| "%val" | to print the numeric value of the slice |
62| "%frac" | to print the relative fraction of this slice |
63| "%perc" | to print the % of this slice |
64
65Example:
66```
67mypie->SetLabelFormat("%txt (%frac)");
68```
69The numeric format in the label can be changed with TPie::SetFractionFormat.
70The numeric format the slices' values can be changed with TPie::SetValueFormat.
71The numeric format for the percent value of a slice can be changed with TPie::SetPercentFormat.
72
73If the colors are not specified (`nullptr`) they are automatically
74taken from the current color palette as shown in the following example.
75
76Begin_Macro(source)
77{
78 float vals[] = {10., 2., 5., 7.5};
79 const char* labels[]={"Label 1","Label 2","Label 3","Label4"};
80
81 auto C = new TCanvas("C","TPie test",500,500);
82 auto pie = new TPie("pie", "Pie Title", 4, vals, nullptr, labels);
83 pie->SetTextFont(42);
84 pie->SetTextSize(0.04);
85 pie->SetLabelFormat("#splitline{%txt}{%perc}");
86 pie->SetLabelsOffset(.02);
87 pie->SetRadius(.3);
88 pie->Draw("");
89}
90End_Macro
91
92More complex example:
93
94Begin_Macro(source)
95../../../tutorials/visualisation/graphics/piechart.C
96End_Macro
97
98*/
99
100////////////////////////////////////////////////////////////////////////////////
101/// Default constructor.
102
104{
105 Init(1, 0, 0.5, 0.5, 0.4);
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// This constructor creates a pie chart when only the number of
110/// the slices is known. The number of slices is fixed.
111
112TPie::TPie(const char *name, const char *title, Int_t npoints) :
113 TNamed(name,title)
114{
115 Init(npoints, 0, 0.5, 0.5, 0.4);
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Normal constructor. The 1st and 2nd parameters are the name of the object
120/// and its title.
121///
122/// The number of points passed at this point is used to allocate the memory.
123///
124/// Slices values are given as Double_t.
125///
126/// The 4th elements is an array containing, in double precision format,
127/// the value of each slice. It is also possible to specify the filled color
128/// of each slice. If the color array is not specified the slices are colored
129/// using a color sequence in the standard palette.
130
131TPie::TPie(const char *name, const char *title,
132 Int_t npoints, Double_t *vals,
133 Int_t *colors, const char *lbls[]) : TNamed(name,title)
134{
135 Init(npoints, 0, 0.5, 0.5, 0.4);
136 for (Int_t i=0; i<fNvals; ++i) fPieSlices[i]->SetValue(vals[i]);
137
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Normal constructor (Float_t).
144
145TPie::TPie(const char *name,
146 const char *title,
147 Int_t npoints, Float_t *vals,
148 Int_t *colors, const char *lbls[]) : TNamed(name,title)
149{
150 Init(npoints, 0, 0.5, 0.5, 0.4);
151 for (Int_t i=0; i<fNvals; ++i) fPieSlices[i]->SetValue(vals[i]);
152
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// Constructor from a TH1
159
160TPie::TPie(const TH1 *h) : TNamed(h->GetName(),h->GetTitle())
161{
162 Int_t i;
163
164 const TAxis *axis = h->GetXaxis();
165 Int_t first = axis->GetFirst();
166 Int_t last = axis->GetLast();
167 Int_t np = last-first+1;
168 Init(np, 0, 0.5, 0.5, 0.4);
169
170 for (i=first; i<=last; ++i) fPieSlices[i-first]->SetValue(h->GetBinContent(i));
171 if (axis->GetLabels()) {
172 for (i=first; i<=last; ++i) fPieSlices[i-first]->SetTitle(axis->GetBinLabel(i));
173 } else {
174 SetLabelFormat("%val");
175 }
176 SetTextSize(axis->GetLabelSize());
178 SetTextFont(axis->GetLabelFont());
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Copy constructor.
183
185{
186 Init(cpy.fNvals, cpy.fAngularOffset, cpy.fX, cpy.fY, cpy.fRadius);
187
188 for (Int_t i=0;i<fNvals;++i)
189 cpy.fPieSlices[i]->Copy(*fPieSlices[i]);
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Destructor.
194
196{
197 if (fNvals>0) {
198 for (int i=0; i<fNvals; ++i) delete fPieSlices[i];
199 delete [] fPieSlices;
200 }
201
202 if (fLegend) delete fLegend;
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Evaluate the distance to the chart in gPad.
207
209{
210 Int_t dist = 9999;
211 if (gPad) {
212 auto info = FindSlice(*gPad, px, py);
213 if ((info.num >= 0) && (info.rad <= fRadius))
214 dist = 0;
215 }
216
217 return dist;
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Find slice at given position
222
224{
225 SliceInfo_t res;
226 res.num = -1;
227
228 // coordinates
229 Double_t xx = parent.AbsPixeltoX(px);
230 Double_t yy = parent.AbsPixeltoY(py);
231
232 // XY metric
235 Double_t radXY = 1.;
236 if (fIs3D) {
237 radXY = TMath::Sin(fAngle3D / 180. * TMath::Pi());
238 radY = radXY * radX;
239 }
240
241 auto angles = GetSlicesAngles();
242
243 Float_t dPxl = (parent.PixeltoY(0) - parent.PixeltoY(1)) / radY;
244 for (Int_t i = 0; i < fNvals; ++i) {
245
246 // Angles' values for this slice
247 Double_t phimin = angles[2 * i];
248 Double_t cphi = angles[2 * i + 1];
249 Double_t phimax = angles[2 * i + 2];
250
252
253 Double_t dx = (xx - GetX() - radOffset * TMath::Cos(cphi)) / radX;
254 Double_t dy = (yy - GetY() - radOffset * TMath::Sin(cphi) * radXY) / radY;
255
256 if (TMath::Abs(dy) < dPxl)
257 dy = dPxl;
258
259 Double_t ang = TMath::ATan2(dy, dx);
260 if (ang < 0)
261 ang += TMath::TwoPi();
262
263 Double_t dist = TMath::Sqrt(dx * dx + dy * dy);
264
265 if (((ang >= phimin && ang <= phimax) || (ang + TMath::TwoPi() >= phimin && ang + TMath::TwoPi() <= phimax)) &&
266 dist <= 1.) {
267 res.num = i;
268 res.ang = ang;
269 res.cphi = cphi;
270 res.rad = dist;
271 break;
272 }
273 }
274 return res;
275}
276
277////////////////////////////////////////////////////////////////////////////////
278/// Returns the slice number at the pixel position (px,py).
279/// Returns -1 if no slice is picked.
280
282{
283 if (!gPad)
284 return -1;
285 auto res = FindSlice(*gPad, px, py);
286 return res.num;
287}
288
289
290////////////////////////////////////////////////////////////////////////////////
291/// Draw the pie chart.
292///
293/// The possible options are listed in the TPie::Paint() method.
294
296{
298 soption.ToLower();
299
300 if (soption.Length() == 0)
301 soption = "l";
302
303 if (!gPad || !gPad->IsEditable())
304 gROOT->MakeDefCanvas();
305
306 if (!soption.Contains("same")) {
307 gPad->Clear();
308 gPad->Range(0.,0.,1.,1.);
309 }
310
311 for (Int_t i = 0; i < fNvals; ++i)
312 fPieSlices[i]->AppendPad();
313 AppendPad(soption.Data());
314}
315
317 public:
318
320
321 Int_t oldpx = 0, oldpy = 0;
322
323 Double_t angularOffset0 = 0; // Reference angular offset
324
325 Int_t currentSlice = -1; // Current slice under mouse.
326 Double_t sliceAngle = 0.; // angle for moving slice
327 Double_t sliceOffset = 0; // offset for moving slice
328 Double_t angle0 = 0; // previous angle to mouse when rotating
329};
330
331
332////////////////////////////////////////////////////////////////////////////////
333/// This method is for internal use. It is used by Execute event to draw the
334/// outline of "this" TPie. Used when the opaque movements are not permitted.
335
337{
338 TAttLine(kBlack, 1, 2).ModifyOn(parent);
339
340 std::vector<Double_t> xx, yy;
341
342 // XY metric
343 Double_t radXY = !fIs3D ? 1. : TMath::Sin(fAngle3D/180.*TMath::Pi()), x0 = 0, y0 = 0;
344
345 auto addPoint = [&parent, &xx, &yy, &x0, &y0](double x1, double y1) {
346 xx.emplace_back(parent.XtoPad(x0 + x1));
347 yy.emplace_back(parent.YtoPad(y0 + y1));
348 };
349
350 auto angles = GetSlicesAngles();
351
352 for (Int_t loop3d = fIs3D ? 1 : 0; loop3d >= 0; loop3d--)
353 for (Int_t i = 0; i < fNvals; ++i) {
354 xx.clear();
355 yy.clear();
356 Float_t minphi = angles[i * 2];
357 Float_t avgphi = angles[i * 2 + 1];
358 Float_t maxphi = angles[i * 2 + 2];
359
361 x0 = fX + radOffset * TMath::Cos(avgphi);
362 y0 = fY + radOffset * TMath::Sin(avgphi) * radXY - loop3d * fHeight; // draw layer beyond
363
364 addPoint(0, 0);
365
367 Int_t ndiv = dphi > 1.5 ? (Int_t)(dphi / .15) : 10;
368 dphi /= ndiv;
369
370 // Loop to draw the arc
371 for (Int_t j = 0; j <= ndiv; ++j) {
372 Double_t phi = minphi + dphi * j;
373 addPoint(fRadius * TMath::Cos(phi), fRadius * TMath::Sin(phi) * radXY);
374 }
375
376 addPoint(0, 0);
377
378 if (loop3d)
379 addPoint(0, fHeight);
380
381 parent.PaintPolyLine(xx.size(), xx.data(), yy.data(),
382 TString::Format("ipiechart_slice%d_loop%d", i, loop3d).Data());
383
384 if (loop3d) {
385 xx.clear();
386 yy.clear();
389 parent.PaintPolyLine(xx.size(), xx.data(), yy.data(),
390 TString::Format("ipiechart_slice%d_bindmin", i).Data());
391 xx.clear();
392 yy.clear();
395 parent.PaintPolyLine(xx.size(), xx.data(), yy.data(),
396 TString::Format("ipiechart_slice%d_bindmax", i).Data());
397 }
398 }
399}
400
401////////////////////////////////////////////////////////////////////////////////
402/// Execute the mouse events.
403
405{
406 if (!gPad || !gPad->IsEditable()) return;
407
408 auto &parent = *gPad;
409
410 Bool_t opaque = parent.OpaqueMoving();
411
412 // Portion of pie considered as "border"
413 const Double_t dr = parent.PixeltoX(4) / GetRadius();
414 const Double_t minRad = parent.PixeltoX(10);
415
416 // Angular divisions in radial direction
417 const Double_t angstep1 = 0.5*TMath::PiOver4();
418 const Double_t angstep2 = 1.5*TMath::PiOver4();
419 const Double_t angstep3 = 2.5*TMath::PiOver4();
420 const Double_t angstep4 = 3.5*TMath::PiOver4();
421 const Double_t angstep5 = 4.5*TMath::PiOver4();
422 const Double_t angstep6 = 5.5*TMath::PiOver4();
423 const Double_t angstep7 = 6.5*TMath::PiOver4();
424 const Double_t angstep8 = 7.5*TMath::PiOver4();
425
426 // XY metric
428
429 auto inter = dynamic_cast<TPieInteractive *>(parent.Interactive(this));
430
431 auto calcAngle = [this, &parent,px,py]() {
432 Double_t xx = parent.AbsPixeltoX(px);
433 Double_t yy = parent.AbsPixeltoY(py);
434
435 Double_t dx1 = xx - GetX();
436 Double_t dy1 = yy - GetY();
437
438 return TMath::ATan2(dy1, dx1) / TMath::Pi() * 180.;
439 };
440
441 auto info = FindSlice(parent, px, py);
442 if (info.num < 0)
443 info.rad = 100; // far away to exclude any selection
444
445 switch(event) {
446 case kArrowKeyPress:
447 case kButton1Down:
448 inter = new TPieInteractive();
449 parent.Interactive(this, inter);
450
451 // Current center and radius.
452 inter->angularOffset0 = fAngularOffset;
453 // no break
454
455 case kMouseMotion: {
456 TPieInteractive dummy;
457 if (!inter) inter = &dummy; //
458
459 if ((info.rad >= 1 - dr) && (info.rad <= 1 + dr)) {
460 if (info.ang >= angstep8 || info.ang < angstep1)
461 parent.SetCursor(kRightSide);
462 else if (info.ang >= angstep1 && info.ang < angstep2)
463 parent.SetCursor(kTopRight);
464 else if (info.ang >= angstep2 && info.ang < angstep3)
465 parent.SetCursor(kTopSide);
466 else if (info.ang >= angstep3 && info.ang < angstep4)
467 parent.SetCursor(kTopLeft);
468 else if (info.ang >= angstep4 && info.ang <= angstep5)
469 parent.SetCursor(kLeftSide);
470 else if (info.ang >= angstep5 && info.ang < angstep6)
471 parent.SetCursor(kBottomLeft);
472 else if (info.ang >= angstep6 && info.ang < angstep7)
473 parent.SetCursor(kBottomSide);
474 else if (info.ang >= angstep7 && info.ang < angstep8)
475 parent.SetCursor(kBottomRight);
477 } else if ((info.rad > 0.6) && (info.rad < 1.)) {
478 if (info.num >= 0) {
479 parent.SetCursor(kPointer);
480 inter->currentSlice = info.num;
481 inter->sliceAngle = info.cphi;
482 inter->sliceOffset = fPieSlices[inter->currentSlice]->GetRadiusOffset();
484 } else
485 parent.Interactive(); // reject interactive
486 } else if ((info.rad >= 0.3) && (info.rad <= 0.6)) {
487 parent.SetCursor(kRotate);
489 inter->angle0 = calcAngle();
490 } else if (info.rad <= 0.3) {
491 parent.SetCursor(kHand);
493 }
494 inter->oldpx = px;
495 inter->oldpy = py;
496 break;
497 }
498
499 case kArrowKeyRelease:
500 case kButton1Motion: {
501 if (!inter)
502 break;
503
504 Int_t dx = px - inter->oldpx;
505 Int_t dy = py - inter->oldpy;
506
507 Double_t mdx = parent.PixeltoX(dx);
508 Double_t mdy = parent.PixeltoY(dy);
509
510 if (inter->fMode == TPieInteractive::pMovingPie) {
511 parent.SetCursor(kMove);
512 fX += mdx;
513 fY += mdy;
514 } else if (inter->fMode == TPieInteractive::pMovingSlice) {
515 parent.SetCursor(kMove);
516 inter->sliceOffset += TMath::Cos(inter->sliceAngle)*mdx + TMath::Sin(inter->sliceAngle)*mdy/radXY;
517 fPieSlices[inter->currentSlice]->SetRadiusOffset(TMath::Max(0., inter->sliceOffset));
518 } else if (inter->fMode == TPieInteractive::pResizing) {
521 } else if (inter->fMode == TPieInteractive::pRotating) {
524 inter->angle0 = angle1;
525 }
526
527 if (!opaque)
528 DrawGhost(parent);
529 else
530 parent.Modified();
531
532 parent.UpdateAsync();
533
534 inter->oldpx = px;
535 inter->oldpy = py;
536
537 break;
538 }
539
540 case kButton1Up:
541 if (gROOT->IsEscaped()) {
542 gROOT->SetEscape(kFALSE);
543 fAngularOffset = inter->angularOffset0;
544 parent.Modified();
545 } else if (!opaque) {
546 parent.Modified();
547 }
548
549 parent.Interactive(); // remove interactive object
550 parent.UpdateAsync();
551
552 break;
553
554 case kButton1Locate:
555
556 ExecuteEvent(kButton1Down, px, py);
557
558 while (true) {
559 px = py = 0;
560 event = parent.GetCanvasImp()->RequestLocator(px, py);
561
563
564 if (event != -1) { // button is released
565 ExecuteEvent(kButton1Up, px, py);
566 return;
567 }
568 }
569 break;
570
571 case kMouseEnter:
572 break;
573
574 default:
575 // unknown event
576 break;
577 }
578}
579
580////////////////////////////////////////////////////////////////////////////////
581/// Returns the label of the entry number "i".
582
583const char* TPie::GetEntryLabel(Int_t i) const
584{
585 return GetSlice(i)->GetTitle();
586}
587
588////////////////////////////////////////////////////////////////////////////////
589/// Return the color of the slice number "i".
590
592{
593 return GetSlice(i)->GetFillColor();
594}
595
596////////////////////////////////////////////////////////////////////////////////
597/// Return the style use to fill the slice number "i".
598
600{
601 return GetSlice(i)->GetFillStyle();
602}
603
604////////////////////////////////////////////////////////////////////////////////
605/// Return the line color used to outline thi "i" slice
606
608{
609 return GetSlice(i)->GetLineColor();
610}
611
612////////////////////////////////////////////////////////////////////////////////
613/// Return the style used to outline thi "i" slice
614
616{
617 return GetSlice(i)->GetLineStyle();
618}
619
620////////////////////////////////////////////////////////////////////////////////
621/// Return the line width used to outline thi "i" slice
622
624{
625 return GetSlice(i)->GetLineWidth();
626}
627
628////////////////////////////////////////////////////////////////////////////////
629/// Return the radial offset's value for the slice number "i".
630
635
636////////////////////////////////////////////////////////////////////////////////
637/// Return the value associated with the slice number "i".
638
640{
641 return GetSlice(i)->GetValue();
642}
643
644////////////////////////////////////////////////////////////////////////////////
645/// Return sum of all entries.
646/// Absolute value for each entry will be used
647
649{
650 Double_t sum = 0;
651 for (Int_t i = 0; i < fNvals; ++i)
652 sum += TMath::Abs(fPieSlices[i]->GetValue());
653 return sum;
654}
655
656
657////////////////////////////////////////////////////////////////////////////////
658/// If created before by Paint option or by MakeLegend method return
659/// the pointer to the legend, otherwise return 0;
660
662{
663 return fLegend;
664}
665
666////////////////////////////////////////////////////////////////////////////////
667/// Return the reference to the slice of index 'id'.
668
670{
671 return (id >= 0) && (id < fNvals) ? fPieSlices[id] : nullptr;
672}
673
674////////////////////////////////////////////////////////////////////////////////
675/// Common initialization for all constructors.
676/// This is a private function called to allocate the memory.
677
679{
681 fX = x;
682 fY = y;
683 fRadius = r;
684 fNvals = np;
685 fLegend = nullptr;
686 fHeight = 0.08;
687 fAngle3D = 30;
688 fIs3D = kFALSE;
689
691
693
695
696 for (Int_t i=0;i<fNvals;++i) {
697 TString tmplbl = "Slice";
698 tmplbl += i;
699 fPieSlices[i] = new TPieSlice(tmplbl.Data(), tmplbl.Data(), this);
700 fPieSlices[i]->SetRadiusOffset(0.);
706 fPieSlices[i]->SetFillStyle(1001);
707 }
708
709 fLabelFormat = "%txt";
710 fFractionFormat = "%3.2f";
711 fValueFormat = "%4.2f";
712 fPercentFormat = "%3.1f";
713}
714
715////////////////////////////////////////////////////////////////////////////////
716/// This method create a legend that explains the contents
717/// of the slice for this pie-chart.
718///
719/// The parameter passed reppresents the option passed to shown the slices,
720/// see TLegend::AddEntry() for further details.
721///
722/// The pointer of the TLegend is returned.
723
725{
726 if (!fLegend) fLegend = new TLegend(x1,y1,x2,y2,leg_header);
727 else fLegend->Clear();
728
729 for (Int_t i=0;i<fNvals;++i) {
731 }
732
733 if (gPad) fLegend->Draw();
734
735 return fLegend;
736}
737
738////////////////////////////////////////////////////////////////////////////////
739/// Paint a Pie chart in a canvas.
740/// [See the class description for the possible drawing options](\ref PIE00)
741
743{
745
747
748 // if true the lines around the slices are drawn, if false not
750
751 // if true the labels' colors are the same as the slices' colors
753
754 // For the label orientation there are 3 possibilities:
755 // 0: horizontal
756 // 1: radial
757 // 2: tangent
758 Int_t lblor = 0;
759
760 // Parse the options
761 Int_t idx;
762 // Paint the TPie in an existing canvas
763 if ( (idx=soption.Index("same"))>=0 ) {
765 soption.Remove(idx,4);
766 }
767
768 if ( (idx=soption.Index("nol"))>=0 ) {
770 soption.Remove(idx,3);
771 }
772
773 if ( (idx=soption.Index("sc"))>=0 ) {
775 soption.Remove(idx,2);
776 }
777
778 // check if is active the pseudo-3d
779 if ( (idx=soption.Index("3d"))>=0 ) {
780 fIs3D = kTRUE;
781 soption.Remove(idx,2);
782 } else {
783 fIs3D = kFALSE;
784 }
785
786 // seek if have to draw the labels around the pie chart
787 if ( (idx=soption.Index("t"))>=0 ) {
788 lblor = 2;
789 soption.Remove(idx,1);
790 }
791
792 // Seek if have to paint the labels along the radii
793 if ( (idx=soption.Index("r"))>=0 ) {
794 lblor = 1;
795 soption.Remove(idx,1);
796 }
797
798 // Seeks if has to paint sort the slices in increasing mode
799 if ( (idx=soption.Index(">"))>=0 ) {
801 soption.Remove(idx,1);
802 }
803
804 // Seeks if has to paint sort the slices in decreasing mode
805 if ( (idx=soption.Index("<"))>=0 ) {
807 soption.Remove(idx,1);
808 }
809
810 if (fNvals<=0) {
811 Warning("Paint","No vals");
812 return;
813 }
814
815 if (!fPieSlices) {
816 Warning("Paint","No valid arrays of values");
817 return;
818 }
819
820 // Check if gPad exists and define the drawing range.
821 if (!gPad) return;
822
823 // Objects useful to draw labels and slices
825 TArc arc;
826 TLine line;
827
828 // XY metric
831 Double_t radXY = 1.;
832
833 if (fIs3D) {
836 }
837
838 auto angles = GetSlicesAngles();
839
840 // Draw the slices.
841 Int_t pixelHeight = gPad->YtoPixel(0)-gPad->YtoPixel(fHeight);
842 for (Int_t pi = 0; pi < pixelHeight && fIs3D; ++pi) { // loop for pseudo-3d effect
843 for (Int_t i=0;i<fNvals;++i) {
844 // draw the arc
845 // set the color of the next slice
846 if (pi>0) {
847 arc.SetFillStyle(0);
848 arc.SetLineColor(TColor::GetColorDark((fPieSlices[i]->GetFillColor())));
849 } else {
850 arc.SetFillStyle(0);
851 if (optionLine) {
852 arc.SetLineColor(fPieSlices[i]->GetLineColor());
853 arc.SetLineStyle(fPieSlices[i]->GetLineStyle());
854 arc.SetLineWidth(fPieSlices[i]->GetLineWidth());
855 } else {
856 arc.SetLineWidth(1);
857 arc.SetLineColor(TColor::GetColorDark((fPieSlices[i]->GetFillColor())));
858 }
859 }
860 // Paint the slice
861 Float_t aphi = angles[2*i+1];
862
865
866 arc.PaintEllipse(ax, ay, radX, radY, angles[2 * i] / TMath::Pi() * 180, angles[2 * i + 2]/ TMath::Pi() * 180, 0.);
867
868 if (optionLine) {
869 line.SetLineColor(fPieSlices[i]->GetLineColor());
870 line.SetLineStyle(fPieSlices[i]->GetLineStyle());
871 line.SetLineWidth(fPieSlices[i]->GetLineWidth());
873
874 Double_t x0, y0;
875 x0 = ax+radX*TMath::Cos(angles[2*i]);
876 y0 = ay+radY*TMath::Sin(angles[2*i]);
877 line.PaintLine(x0,y0,x0,y0);
878
879 x0 = ax+radX*TMath::Cos(angles[2*i+2]);
880 y0 = ay+radY*TMath::Sin(angles[2*i+2]);
881 line.PaintLine(x0,y0,x0,y0);
882 }
883 }
884 } // end loop for pseudo-3d effect
885
886 for (Int_t i=0;i<fNvals;++i) { // loop for the piechart
887 // Set the color of the next slice
888 arc.SetFillColor(fPieSlices[i]->GetFillColor());
889 arc.SetFillStyle(fPieSlices[i]->GetFillStyle());
890 if (optionLine) {
891 arc.SetLineColor(fPieSlices[i]->GetLineColor());
892 arc.SetLineStyle(fPieSlices[i]->GetLineStyle());
893 arc.SetLineWidth(fPieSlices[i]->GetLineWidth());
894 } else {
895 arc.SetLineWidth(1);
896 arc.SetLineColor(fPieSlices[i]->GetFillColor());
897 }
898
899 // Paint the slice
900 Float_t aphi = angles[2*i+1];
901
904 arc.PaintEllipse(ax, ay, radX, radY, angles[2*i] / TMath::Pi() * 180, angles[2*i+2] / TMath::Pi() * 180, 0.);
905
906 } // end loop to draw the slices
907
908
909 // Set the font
910 textlabel.SetTextFont(GetTextFont());
911 textlabel.SetTextSize(GetTextSize());
912 textlabel.SetTextColor(GetTextColor());
913
915 if (sum <= 0) sum = 1.; // just to avoid zero division
916
917 // Loop to place the labels.
918 for (Int_t i=0;i<fNvals;++i) {
919 Float_t aphi = angles[2*i+1];
920
922
923 // Paint the text in the pad
925
926 tmptxt.ReplaceAll("%txt",fPieSlices[i]->GetTitle());
927 tmptxt.ReplaceAll("%val",TString::Format(fValueFormat.Data(),fPieSlices[i]->GetValue()));
928 tmptxt.ReplaceAll("%frac",TString::Format(fFractionFormat.Data(),fPieSlices[i]->GetValue()/sum));
929 tmptxt.ReplaceAll("%perc",TString::Format(TString::Format("%s %s",fPercentFormat.Data(),"%s").Data(),(fPieSlices[i]->GetValue()/sum)*100,"%"));
930
931 textlabel.SetTitle(tmptxt.Data());
932 Double_t h = textlabel.GetYsize();
933 Double_t w = textlabel.GetXsize();
934
937
938 Double_t lblang = 0;
939
940 if (lblor==1) { // radial direction for the label
942 lblang += aphi;
943 if (lblang<=0) lblang += TMath::TwoPi();
945
946 lx += h/2.*TMath::Sin(lblang);
947 ly -= h/2.*TMath::Cos(lblang);
948
949 // This control prevent text up-side
953 lblang -= TMath::Pi();
954 }
955 } else if (lblor==2) { // tangential direction of the labels
958 lblang += aphi;//-TMath::PiOver2();
959 if (lblang<0) lblang+=TMath::TwoPi();
960
961 lx -= w/2.*TMath::Cos(lblang);
962 ly -= w/2.*TMath::Sin(lblang);
963
967 lblang -= TMath::Pi();
968 }
969 } else { // horizontal labels (default direction)
971 if (aphi>TMath::PiOver2() || aphi<=-TMath::PiOver2()) lx -= w;
972 if (aphi<0) ly -= h;
973 }
974
977 ly -= fHeight;
978
979 if (optionSameColor) textlabel.SetTextColor((fPieSlices[i]->GetFillColor()));
980 textlabel.PaintLatex(lx,ly,
982 GetTextSize(), tmptxt.Data());
983 }
984
985 if (optionSame) return;
986
987 // Draw title
988 TPaveText *title = nullptr;
989 if (auto obj = gPad->GetListOfPrimitives()->FindObject("title")) {
990 title = dynamic_cast<TPaveText*>(obj);
991 }
992
993 // Check the OptTitle option
994 if (strlen(GetTitle()) == 0 || gStyle->GetOptTitle() <= 0) {
995 if (title) delete title;
996 return;
997 }
998
999 // Height and width of the title
1002 if (ht<=0) ht = 1.1*gStyle->GetTitleFontSize();
1003 if (ht<=0) ht = 0.05; // minum height
1004 if (wt<=0) { // eval the width of the title
1005 TLatex l;
1006 l.SetTextSize(ht);
1007 l.SetTitle(GetTitle());
1008 // adjustment in case the title has several lines (#splitline)
1009 ht = TMath::Max(ht, 1.2*l.GetYsize()/(gPad->GetY2() - gPad->GetY1()));
1010 Double_t wndc = l.GetXsize()/(gPad->GetX2() - gPad->GetX1());
1011 wt = TMath::Min(0.7, 0.02+wndc);
1012 }
1013
1014 if (title) {
1015 TText *t0 = (TText*)title->GetLine(0);
1016 if (t0) {
1017 if (!strcmp(t0->GetTitle(),GetTitle())) return;
1018 t0->SetTitle(GetTitle());
1019 if (wt > 0) title->SetX2NDC(title->GetX1NDC()+wt);
1020 }
1021 return;
1022 }
1023
1025 if (talh < 1) talh = 1; else if (talh > 3) talh = 3;
1027 if (talv < 1) talv = 1; else if (talv > 3) talv = 3;
1029 xpos = gStyle->GetTitleX();
1030 ypos = gStyle->GetTitleY();
1031 if (talh == 2) xpos = xpos-wt/2.;
1032 if (talh == 3) xpos = xpos-wt;
1033 if (talv == 2) ypos = ypos+ht/2.;
1034 if (talv == 1) ypos = ypos+ht;
1035
1036 title = new TPaveText(xpos,ypos-ht,xpos+wt,ypos,"blNDC");
1039 title->SetName("title");
1040
1043 title->SetTextFont(gStyle->GetTitleFont(""));
1044 if (gStyle->GetTitleFont("")%10 > 2)
1046 title->AddText(GetTitle());
1047
1048 title->SetBit(kCanDelete);
1049
1050 title->Draw();
1051 title->Paint();
1052}
1053
1054////////////////////////////////////////////////////////////////////////////////
1055/// Save primitive as a C++ statement(s) on output stream out
1056
1057void TPie::SavePrimitive(std::ostream &out, Option_t *option)
1058{
1059 SavePrimitiveConstructor(out, Class(), "pie", TString::Format("\"%s\", \"%s\", %d", GetName(), TString(GetTitle()).ReplaceSpecialCppChars().Data(), fNvals));
1060
1061 out << " pie->SetCircle(" << fX << ", " << fY << ", " << fRadius << ");\n";
1062 out << " pie->SetValueFormat(\"" << GetValueFormat() << "\");\n";
1063 out << " pie->SetLabelFormat(\"" << GetLabelFormat() << "\");\n";
1064 out << " pie->SetPercentFormat(\"" << GetPercentFormat() << "\");\n";
1065 out << " pie->SetLabelsOffset(" << GetLabelsOffset() << ");\n";
1066 out << " pie->SetAngularOffset(" << GetAngularOffset() << ");\n";
1067
1068 SaveTextAttributes(out, "pie", 11, 0, 1, 62, 0.05);
1069
1070 // Save the values for the slices
1071 for (Int_t i = 0; i < fNvals; ++i) {
1072 auto slice_name = TString::Format("pie->GetSlice(%d)", i);
1073 fPieSlices[i]->SavePrimitive(out, slice_name.Data());
1074 }
1075
1076 out << " gPad->Add(pie, \"" << TString(option).ReplaceSpecialCppChars() << "\");\n";
1077}
1078
1079////////////////////////////////////////////////////////////////////////////////
1080/// Set the value of for the pseudo 3D view angle, in degree.
1081/// The range of the permitted values is: [0,90]
1082
1084 // check if val is in the permitted range
1085 while (val>360.) val -= 360.;
1086 while (val<0) val += 360.;
1087 if (val>=90 && val<180) val = 180-val;
1088 else if (val>=180 && val<=360) val = 360-val;
1089
1090 fAngle3D = val;
1091}
1092
1093////////////////////////////////////////////////////////////////////////////////
1094/// Set the global angular offset for slices in degree [0,360]
1095
1097{
1099
1100 while (fAngularOffset >= 360.)
1101 fAngularOffset -= 360.;
1102 while (fAngularOffset < 0.)
1103 fAngularOffset += 360.;
1104}
1105
1106////////////////////////////////////////////////////////////////////////////////
1107/// Set the coordinates of the circle that describe the pie:
1108/// - the 1st and the 2nd arguments are the x and y center's coordinates.
1109/// - the 3rd value is the pie-chart's radius.
1110///
1111/// All the coordinates are in NDC space.
1112
1114{
1115 fX = x;
1116 fY = y;
1117 fRadius = rad;
1118}
1119
1120////////////////////////////////////////////////////////////////////////////////
1121/// Set slice number "i" label. The first parameter is the index of the slice,
1122/// the other is the label text.
1123
1124void TPie::SetEntryLabel(Int_t i, const char *text)
1125{
1126 // Set the Label of a single slice
1127 if (i>=0 && i<fNvals) fPieSlices[i]->SetTitle(text);
1128}
1129
1130////////////////////////////////////////////////////////////////////////////////
1131/// Set the color for the slice's outline. "i" is the slice number.
1132
1134{
1135 if (i>=0 && i<fNvals) fPieSlices[i]->SetLineColor(color);
1136}
1137
1138////////////////////////////////////////////////////////////////////////////////
1139/// Set the style for the slice's outline. "i" is the slice number.
1140
1142{
1143 if (i>=0 && i<fNvals) fPieSlices[i]->SetLineStyle(style);
1144}
1145
1146////////////////////////////////////////////////////////////////////////////////
1147/// Set the width of the slice's outline. "i" is the slice number.
1148
1150{
1151 if (i>=0 && i<fNvals) fPieSlices[i]->SetLineWidth(width);
1152}
1153
1154////////////////////////////////////////////////////////////////////////////////
1155/// Set the color for the slice "i".
1156
1158{
1159 if (i>=0 && i<fNvals) fPieSlices[i]->SetFillColor(color);
1160}
1161
1162////////////////////////////////////////////////////////////////////////////////
1163/// Set the fill style for the "i" slice
1164
1166{
1167 if (i>=0 && i<fNvals) fPieSlices[i]->SetFillStyle(style);
1168}
1169
1170////////////////////////////////////////////////////////////////////////////////
1171/// Set the distance, in the direction of the radius of the slice.
1172
1174{
1175 if (i>=0 && i<fNvals) fPieSlices[i]->SetRadiusOffset(shift);
1176}
1177
1178////////////////////////////////////////////////////////////////////////////////
1179/// Set the value of a slice
1180
1182{
1183 if (i>=0 && i<fNvals) fPieSlices[i]->SetValue(val);
1184}
1185
1186////////////////////////////////////////////////////////////////////////////////
1187/// Set the fill colors for all the TPie's slices.
1188
1190{
1191 if (!colors) return;
1192 for (Int_t i=0;i<fNvals;++i) fPieSlices[i]->SetFillColor(colors[i]);
1193}
1194
1195////////////////////////////////////////////////////////////////////////////////
1196/// Set the height, in pixel, for the piechart if is drawn using
1197/// the pseudo-3d mode.
1198///
1199/// The default value is 20 pixel.
1200
1202{
1203 fHeight = val;
1204}
1205
1206////////////////////////////////////////////////////////////////////////////////
1207/// This method is used to customize the label format.
1208/// [See the class description for the possible labels format](\ref PIE01)
1209
1210void TPie::SetLabelFormat(const char *fmt)
1211{
1212 fLabelFormat = fmt;
1213}
1214
1215////////////////////////////////////////////////////////////////////////////////
1216/// Set numeric format in the label, is used if the label format
1217/// there is the modifier %frac, in this case the value is printed
1218/// using this format.
1219///
1220/// The numeric format use the standard C modifier used in stdio library:
1221/// %f, %2.1$, %e... for further documentation you can use the printf
1222/// man page ("man 3 printf" on linux)
1223///
1224/// Example:
1225/// ~~~ {.cpp}
1226/// mypie->SetLabelFormat("%txt (%frac)");
1227/// mypie->SetFractionFormat("2.1f");
1228/// ~~~
1229
1231{
1233}
1234
1235////////////////////////////////////////////////////////////////////////////////
1236/// Set the labels for all the slices.
1237
1238void TPie::SetLabels(const char *lbls[])
1239{
1240 if (!lbls) return;
1241 for (Int_t i=0;i<fNvals;++i) fPieSlices[i]->SetTitle(lbls[i]);
1242}
1243
1244////////////////////////////////////////////////////////////////////////////////
1245/// Set the distance between the label end the external line of the TPie.
1246
1251
1252////////////////////////////////////////////////////////////////////////////////
1253/// Set the numeric format for the percent value of a slice, default: %3.1f
1254
1256{
1258}
1259
1260////////////////////////////////////////////////////////////////////////////////
1261/// Set the pie chart's radius' value.
1262
1264{
1265 if (rad>0) {
1266 fRadius = rad;
1267 } else {
1268 Warning("SetRadius",
1269 "It's not possible set the radius to a negative value");
1270 }
1271}
1272
1273////////////////////////////////////////////////////////////////////////////////
1274/// Set the numeric format the slices' values.
1275/// Used by %val (see SetLabelFormat()).
1276
1277void TPie::SetValueFormat(const char *fmt)
1278{
1279 fValueFormat = fmt;
1280}
1281
1282////////////////////////////////////////////////////////////////////////////////
1283/// Set X value.
1284
1286{
1287 fX = x;
1288}
1289
1290////////////////////////////////////////////////////////////////////////////////
1291/// Set Y value.
1292
1294{
1295 fY = y;
1296}
1297
1298////////////////////////////////////////////////////////////////////////////////
1299/// Return calculated angle for all slices
1300/// Only for internal use
1301
1302std::vector<Float_t> TPie::GetSlicesAngles() const
1303{
1304 std::vector<Float_t> angles(2 * fNvals + 1, 0.);
1305
1307
1308 if (sum > 0)
1309 sum = 360. / sum;
1310 else
1311 sum = 1.;
1312
1313 angles[0] = GetAngularOffset();
1314 for (Int_t i = 0; i < fNvals; ++i) {
1315 Float_t dphi = TMath::Abs(fPieSlices[i]->GetValue()) * sum;
1316 angles[2 * i + 1] = angles[2 * i] + dphi / 2.;
1317 angles[2 * i + 2] = angles[2 * i] + dphi;
1318 }
1319
1320 // convert in radians
1321 for (auto &v : angles)
1322 v *= TMath::Pi() / 180.;
1323
1324 return angles;
1325}
1326
1327
1328////////////////////////////////////////////////////////////////////////////////
1329/// Make the slices.
1330/// Deprecated, no longer necessary
1331
1333{
1334 }
1335
1336////////////////////////////////////////////////////////////////////////////////
1337/// This method, mainly intended for internal use, ordered the slices according their values.
1338/// The default (amode=kTRUE) is increasing order, but is also possible in decreasing order (amode=kFALSE).
1339///
1340/// If the merge_threshold>0 the slice that contains a quantity smaller than merge_threshold are merged
1341/// together
1342
1344{
1345
1346 // main loop to order, bubble sort, the array
1348
1349 while (isDone==kFALSE) {
1350 isDone = kTRUE;
1351
1352 for (Int_t i=0;i<fNvals-1;++i) { // loop over the values
1353 if ( (amode && (fPieSlices[i]->GetValue()>fPieSlices[i+1]->GetValue())) ||
1354 (!amode && (fPieSlices[i]->GetValue()<fPieSlices[i+1]->GetValue()))
1355 )
1356 {
1357 // exchange the order
1359 fPieSlices[i] = fPieSlices[i+1];
1360 fPieSlices[i+1] = tmpcpy;
1361
1362 isDone = kFALSE;
1363 }
1364 } // end loop the values
1365 } // end main ordering loop
1366
1367 if (merge_threshold>0) {
1368 // merge smallest slices
1369 TPieSlice *merged_slice = new TPieSlice("merged","other",this);
1370 merged_slice->SetRadiusOffset(0.);
1371 merged_slice->SetLineColor(1);
1372 merged_slice->SetLineStyle(1);
1373 merged_slice->SetLineWidth(1);
1374 merged_slice->SetFillColor(gStyle->GetColorPalette( (amode ? 0 : fNvals-1) ));
1375 merged_slice->SetFillStyle(1001);
1376
1377 if (amode) {
1378 // search slices under the threshold
1379 Int_t iMerged = 0;
1381 merged_slice->SetValue( merged_slice->GetValue()+fPieSlices[iMerged]->GetValue() );
1382 }
1383
1384 // evaluate number of valid slices
1385 if (iMerged<=1) { // no slices to merge
1386 delete merged_slice;
1387 }
1388 else { // write a new array with the right dimension
1390 fNvals = fNvals-iMerged+1;
1393 for (Int_t i=0;i<old_fNvals;++i) {
1394 if (i<iMerged) delete fPieSlices[i];
1395 else new_array[i-iMerged+1] = fPieSlices[i];
1396 }
1397 delete [] fPieSlices;
1399 }
1400 }
1401 else {
1402 Int_t iMerged = fNvals-1;
1404 merged_slice->SetValue( merged_slice->GetValue()+fPieSlices[iMerged]->GetValue() );
1405 }
1406
1407 // evaluate number of valid slices
1409 if (nMerged<=1) { // no slices to merge
1410 delete merged_slice;
1411 }
1412 else { // write a new array with the right dimension
1414 fNvals = fNvals-nMerged+1;
1417 for (Int_t i=old_fNvals-1;i>=0;--i) {
1418 if (i>iMerged) delete fPieSlices[i];
1419 else new_array[i-nMerged-1] = fPieSlices[i];
1420 }
1421 delete [] fPieSlices;
1423 }
1424
1425 }
1426 }
1427}
1428
@ kMouseMotion
Definition Buttons.h:23
@ kArrowKeyRelease
Definition Buttons.h:21
@ kButton1Motion
Definition Buttons.h:20
@ kButton1Up
Definition Buttons.h:19
@ kArrowKeyPress
Definition Buttons.h:21
@ kButton1Down
Definition Buttons.h:17
@ kButton1Locate
Definition Buttons.h:22
@ kMouseEnter
Definition Buttons.h:23
@ kRightSide
Definition GuiTypes.h:374
@ kBottomSide
Definition GuiTypes.h:374
@ kTopLeft
Definition GuiTypes.h:373
@ kBottomRight
Definition GuiTypes.h:373
@ kTopSide
Definition GuiTypes.h:374
@ kLeftSide
Definition GuiTypes.h:374
@ kMove
Definition GuiTypes.h:375
@ kTopRight
Definition GuiTypes.h:373
@ kBottomLeft
Definition GuiTypes.h:373
@ kHand
Definition GuiTypes.h:375
@ kRotate
Definition GuiTypes.h:375
@ kPointer
Definition GuiTypes.h:376
#define h(i)
Definition RSha256.hxx:106
cudaEvent_t event
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
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
@ kBlack
Definition Rtypes.h:65
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t option
Option_t Option_t SetTextSize
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 winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
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 SetTextFont
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void xpos
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t SetFillColor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void ypos
Option_t Option_t width
Option_t Option_t style
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition TGX11.cxx:142
#define gROOT
Definition TROOT.h:417
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
Create an Arc.
Definition TArc.h:26
virtual Color_t GetLabelColor() const
Definition TAttAxis.h:39
virtual Style_t GetLabelFont() const
Definition TAttAxis.h:40
virtual Float_t GetLabelSize() const
Definition TAttAxis.h:42
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:32
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:33
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:42
Line Attributes class.
Definition TAttLine.h:21
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:46
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void ModifyOn(TVirtualPad &pad)
Change current line attributes on specified pad.
Definition TAttLine.cxx:255
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:37
Text Attributes class.
Definition TAttText.h:21
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:39
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:38
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:37
virtual Float_t GetTextAngle() const
Return the text angle.
Definition TAttText.h:36
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:50
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:52
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
Save text attributes as C++ statement(s) on output stream out.
Definition TAttText.cxx:399
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:53
Class to manage histogram axis.
Definition TAxis.h:32
const char * GetBinLabel(Int_t bin) const
Return label for bin.
Definition TAxis.cxx:444
Int_t GetLast() const
Return last bin on the axis i.e.
Definition TAxis.cxx:473
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition TAxis.cxx:462
THashList * GetLabels() const
Definition TAxis.h:123
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:2151
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
To draw Mathematical Formula.
Definition TLatex.h:20
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition TLegend.cxx:319
void Draw(Option_t *option="") override
Draw this legend with its current attributes.
Definition TLegend.cxx:424
void Clear(Option_t *option="") override
Clear all entries in this legend, including the header.
Definition TLegend.cxx:378
Use the TLine constructor to create a simple line.
Definition TLine.h:22
virtual void PaintLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this line with new coordinates.
Definition TLine.cxx:261
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1082
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:203
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:886
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
Definition TObject.cxx:776
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
void Draw(Option_t *option="") override
Draw this pavetext with its current attributes.
void Paint(Option_t *option="") override
Paint this pavetext with its current attributes.
virtual TText * GetLine(Int_t number) const
Get Pointer to line number in this pavetext.
virtual void SetName(const char *name="")
Definition TPave.h:81
virtual void SetBorderSize(Int_t bordersize=4)
Sets the border size of the TPave box and shadow.
Definition TPave.h:79
Double_t GetX1NDC() const
Definition TPave.h:61
virtual void SetX2NDC(Double_t x2)
Definition TPave.h:85
Double_t angle0
Definition TPie.cxx:328
Int_t currentSlice
Definition TPie.cxx:325
enum TPieInteractive::EMode fMode
Double_t sliceOffset
Definition TPie.cxx:327
Double_t angularOffset0
Definition TPie.cxx:323
Double_t sliceAngle
Definition TPie.cxx:326
A slice of a piechart, see the TPie class.
Definition TPieSlice.h:18
void SetValue(Double_t)
Set the value for this slice.
Double_t GetRadiusOffset() const
return the value of the offset in radial direction for this slice.
Definition TPieSlice.cxx:82
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
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
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
static TClass * Class()
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
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
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 Draw(Option_t *option="l") override
Draw the pie chart.
Definition TPie.cxx:295
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
friend class TPieSlice
Definition TPie.h:29
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
Basic string class.
Definition TString.h:137
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1122
const char * Data() const
Definition TString.h:385
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2460
Float_t GetTitleX() const
Definition TStyle.h:282
Int_t GetOptTitle() const
Definition TStyle.h:248
Float_t GetTitleY() const
Definition TStyle.h:283
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition TStyle.cxx:1217
Color_t GetTitleFillColor() const
Definition TStyle.h:273
Style_t GetTitleStyle() const
Definition TStyle.h:275
Float_t GetLabelOffset(Option_t *axis="X") const
Return label offset.
Definition TStyle.cxx:1134
Width_t GetTitleBorderSize() const
Definition TStyle.h:277
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
Definition TStyle.cxx:1102
Color_t GetTitleTextColor() const
Definition TStyle.h:274
Float_t GetTitleH() const
Definition TStyle.h:285
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
Definition TStyle.cxx:1176
Float_t GetTitleFontSize() const
Definition TStyle.h:276
Int_t GetTitleAlign() const
Definition TStyle.h:272
Float_t GetTitleW() const
Definition TStyle.h:284
Base class for several text objects.
Definition TText.h:22
Helper class to store interactive parameters for individual objects Should be used via gPad->Interact...
Definition TVirtualPad.h:75
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual Double_t PixeltoY(Double_t py)=0
virtual Double_t AbsPixeltoX(Double_t px)=0
virtual Double_t YtoPad(Double_t y) const =0
virtual void PaintPolyLine(Int_t n, Float_t *x, Float_t *y, Option_t *option="")=0
virtual Double_t XtoPad(Double_t x) const =0
virtual Double_t AbsPixeltoY(Double_t py)=0
TLine * line
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
constexpr Double_t PiOver2()
Definition TMath.h:54
Double_t ATan2(Double_t y, Double_t x)
Returns the principal value of the arc tangent of y/x, expressed in radians.
Definition TMath.h:659
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:675
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
constexpr Double_t PiOver4()
Definition TMath.h:61
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:607
constexpr Double_t Pi()
Definition TMath.h:40
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:601
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122
constexpr Double_t TwoPi()
Definition TMath.h:47
Double_t rad
Definition TPie.h:38
Double_t cphi
Definition TPie.h:37
Double_t ang
Definition TPie.h:36
TLine l
Definition textangle.C:4
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2335