Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
AxisStyle.cxx
1/*
2 * AxisStyle.cxx
3 *
4 * Created on: 30 lip 2024
5 * Author: daniel
6 */
7
8#include "AxisStyle.h"
9
10#include <RtypesCore.h>
11#include <TAxis.h>
12#include <TString.h>
13
14#include "XMLNode.h"
15
16namespace Hal {
17 const unsigned short int AxisStyle::kTitleOffset = 0;
18 const unsigned short int AxisStyle::kLabelOffset = 1;
19 const unsigned short int AxisStyle::kTitleSize = 2;
20 const unsigned short int AxisStyle::kLabelSize = 3;
21 const unsigned short int AxisStyle::kTickLength = 4;
22 const unsigned short int AxisStyle::kNdivisions = 5;
23 const unsigned short int AxisStyle::kAxisColor = 6;
24 const unsigned short int AxisStyle::kLabelColor = 7;
25 const unsigned short int AxisStyle::kTitleColor = 8;
26 const unsigned short int AxisStyle::kTitleFont = 9;
27 const unsigned short int AxisStyle::kCenterTitle = 10;
28 const unsigned short int AxisStyle::kRangeMin = 11;
29 const unsigned short int AxisStyle::kRangeMax = 12;
30 const unsigned short int AxisStyle::kTitle = 13;
31
32 void AxisStyle::SetTitleOffset(Float_t val) { SetF(kTitleOffset, val); }
33
34 void AxisStyle::SetLabelOffset(Float_t val) { SetF(kLabelOffset, val); }
35
36 void AxisStyle::SetTitleSize(Float_t val) { SetF(kTitleSize, val); }
37
38 void AxisStyle::SetLabelSize(Float_t val) { SetF(kLabelSize, val); }
39
40 void AxisStyle::SetTickLength(Float_t val) { SetF(kTickLength, val); }
41
42 void AxisStyle::SetNdivisions(Int_t val) { SetI(kNdivisions, val); }
43
44 void AxisStyle::SetAxisColor(Int_t val) { SetI(kAxisColor, val); }
45
46 void AxisStyle::SetLabelColor(Int_t val) { SetI(kLabelColor, val); }
47
48 void AxisStyle::SetTitleColor(Int_t val) { SetI(kTitleColor, val); }
49
50 void AxisStyle::SetTitleFont(Int_t val) { SetI(kTitleFont, val); }
51
52 void AxisStyle::SetCenterTitle(Int_t val) { SetI(kCenterTitle, val); }
53
54 Float_t AxisStyle::GetTitleOffset() const { return GetF(kTitleOffset); }
55
56 Float_t AxisStyle::GetLabelOffset() const { return GetF(kLabelOffset); }
57
58 Float_t AxisStyle::GetTitleSize() const { return GetF(kTitleSize); }
59
60 Float_t AxisStyle::GetLabelSize() const { return GetF(kLabelSize); }
61
62 Float_t AxisStyle::GetTickLength() const { return GetF(kTickLength); }
63
64 Int_t AxisStyle::GetNDivisions() const { return GetI(kNdivisions); }
65
66 Int_t AxisStyle::GetAxisColor() const { return GetI(kAxisColor); }
67
68 Int_t AxisStyle::GetLabelColor() const { return GetI(kLabelColor); }
69
70 Int_t AxisStyle::GetTitleColor() const { return GetI(kTitleColor); }
71
72 Int_t AxisStyle::GetTitleFont() const { return GetI(kTitleFont); }
73
74 Int_t AxisStyle::GetCenterTitle() const { return GetI(kCenterTitle); }
75
76 void AxisStyle::Apply(TAxis& obj) const {
77 if (Find(kTitleOffset)) obj.SetTitleOffset(GetF(kTitleOffset));
78 if (Find(kLabelOffset)) obj.SetLabelOffset(GetF(kLabelOffset));
79 if (Find(kTitleSize)) obj.SetTitleSize(GetF(kTitleSize));
80 if (Find(kLabelSize)) obj.SetLabelSize(GetF(kLabelSize));
81 if (Find(kTickLength)) obj.SetTickLength(GetF(kTickLength));
82 if (Find(kNdivisions)) obj.SetNdivisions(GetI(kNdivisions));
83 if (Find(kAxisColor)) obj.SetAxisColor(GetI(kAxisColor));
84 if (Find(kLabelColor)) obj.SetLabelColor(GetI(kLabelColor));
85 if (Find(kTitleColor)) obj.SetTitleColor(GetI(kTitleColor));
86 if (Find(kTitleFont)) obj.SetTitleFont(GetI(kTitleFont));
87 if (Find(kCenterTitle)) obj.CenterTitle(GetI(kCenterTitle));
88 if (Find(kTitle)) obj.SetTitle(fTitle);
89 if (Find(kRangeMin) && Find(kRangeMin)) obj.SetRangeUser(GetF(kRangeMin), GetF(kRangeMax));
90 };
91
92 void AxisStyle::SetTitle(TString val) {
93 SetI(kTitle, 0);
94 fTitle = val;
95 }
96
97 void AxisStyle::ExportToXML(XMLNode* node) const {
98 if (Find(kTitleOffset)) node->AddAttrib(new Hal::XMLAttrib("TitleOffset", Form("%4.4f", GetF(kTitleOffset))));
99 if (Find(kLabelOffset)) node->AddAttrib(new Hal::XMLAttrib("LabelOffset", Form("%4.4f", GetF(kLabelOffset))));
100 if (Find(kTitleSize)) node->AddAttrib(new Hal::XMLAttrib("TitleSize", Form("%4.4f", GetF(kTitleSize))));
101 if (Find(kLabelSize)) node->AddAttrib(new Hal::XMLAttrib("LabelSize", Form("%4.4f", GetF(kLabelSize))));
102 if (Find(kTickLength)) node->AddAttrib(new Hal::XMLAttrib("TickLength", Form("%4.4f", GetF(kTickLength))));
103 if (Find(kNdivisions)) node->AddAttrib(new Hal::XMLAttrib("Ndivisions", Form("%i", GetI(kNdivisions))));
104 if (Find(kAxisColor)) node->AddAttrib(new Hal::XMLAttrib("AxisColor", Form("%i", GetI(kAxisColor))));
105 if (Find(kLabelColor)) node->AddAttrib(new Hal::XMLAttrib("LabelColor", Form("%i", GetI(kLabelColor))));
106 if (Find(kTitleColor)) node->AddAttrib(new Hal::XMLAttrib("TitleColor", Form("%i", GetI(kTitleColor))));
107 if (Find(kTitleFont)) node->AddAttrib(new Hal::XMLAttrib("TitleFont", Form("%i", GetI(kTitleFont))));
108 if (Find(kCenterTitle)) node->AddAttrib(new Hal::XMLAttrib("CenterTitle", Form("%i", GetI(kCenterTitle))));
109 if (Find(kTitle)) node->AddAttrib(new Hal::XMLAttrib("Title", fTitle));
110 if (Find(kRangeMin)) node->AddAttrib(new Hal::XMLAttrib("RangeMin", Form("%4.4f", GetF(kRangeMin))));
111 if (Find(kRangeMax)) node->AddAttrib(new Hal::XMLAttrib("RangeMax", Form("%4.4f", GetF(kRangeMax))));
112 }
113
114 void AxisStyle::SetRangeUser(Float_t min, Float_t max) {
115 SetF(kRangeMin, min);
116 SetF(kRangeMax, max);
117 }
118
119 void AxisStyle::ImportFromXML(XMLNode* node) {
120
121 if (auto atr = node->GetAttrib("TitleOffset")) {
122 float x = atr->GetValue().Atof();
123 SetTitleOffset(x);
124 }
125 if (auto atr = node->GetAttrib("LabelOffset")) {
126 float x = atr->GetValue().Atof();
127 SetLabelOffset(x);
128 }
129 if (auto atr = node->GetAttrib("TitleSize")) {
130 float x = atr->GetValue().Atof();
131 SetTitleSize(x);
132 }
133 if (auto atr = node->GetAttrib("LabelSize")) {
134 float x = atr->GetValue().Atof();
135 SetLabelSize(x);
136 }
137 if (auto atr = node->GetAttrib("TickLength")) {
138 float x = atr->GetValue().Atof();
139 SetTickLength(x);
140 }
141 if (auto atr = node->GetAttrib("Ndivisions")) {
142 int x = atr->GetValue().Atoi();
143 SetNdivisions(x);
144 }
145 if (auto atr = node->GetAttrib("AxisColor")) {
146 int x = atr->GetValue().Atoi();
147 SetAxisColor(x);
148 }
149 if (auto atr = node->GetAttrib("LabelColor")) {
150 int x = atr->GetValue().Atoi();
151 SetLabelColor(x);
152 }
153 if (auto atr = node->GetAttrib("TitleColor")) {
154 int x = atr->GetValue().Atoi();
155 SetTitleColor(x);
156 }
157 if (auto atr = node->GetAttrib("TitleFont")) {
158 int x = atr->GetValue().Atoi();
159 SetTitleFont(x);
160 }
161 if (auto atr = node->GetAttrib("CenterTitle")) {
162 int x = atr->GetValue().Atoi();
163 SetCenterTitle(x);
164 }
165
166 if (node->GetAttrib("RangeMin") && node->GetAttrib("RangeMin")) {
167 auto atr1 = node->GetAttrib("RangeMin");
168 auto atr2 = node->GetAttrib("RangeMax");
169 float mini = atr1->GetValue().Atof();
170 float maxi = atr2->GetValue().Atof();
171 SetRangeUser(mini, maxi);
172 }
173
174 if (auto atr = node->GetAttrib("CenterTitle")) {
175 int x = atr->GetValue().Atoi();
176 SetCenterTitle(x);
177 }
178 if (auto atr = node->GetAttrib("Title")) {
179 TString x = atr->GetValue();
180 SetTitle(x);
181 }
182 }
183
184 AxisStyle::AxisStyle() {}
185
186 AxisStyle::AxisStyle(Double_t titleSize, Double_t labelSize, Double_t titleOffset, Double_t labelOffset) {
187 SetTitleSize(titleSize);
188 SetLabelSize(labelSize);
189 SetTitleOffset(titleOffset);
190 SetLabelOffset(labelOffset);
191 }
192
193} /* namespace Hal */
Bool_t Find(Int_t bit) const
Definition Style.h:55