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