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