ROOT  6.06/09
Reference Guide
TAttAxis.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Rene Brun 12/12/94
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 "Riostream.h"
13 #include "TAttAxis.h"
14 #include "TStyle.h"
15 #include "TVirtualPad.h"
16 #include "TColor.h"
17 #include "TClass.h"
18 #include "TMathBase.h"
19 #include <stdlib.h>
20 
22 
23 /** \class TAttAxis
24 Manages histogram axis attributes
25 */
26 
28 {
29  // Constructor.
30  ResetAttAxis();
31 }
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Destructor.
35 
37 {
38 }
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Copy of the object.
42 
43 void TAttAxis::Copy(TAttAxis &attaxis) const
44 {
45  attaxis.fNdivisions = fNdivisions;
46  attaxis.fAxisColor = fAxisColor;
47  attaxis.fLabelColor = fLabelColor;
48  attaxis.fLabelFont = fLabelFont;
49  attaxis.fLabelOffset = fLabelOffset;
50  attaxis.fLabelSize = fLabelSize;
51  attaxis.fTickLength = fTickLength;
52  attaxis.fTitleOffset = fTitleOffset;
53  attaxis.fTitleSize = fTitleSize;
54  attaxis.fTitleColor = fTitleColor;
55  attaxis.fTitleFont = fTitleFont;
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Reset axis attributes
60 
62 {
63  if (gStyle) {
64  fNdivisions = gStyle->GetNdivisions(option);
65  fAxisColor = gStyle->GetAxisColor(option);
66  fLabelColor = gStyle->GetLabelColor(option);
67  fLabelFont = gStyle->GetLabelFont(option);
68  fLabelOffset = gStyle->GetLabelOffset(option);
69  fLabelSize = gStyle->GetLabelSize(option);
70  fTickLength = gStyle->GetTickLength(option);
71  fTitleOffset = gStyle->GetTitleOffset(option);
72  fTitleSize = gStyle->GetTitleSize(option);
73  fTitleColor = gStyle->GetTitleColor(option);
74  fTitleFont = gStyle->GetTitleFont(option);
75  } else {
76  fNdivisions = 510;
77  fAxisColor = 1;
78  fLabelColor = 1;
79  fLabelFont = 62;
80  fLabelOffset = 0.005;
81  fLabelSize = 0.04;
82  fTickLength = 0.03;
83  fTitleOffset = 1;
85  fTitleColor = 1;
86  fTitleFont = 62;
87  }
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Save axis attributes as C++ statement(s) on output stream out
92 
93 void TAttAxis::SaveAttributes(std::ostream &out, const char *name, const char *subname)
94 {
95  if (fNdivisions != 510) {
96  out<<" "<<name<<subname<<"->SetNdivisions("<<fNdivisions<<");"<<std::endl;
97  }
98  if (fAxisColor != 1) {
99  if (fAxisColor > 228) {
100  TColor::SaveColor(out, fAxisColor);
101  out<<" "<<name<<subname<<"->SetAxisColor(ci);" << std::endl;
102  } else
103  out<<" "<<name<<subname<<"->SetAxisColor("<<fAxisColor<<");"<<std::endl;
104  }
105  if (fLabelColor != 1) {
106  if (fLabelColor > 228) {
107  TColor::SaveColor(out, fLabelColor);
108  out<<" "<<name<<subname<<"->SetLabelColor(ci);" << std::endl;
109  } else
110  out<<" "<<name<<subname<<"->SetLabelColor("<<fLabelColor<<");"<<std::endl;
111  }
112  if (fLabelFont != 62) {
113  out<<" "<<name<<subname<<"->SetLabelFont("<<fLabelFont<<");"<<std::endl;
114  }
115  if (TMath::Abs(fLabelOffset-0.005) > 0.0001) {
116  out<<" "<<name<<subname<<"->SetLabelOffset("<<fLabelOffset<<");"<<std::endl;
117  }
118  if (TMath::Abs(fLabelSize-0.04) > 0.001) {
119  out<<" "<<name<<subname<<"->SetLabelSize("<<fLabelSize<<");"<<std::endl;
120  }
121  if (TMath::Abs(fTitleSize-0.04) > 0.001) {
122  out<<" "<<name<<subname<<"->SetTitleSize("<<fTitleSize<<");"<<std::endl;
123  }
124  if (TMath::Abs(fTickLength-0.03) > 0.001) {
125  out<<" "<<name<<subname<<"->SetTickLength("<<fTickLength<<");"<<std::endl;
126  }
127  if (TMath::Abs(fTitleOffset-1) > 0.001) {
128  out<<" "<<name<<subname<<"->SetTitleOffset("<<fTitleOffset<<");"<<std::endl;
129  }
130  if (fTitleColor != 1) {
131  if (fTitleColor > 228) {
133  out<<" "<<name<<subname<<"->SetTitleColor(ci);" << std::endl;
134  } else
135  out<<" "<<name<<subname<<"->SetTitleColor("<<fTitleColor<<");"<<std::endl;
136  }
137  if (fTitleFont != 62) {
138  out<<" "<<name<<subname<<"->SetTitleFont("<<fTitleFont<<");"<<std::endl;
139  }
140 }
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Set color of the line axis and tick marks
144 
146 {
147  if (alpha<1.) fAxisColor = TColor::GetColorTransparent(color, alpha);
148  else fAxisColor = color;
149  if (gPad) gPad->Modified();
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Set color of labels
154 
156 {
157  if (alpha<1.) fLabelColor = TColor::GetColorTransparent(color, alpha);
158  else fLabelColor = color;
159  if (gPad) gPad->Modified();
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Set labels' font.
164 
166 {
167  fLabelFont = font;
168  if (gPad) gPad->Modified();
169 }
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// Set distance between the axis and the labels
173 /// The distance is expressed in per cent of the pad width
174 
176 {
177  fLabelOffset = offset;
178  if (gPad) gPad->Modified();
179 }
180 
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 /// Set size of axis labels
184 /// The size is expressed in per cent of the pad width
185 
187 {
188  fLabelSize = size;
189  if (gPad) gPad->Modified();
190 }
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 /// Set the number of divisions for this axis.
194 ///
195 /// - if optim = kTRUE (default), the number of divisions will be
196 /// optimized around the specified value.
197 /// - if optim = kFALSE, or n < 0, the axis will be forced to use
198 /// exactly n divisions.
199 ///~~~ {.cpp}
200 /// n = n1 + 100*n2 + 10000*n3
201 ///~~~
202 /// Where n1 is the number of primary divisions,
203 /// n2 is the number of second order divisions and
204 /// n3 is the number of third order divisions.
205 ///
206 /// e.g. 512 means 12 primary and 5 secondary divisions.
207 ///
208 /// If the number of divisions is "optimized" (see above) n1, n2, n3 are
209 /// maximum values.
210 
212 {
213  fNdivisions = n;
214  if (!optim) fNdivisions = -abs(n);
215  if (gPad) gPad->Modified();
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 ///see function above
220 
222 {
223  SetNdivisions(n1+100*n2+10000*n3, optim);
224 }
225 
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Set tick mark length
229 /// The length is expressed in per cent of the pad width
230 
232 {
233  fTickLength = length;
234  if (gPad) gPad->Modified();
235 }
236 
237 ////////////////////////////////////////////////////////////////////////////////
238 /// Set distance between the axis and the axis title
239 /// Offset is a correction factor with respect to the "standard" value.
240 /// - offset = 1 uses the default position that is computed in function
241 /// of the label offset and size.
242 /// - offset = 1.2 will add 20 per cent more to the default offset.
243 
245 {
246  fTitleOffset = offset;
247  if (gPad) gPad->Modified();
248 }
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Set size of axis title
252 /// The size is expressed in per cent of the pad width
253 
255 {
256  fTitleSize = size;
257  if (gPad) gPad->Modified();
258 }
259 
260 ////////////////////////////////////////////////////////////////////////////////
261 /// Set color of axis title
262 
264 {
265  fTitleColor = color;
266  if (gPad) gPad->Modified();
267 }
268 
269 ////////////////////////////////////////////////////////////////////////////////
270 /// Set the title font.
271 
273 {
274  fTitleFont = font;
275  if (gPad) gPad->Modified();
276 }
277 
278 ////////////////////////////////////////////////////////////////////////////////
279 /// Stream an object of class TAttAxis.
280 
281 void TAttAxis::Streamer(TBuffer &R__b)
282 {
283  if (R__b.IsReading()) {
284  UInt_t R__s, R__c;
285  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
286  if (R__v > 3) {
287  R__b.ReadClassBuffer(TAttAxis::Class(), this, R__v, R__s, R__c);
288  return;
289  }
290  //====process old versions before automatic schema evolution
291  R__b >> fNdivisions;
292  R__b >> fAxisColor;
293  R__b >> fLabelColor;
294  R__b >> fLabelFont;
295  R__b >> fLabelOffset;
296  R__b >> fLabelSize;
297  R__b >> fTickLength;
298  R__b >> fTitleOffset;
299 
300  if (R__v > 1 && R__b.GetVersionOwner() > 900)
301  R__b >> fTitleSize;
302  else
304  if (R__v > 2) {
305  R__b >> fTitleColor;
306  R__b >> fTitleFont;
307  }
308  //====end of old versions
309 
310  } else {
311  R__b.WriteClassBuffer(TAttAxis::Class(),this);
312  }
313 }
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:244
Float_t GetLabelSize(Option_t *axis="X") const
Return label size.
Definition: TStyle.cxx:774
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
Color_t fAxisColor
Definition: TAttAxis.h:35
Float_t fLabelOffset
Definition: TAttAxis.h:38
Style_t fLabelFont
Definition: TAttAxis.h:37
short Style_t
Definition: RtypesCore.h:76
Bool_t IsReading() const
Definition: TBuffer.h:81
short Version_t
Definition: RtypesCore.h:61
float Float_t
Definition: RtypesCore.h:53
Float_t fLabelSize
Definition: TAttAxis.h:39
const char Option_t
Definition: RtypesCore.h:62
virtual void ResetAttAxis(Option_t *option="")
Reset axis attributes.
Definition: TAttAxis.cxx:61
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
Float_t GetTickLength(Option_t *axis="X") const
Return tick length.
Definition: TStyle.cxx:814
static void SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition: TColor.cxx:1967
Int_t fNdivisions
Definition: TAttAxis.h:34
virtual void SetLabelColor(Color_t color=1, Float_t alpha=1.)
Set color of labels.
Definition: TAttAxis.cxx:155
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:211
Float_t GetTitleSize(Option_t *axis="X") const
Return title size.
Definition: TStyle.cxx:862
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
virtual void SetTitleFont(Style_t font=62)
Set the title font.
Definition: TAttAxis.cxx:272
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Manages histogram axis attributes.
Definition: TAttAxis.h:32
Float_t fTitleSize
Definition: TAttAxis.h:42
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels The distance is expressed in per cent of the pad width...
Definition: TAttAxis.cxx:175
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
virtual void SetLabelFont(Style_t font=62)
Set labels' font.
Definition: TAttAxis.cxx:165
Style_t fTitleFont
Definition: TAttAxis.h:44
void Class()
Definition: Class.C:29
virtual Int_t GetVersionOwner() const =0
Color_t fLabelColor
Definition: TAttAxis.h:36
void Copy(TAttAxis &attaxis) const
Copy of the object.
Definition: TAttAxis.cxx:43
static Vc_ALWAYS_INLINE Vector< T > abs(const Vector< T > &x)
Definition: vector.h:450
virtual ~TAttAxis()
Destructor.
Definition: TAttAxis.cxx:36
Style_t GetLabelFont(Option_t *axis="X") const
Return label font.
Definition: TStyle.cxx:750
char * out
Definition: TBase64.cxx:29
short Color_t
Definition: RtypesCore.h:79
Color_t GetAxisColor(Option_t *axis="X") const
Return the axis color number in the axis.
Definition: TStyle.cxx:718
Double_t length(const TVector2 &v)
Definition: CsgOps.cxx:347
Float_t GetTitleOffset(Option_t *axis="X") const
Return title offset.
Definition: TStyle.cxx:850
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SetAxisColor(Color_t color=1, Float_t alpha=1.)
Set color of the line axis and tick marks.
Definition: TAttAxis.cxx:145
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:186
virtual void SetTitleColor(Color_t color=1)
Set color of axis title.
Definition: TAttAxis.cxx:263
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:254
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1839
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual void SaveAttributes(std::ostream &out, const char *name, const char *subname)
Save axis attributes as C++ statement(s) on output stream out.
Definition: TAttAxis.cxx:93
Color_t GetLabelColor(Option_t *axis="X") const
Return the label color number in the axis.
Definition: TStyle.cxx:738
#define ClassImp(name)
Definition: Rtypes.h:279
Int_t GetNdivisions(Option_t *axis="X") const
Return number of divisions.
Definition: TStyle.cxx:706
Color_t GetTitleColor(Option_t *axis="X") const
Return title color.
Definition: TStyle.cxx:826
#define name(a, b)
Definition: linkTestLib0.cpp:5
Float_t GetLabelOffset(Option_t *axis="X") const
Return label offset.
Definition: TStyle.cxx:762
Float_t fTickLength
Definition: TAttAxis.h:40
#define gPad
Definition: TVirtualPad.h:288
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length The length is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:231
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition: TStyle.cxx:838
Color_t fTitleColor
Definition: TAttAxis.h:43
const Int_t n
Definition: legend1.C:16
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
Float_t fTitleOffset
Definition: TAttAxis.h:41