3131/* * \class TPie
3232\ingroup BasicGraphics
3333
34- Draw a Pie Chart,
34+ Define 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+
49+ After the use of > or < options the internal order of the TPieSlices is changed.
50+
51+ \anchor PIE01
52+ #### Labels format
53+ The labels' format can be changed with TPie::SetLabelFormat().
54+
55+ The 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 |
3563
3664Example:
65+ ```
66+ mypie->SetLabelFormat("%txt (%frac)");
67+ ```
68+ The numeric format in the label can be changed with TPie::SetFractionFormat.
69+ The numeric format the slices' values can be changed with TPie::SetValueFormat.
70+ The numeric format for the percent value of a slice can be changed with TPie::SetPercentFormat.
71+
72+ If the colors are not specified (`nullptr`) they are automatically
73+ taken from the current color palette as shown in the following example.
74+
75+ Begin_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+ }
89+ End_Macro
90+
91+ More complex example:
3792
3893Begin_Macro(source)
3994../../../tutorials/visualisation/graphics/piechart.C
4095End_Macro
96+
4197*/
4298
4399Double_t gX = 0 ; // Temporary pie X position.
@@ -739,6 +795,8 @@ void TPie::Init(Int_t np, Double_t ao, Double_t x, Double_t y, Double_t r)
739795
740796 fPieSlices = new TPieSlice*[fNvals ];
741797
798+ Int_t ic = 0 , dc = TMath::Max (1 , gStyle ->GetNumberOfColors ()/fNvals );
799+
742800 for (Int_t i=0 ;i<fNvals ;++i) {
743801 TString tmplbl = " Slice" ;
744802 tmplbl += i;
@@ -747,7 +805,8 @@ void TPie::Init(Int_t np, Double_t ao, Double_t x, Double_t y, Double_t r)
747805 fPieSlices [i]->SetLineColor (1 );
748806 fPieSlices [i]->SetLineStyle (1 );
749807 fPieSlices [i]->SetLineWidth (1 );
750- fPieSlices [i]->SetFillColor (gStyle ->GetColorPalette (i));
808+ fPieSlices [i]->SetFillColor (gStyle ->GetColorPalette (ic));
809+ ic = TMath::Min (gStyle ->GetNumberOfColors (), ic+dc);
751810 fPieSlices [i]->SetFillStyle (1001 );
752811 }
753812
@@ -782,23 +841,7 @@ TLegend* TPie::MakeLegend(Double_t x1, Double_t y1, Double_t x2, Double_t y2, co
782841
783842// //////////////////////////////////////////////////////////////////////////////
784843// / Paint a Pie chart in a canvas.
785- // / The possible option are:
786- // /
787- // / - "R" Print the labels along the central "R"adius of slices.
788- // / - "T" Print the label in a direction "T"angent to circle that describes
789- // / the TPie.
790- // / - "SC" Paint the labels with the "S"ame "C"olor as the slices.
791- // / - "3D" Draw the pie-chart with a pseudo 3D effect.
792- // / - "NOL" No OutLine: Don't draw the slices' outlines, any property over the
793- // / slices' line is ignored.
794- // / - ">" Sort the slices in increasing order.
795- // / - "<" Sort the slices in decreasing order.
796- // /
797- // / After the use of > or < options the internal order of the TPieSlices
798- // / is changed.
799- // /
800- // / Other options changing the labels' format are described in
801- // / TPie::SetLabelFormat().
844+ // / [See the class description for the possible drawing options](\ref PIE00)
802845
803846void TPie::Paint (Option_t *option)
804847{
@@ -1268,15 +1311,8 @@ void TPie::SetHeight(Double_t val/*=20*/)
12681311}
12691312
12701313// //////////////////////////////////////////////////////////////////////////////
1271- // / This method is used to customize the label format. The format string
1272- // / must contain one of these modifiers:
1273- // /
1274- // / - %txt : to print the text label associated with the slice
1275- // / - %val : to print the numeric value of the slice
1276- // / - %frac : to print the relative fraction of this slice
1277- // / - %perc : to print the % of this slice
1278- // /
1279- // / ex. : mypie->SetLabelFormat("%txt (%frac)");
1314+ // / This method is used to customize the label format.
1315+ // / [See the class description for the possible labels format](\ref PIE01)
12801316
12811317void TPie::SetLabelFormat (const char *fmt)
12821318{
0 commit comments