Logo ROOT  
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 "TAttAxis.h"
13#include "TBuffer.h"
14#include "TStyle.h"
15#include "TVirtualPad.h"
16#include "TColor.h"
17#include "TMathBase.h"
18#include <cstdlib>
19#include <iostream>
20
22
23/** \class TAttAxis
24\ingroup Base
25\ingroup GraphicsAtt
26
27Manages histogram axis attributes.
28
29They are:
30
31 - The number of divisions: TAttAxis::SetNdivisions.
32 - The line axis' color: TAttAxis::SetAxisColor.
33 - The axis labels' color: TAttAxis::SetLabelColor.
34 - The axis labels' font: TAttAxis::SetLabelFont.
35 - The axis labels' offset: TAttAxis::SetLabelOffset.
36 - The axis labels' size: TAttAxis::SetLabelSize.
37 - The tick marks's length: TAttAxis::SetTickLength or TAttAxis::SetTickSize .
38 - The axis title's offset: TAttAxis::SetTitleOffset.
39 - The axis title's size: TAttAxis::SetTitleSize.
40 - The axis title's color: TAttAxis::SetTitleColor.
41 - The axis title's font: TAttAxis::SetTitleFont.
42
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.035) > 0.001) {
137 out<<" "<<name<<subname<<"->SetLabelSize("<<fLabelSize<<");"<<std::endl;
138 }
139 if (TMath::Abs(fTitleSize-0.035) > 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/// A negative value allow to draw the label on the other side of the axis.
193
195{
196 fLabelOffset = offset;
197 if (gPad) gPad->Modified();
198}
199
200
201////////////////////////////////////////////////////////////////////////////////
202/// Set size of axis labels.
203/// The size is expressed in per cent of the pad size.
204
206{
208 if (gPad) gPad->Modified();
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Set the number of divisions for this axis.
213///
214/// - if optim = kTRUE (default), the number of divisions will be
215/// optimized around the specified value.
216/// - if optim = kFALSE, or n < 0, the axis will be forced to use
217/// exactly n divisions.
218///~~~ {.cpp}
219/// n = n1 + 100*n2 + 10000*n3
220///~~~
221/// Where n1 is the number of primary divisions,
222/// n2 is the number of second order divisions and
223/// n3 is the number of third order divisions.
224///
225/// If the number of divisions is "optimized" (see above) n1, n2, n3 are
226/// maximum values.
227///
228/// Examples:
229///
230/// - ndiv = 0: no tick marks.
231/// - ndiv = 2: 2 divisions, one tick mark in the middle of the axis.
232/// - ndiv = 510: 10 primary divisions, 5 secondary divisions.
233/// - ndiv = -10: exactly 10 primary divisions.
234
235
236
238{
239 Int_t ndiv = (n%1000000);
240 Bool_t isOptimized = optim && (ndiv>0);
241 Int_t current_maxDigits = abs(fNdivisions)/1000000;
242 fNdivisions = abs(ndiv) + current_maxDigits*1000000;
243 if (!isOptimized) fNdivisions = -fNdivisions;
244
245 if (gPad) gPad->Modified();
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Set the number of divisions for this axis using one `int` per division level.
250
252{
253 SetNdivisions(n1+100*n2+10000*n3, optim);
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// This function sets the maximum number of digits permitted for the axis labels
258/// above which the notation with 10^N is used.
259///
260/// For example, to accept 6 digits number like 900000 on the X axis of the
261/// histogram `h` call:
262///
263/// ~~~ {.cpp}
264/// h->GetXaxis()->SetMaxDigits(6);
265/// ~~~
266///
267/// The default value is 5.
268///
269/// The default value for all axis can be set with the static function
270/// `TGaxis::SetMaxDigits`.
271
273{
274 Bool_t isOptimized = fNdivisions>0;
275 Int_t absDiv = abs(fNdivisions);
276 Int_t current_maxDigits = absDiv/1000000;
277 Int_t current_Ndivisions = absDiv - (current_maxDigits*1000000);
278 fNdivisions = (current_Ndivisions + (maxDigits*1000000));
279 if (!isOptimized) fNdivisions = -fNdivisions;
280
281 if (gPad) gPad->Modified();
282}
283
284////////////////////////////////////////////////////////////////////////////////
285/// Set tick mark length.
286/// The length is expressed in per cent of the pad width.
287
289{
290 fTickLength = length;
291 if (gPad) gPad->Modified();
292}
293
294////////////////////////////////////////////////////////////////////////////////
295/// Set distance between the axis and the axis title.
296/// Offset is a correction factor with respect to the "standard" value.
297/// - offset = 1 uses standard position that is computed in function
298/// of the label offset and size.
299/// - offset = 1.2 will add 20 per cent more to the standard offset.
300/// - offset = 0 automatic placement for the Y axis title (default).
301
303{
304 fTitleOffset = offset;
305 if (gPad) gPad->Modified();
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Set size of axis title.
310/// The size is expressed in per cent of the pad width
311
313{
315 if (gPad) gPad->Modified();
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Set color of axis title.
320
322{
323 fTitleColor = color;
324 if (gPad) gPad->Modified();
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Set the title font.
329
331{
332 fTitleFont = font;
333 if (gPad) gPad->Modified();
334}
335
336////////////////////////////////////////////////////////////////////////////////
337/// Stream an object of class TAttAxis.
338
339void TAttAxis::Streamer(TBuffer &R__b)
340{
341 if (R__b.IsReading()) {
342 UInt_t R__s, R__c;
343 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
344 if (R__v > 3) {
345 R__b.ReadClassBuffer(TAttAxis::Class(), this, R__v, R__s, R__c);
346 return;
347 }
348 //====process old versions before automatic schema evolution
349 R__b >> fNdivisions;
350 R__b >> fAxisColor;
351 R__b >> fLabelColor;
352 R__b >> fLabelFont;
353 R__b >> fLabelOffset;
354 R__b >> fLabelSize;
355 R__b >> fTickLength;
356 R__b >> fTitleOffset;
357
358 if (R__v > 1 && R__b.GetVersionOwner() > 900)
359 R__b >> fTitleSize;
360 else
362 if (R__v > 2) {
363 R__b >> fTitleColor;
364 R__b >> fTitleFont;
365 }
366 //====end of old versions
367
368 } else {
370 }
371}
void Class()
Definition: Class.C:29
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition: RtypesCore.h:45
short Version_t
Definition: RtypesCore.h:65
unsigned int UInt_t
Definition: RtypesCore.h:46
bool Bool_t
Definition: RtypesCore.h:63
short Color_t
Definition: RtypesCore.h:92
short Style_t
Definition: RtypesCore.h:89
float Float_t
Definition: RtypesCore.h:57
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:364
char name[80]
Definition: TGX11.cxx:110
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
#define gPad
Definition: TVirtualPad.h:287
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.
Definition: TAttAxis.cxx:302
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.
Definition: TAttAxis.cxx:205
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:330
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
Definition: TAttAxis.cxx:194
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.
Definition: TAttAxis.cxx:312
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:321
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:272
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.
Definition: TAttAxis.cxx:288
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:237
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:43
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:86
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:2127
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1985
Color_t GetLabelColor(Option_t *axis="X") const
Return the label color number in the axis.
Definition: TStyle.cxx:1064
Int_t GetNdivisions(Option_t *axis="X") const
Return number of divisions.
Definition: TStyle.cxx:1032
Color_t GetTitleColor(Option_t *axis="X") const
Return title color.
Definition: TStyle.cxx:1152
Float_t GetLabelSize(Option_t *axis="X") const
Return label size.
Definition: TStyle.cxx:1100
Float_t GetTickLength(Option_t *axis="X") const
Return tick length.
Definition: TStyle.cxx:1140
Float_t GetTitleSize(Option_t *axis="X") const
Return title size.
Definition: TStyle.cxx:1188
Style_t GetLabelFont(Option_t *axis="X") const
Return label font.
Definition: TStyle.cxx:1076
Float_t GetTitleOffset(Option_t *axis="X") const
Return title offset.
Definition: TStyle.cxx:1176
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition: TStyle.cxx:1164
Float_t GetLabelOffset(Option_t *axis="X") const
Return label offset.
Definition: TStyle.cxx:1088
Color_t GetAxisColor(Option_t *axis="X") const
Return the axis color number in the axis.
Definition: TStyle.cxx:1044
const Int_t n
Definition: legend1.C:16
Short_t Abs(Short_t d)
Definition: TMathBase.h:120