Logo ROOT   6.16/01
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
28Manages histogram axis attributes.
29
30They 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.
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Destructor.
53
55{
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Copy of the object.
60
61void 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) {
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
111void 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) > 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 Int_t ndiv = (n%1000000);
232 Bool_t isOptimized = optim && (ndiv>0);
233 Int_t current_maxDigits = abs(fNdivisions)/1000000;
234 fNdivisions = abs(ndiv) + current_maxDigits*1000000;
235 if (!isOptimized) fNdivisions = -fNdivisions;
236
237 if (gPad) gPad->Modified();
238}
239
240////////////////////////////////////////////////////////////////////////////////
241///see function above
242
244{
245 SetNdivisions(n1+100*n2+10000*n3, optim);
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// This function sets the maximum number of digits permitted for the axis labels
250/// above which the notation with 10^N is used.
251///
252/// For example, to accept 6 digits number like 900000 on the X axis of the
253/// histogram `h` call:
254///
255/// ~~~ {.cpp}
256/// h->GetXaxis()->SetMaxDigits(6);
257/// ~~~
258///
259/// The default value is 5.
260///
261/// The default value for all axis can be set with the static function
262/// `TGaxis::SetMaxDigits`.
263
265{
266 Bool_t isOptimized = fNdivisions>0;
267 Int_t absDiv = abs(fNdivisions);
268 Int_t current_maxDigits = absDiv/1000000;
269 Int_t current_Ndivisions = absDiv - (current_maxDigits*1000000);
270 fNdivisions = (current_Ndivisions + (maxDigits*1000000));
271 if (!isOptimized) fNdivisions = -fNdivisions;
272
273 if (gPad) gPad->Modified();
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Set tick mark length
278/// The length is expressed in per cent of the pad width
279
281{
282 fTickLength = length;
283 if (gPad) gPad->Modified();
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// Set distance between the axis and the axis title
288/// Offset is a correction factor with respect to the "standard" value.
289/// - offset = 1 uses standard position that is computed in function
290/// of the label offset and size.
291/// - offset = 1.2 will add 20 per cent more to the standard offset.
292/// - offset = 0 automatic placement for the Y axis title (default).
293
295{
296 fTitleOffset = offset;
297 if (gPad) gPad->Modified();
298}
299
300////////////////////////////////////////////////////////////////////////////////
301/// Set size of axis title
302/// The size is expressed in per cent of the pad width
303
305{
306 fTitleSize = size;
307 if (gPad) gPad->Modified();
308}
309
310////////////////////////////////////////////////////////////////////////////////
311/// Set color of axis title
312
314{
315 fTitleColor = color;
316 if (gPad) gPad->Modified();
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Set the title font.
321
323{
324 fTitleFont = font;
325 if (gPad) gPad->Modified();
326}
327
328////////////////////////////////////////////////////////////////////////////////
329/// Stream an object of class TAttAxis.
330
331void TAttAxis::Streamer(TBuffer &R__b)
332{
333 if (R__b.IsReading()) {
334 UInt_t R__s, R__c;
335 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
336 if (R__v > 3) {
337 R__b.ReadClassBuffer(TAttAxis::Class(), this, R__v, R__s, R__c);
338 return;
339 }
340 //====process old versions before automatic schema evolution
341 R__b >> fNdivisions;
342 R__b >> fAxisColor;
343 R__b >> fLabelColor;
344 R__b >> fLabelFont;
345 R__b >> fLabelOffset;
346 R__b >> fLabelSize;
347 R__b >> fTickLength;
348 R__b >> fTitleOffset;
349
350 if (R__v > 1 && R__b.GetVersionOwner() > 900)
351 R__b >> fTitleSize;
352 else
354 if (R__v > 2) {
355 R__b >> fTitleColor;
356 R__b >> fTitleFont;
357 }
358 //====end of old versions
359
360 } else {
362 }
363}
void Class()
Definition: Class.C:29
int Int_t
Definition: RtypesCore.h:41
short Version_t
Definition: RtypesCore.h:61
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
short Color_t
Definition: RtypesCore.h:79
short Style_t
Definition: RtypesCore.h:76
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:363
R__EXTERN TStyle * gStyle
Definition: TStyle.h:406
#define gPad
Definition: TVirtualPad.h:286
Manages histogram axis attributes.
Definition: TAttAxis.h:18
Color_t fAxisColor
Color of the line axis.
Definition: TAttAxis.h:21
Int_t fNdivisions
Number of divisions(10000*n3 + 100*n2 + n1)
Definition: TAttAxis.h:20
TAttAxis()
Definition: TAttAxis.cxx:45
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:294
Style_t fTitleFont
Font for axis title.
Definition: TAttAxis.h:30
virtual void SetAxisColor(Color_t color=1, Float_t alpha=1.)
Set color of the line axis and tick marks.
Definition: TAttAxis.cxx:163
Float_t fTitleSize
Size of axis title.
Definition: TAttAxis.h:28
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
Float_t fTitleOffset
Offset of axis title.
Definition: TAttAxis.h:27
virtual void SetTitleFont(Style_t font=62)
Set the title font.
Definition: TAttAxis.cxx:322
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
Float_t fTickLength
Length of tick marks.
Definition: TAttAxis.h:26
virtual void SetLabelFont(Style_t font=62)
Set labels' font.
Definition: TAttAxis.cxx:183
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:304
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
virtual void SetTitleColor(Color_t color=1)
Set color of axis title.
Definition: TAttAxis.cxx:313
Float_t fLabelSize
Size of labels.
Definition: TAttAxis.h:25
virtual ~TAttAxis()
Destructor.
Definition: TAttAxis.cxx:54
virtual void SetMaxDigits(Int_t maxDigits=5)
This function sets the maximum number of digits permitted for the axis labels above which the notatio...
Definition: TAttAxis.cxx:264
Style_t fLabelFont
Font for labels.
Definition: TAttAxis.h:23
Color_t fLabelColor
Color of labels.
Definition: TAttAxis.h:22
virtual void ResetAttAxis(Option_t *option="")
Reset axis attributes.
Definition: TAttAxis.cxx:79
Color_t fTitleColor
Color of axis title.
Definition: TAttAxis.h:29
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:280
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:229
void Copy(TAttAxis &attaxis) const
Copy of the object.
Definition: TAttAxis.cxx:61
Float_t fLabelOffset
Offset of labels.
Definition: TAttAxis.h:24
virtual void SetLabelColor(Color_t color=1, Float_t alpha=1.)
Set color of labels.
Definition: TAttAxis.cxx:173
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual Int_t GetVersionOwner() const =0
Bool_t IsReading() const
Definition: TBuffer.h:83
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
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:2102
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1960
Color_t GetLabelColor(Option_t *axis="X") const
Return the label color number in the axis.
Definition: TStyle.cxx:921
Int_t GetNdivisions(Option_t *axis="X") const
Return number of divisions.
Definition: TStyle.cxx:889
Color_t GetTitleColor(Option_t *axis="X") const
Return title color.
Definition: TStyle.cxx:1009
Float_t GetLabelSize(Option_t *axis="X") const
Return label size.
Definition: TStyle.cxx:957
Float_t GetTickLength(Option_t *axis="X") const
Return tick length.
Definition: TStyle.cxx:997
Float_t GetTitleSize(Option_t *axis="X") const
Return title size.
Definition: TStyle.cxx:1045
Style_t GetLabelFont(Option_t *axis="X") const
Return label font.
Definition: TStyle.cxx:933
Float_t GetTitleOffset(Option_t *axis="X") const
Return title offset.
Definition: TStyle.cxx:1033
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition: TStyle.cxx:1021
Float_t GetLabelOffset(Option_t *axis="X") const
Return label offset.
Definition: TStyle.cxx:945
Color_t GetAxisColor(Option_t *axis="X") const
Return the axis color number in the axis.
Definition: TStyle.cxx:901
const Int_t n
Definition: legend1.C:16
Short_t Abs(Short_t d)
Definition: TMathBase.h:120