Jpp
Public Member Functions | List of all members
JGIZMO::JLegend Class Reference

Wrapper class for ROOT TLegend. More...

#include <JLegend.hh>

Inheritance diagram for JGIZMO::JLegend:

Public Member Functions

 JLegend (const Int_t width, const Int_t height, const std::string option="TR")
 Constructor. More...
 

Detailed Description

Wrapper class for ROOT TLegend.

Definition at line 23 of file JLegend.hh.

Constructor & Destructor Documentation

◆ JLegend()

JGIZMO::JLegend::JLegend ( const Int_t  width,
const Int_t  height,
const std::string  option = "TR" 
)
inline

Constructor.

Parameters
widthwidth [characters]
heightheight [lines]
optionposition [TR TL BL BR]

Definition at line 34 of file JLegend.hh.

36  :
37  TLegend()
38  {
39  using namespace std;
40 
41  gPad->Update();
42 
43  //SetFillStyle(4000);
44  SetFillColor(kWhite);
45  SetBorderSize(0);
46  SetTextAlign(12);
47  SetTextFont(gStyle->GetStatFont());
48  SetTextSize(gStyle->GetStatFontSize());
49 
50  const Double_t X1 = 0.0 + gPad->GetLeftMargin();
51  const Double_t X2 = 1.0 - gPad->GetRightMargin();
52  const Double_t Y1 = 0.0 + gPad->GetBottomMargin();
53  const Double_t Y2 = 1.0 - gPad->GetTopMargin();
54 
55  const Double_t w = gPad->XtoPixel(gPad->GetX2());
56  const Double_t h = gPad->YtoPixel(gPad->GetY1());
57  const Double_t ch = gStyle->GetStatFontSize() * (w < h ? w : h);
58 
59  const Double_t fx = 0.70 * ch/w; // estimated fonst size [NDC]
60  const Double_t fy = 1.10 * ch/h; // estimated fonst size [NDC]
61  const Double_t eps = 0.002; // extra space [NDC]
62  const Int_t nc = 3; // number of characters reserved for margin
63 
64  Int_t wd = width;
65 
66  if (wd < 2) {
67  wd = 2;
68  }
69 
70  SetMargin((Double_t) nc / (Double_t) (wd + nc));
71 
72  Double_t W = (wd + nc) * fx; // width [NDC]
73  Double_t H = (height) * fy; // height [NDC]
74 
75  Double_t fc = 1.0; // scaling factor
76 
77  if (fc * W > X2 - X1 - 2*eps) {
78  fc *= (X2 - X1 - 2*eps) / W;
79  }
80 
81  if (fc * H > Y2 - Y1 - 2*eps) {
82  fc *= (Y2 - Y1 - 2*eps) / H;
83  }
84 
85  SetTextSize(GetTextSize() * fc);
86 
87  W *= fc;
88  H *= fc;
89 
90  // default position is top-right
91 
92  Double_t x1 = X2 - W - eps;
93  Double_t y1 = Y2 - H - eps;
94  Double_t x2 = X2 - eps;
95  Double_t y2 = Y2 - eps;
96 
97  int halign = 2;
98  int valign = 2;
99 
100  if (option.find('T') != string::npos && option.find('B') == string::npos) { // top
101 
102  y1 = Y2 - H - eps;
103  y2 = Y2 - eps;
104 
105  //valign = 1;
106  }
107 
108  if (option.find('B') != string::npos && option.find('T') == string::npos) { // bottom
109 
110  y1 = Y1 + eps;
111  y2 = Y1 + H + eps;
112 
113  //valign = 3;
114  }
115 
116  if (option.find('R') != string::npos && option.find('L') == string::npos) { // right
117 
118  x1 = X2 - W - eps;
119  x2 = X2 - eps;
120 
121  halign = 1;
122  }
123 
124  if (option.find('L') != string::npos && option.find('R') == string::npos) { // left
125 
126  x1 = X1 + eps;
127  x2 = X1 + W + eps;
128 
129  halign = 1;
130  }
131 
132  SetTextAlign(halign*10 + valign);
133  SetX1NDC(x1);
134  SetY1NDC(y1);
135  SetX2NDC(x2);
136  SetY2NDC(y2);
137  }

The documentation for this class was generated from the following file:
JTOOLS::w
data_type w[N+1][M+1]
Definition: JPolint.hh:708
JTOOLS::H
static const double H
Planck constant [eV s].
Definition: JConstants.hh:25
std
Definition: jaanetDictionary.h:36