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