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