Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
32 - The line axis' color
33 - The labels' color
34 - The labels' font
35 - The labels' offset
36 - The labels' size
37 - The tick marks'
38 - The axis title's offset
39 - The axis title's size
40 - The axis title's color
41 - The axis title's font
42*/
43
45{
46 // Constructor.
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Destructor.
52
54{
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// Copy of the object.
59
60void TAttAxis::Copy(TAttAxis &attaxis) const
61{
62 attaxis.fNdivisions = fNdivisions;
63 attaxis.fAxisColor = fAxisColor;
64 attaxis.fLabelColor = fLabelColor;
65 attaxis.fLabelFont = fLabelFont;
66 attaxis.fLabelOffset = fLabelOffset;
67 attaxis.fLabelSize = fLabelSize;
68 attaxis.fTickLength = fTickLength;
69 attaxis.fTitleOffset = fTitleOffset;
70 attaxis.fTitleSize = fTitleSize;
71 attaxis.fTitleColor = fTitleColor;
72 attaxis.fTitleFont = fTitleFont;
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Reset axis attributes.
77
79{
80 if (gStyle) {
92 } else {
93 fNdivisions = 510;
94 fAxisColor = 1;
95 fLabelColor = 1;
96 fLabelFont = 62;
97 fLabelOffset = 0.005;
98 fLabelSize = 0.04;
99 fTickLength = 0.03;
100 fTitleOffset = 1;
102 fTitleColor = 1;
103 fTitleFont = 62;
104 }
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Save axis attributes as C++ statement(s) on output stream out.
109
110void TAttAxis::SaveAttributes(std::ostream &out, const char *name, const char *subname)
111{
112 if (fNdivisions != 510) {
113 out<<" "<<name<<subname<<"->SetNdivisions("<<fNdivisions<<");"<<std::endl;
114 }
115 if (fAxisColor != 1) {
116 if (fAxisColor > 228) {
118 out<<" "<<name<<subname<<"->SetAxisColor(ci);" << std::endl;
119 } else
120 out<<" "<<name<<subname<<"->SetAxisColor("<<fAxisColor<<");"<<std::endl;
121 }
122 if (fLabelColor != 1) {
123 if (fLabelColor > 228) {
125 out<<" "<<name<<subname<<"->SetLabelColor(ci);" << std::endl;
126 } else
127 out<<" "<<name<<subname<<"->SetLabelColor("<<fLabelColor<<");"<<std::endl;
128 }
129 if (fLabelFont != 62) {
130 out<<" "<<name<<subname<<"->SetLabelFont("<<fLabelFont<<");"<<std::endl;
131 }
132 if (TMath::Abs(fLabelOffset-0.005) > 0.0001) {
133 out<<" "<<name<<subname<<"->SetLabelOffset("<<fLabelOffset<<");"<<std::endl;
134 }
135 if (TMath::Abs(fLabelSize-0.035) > 0.001) {
136 out<<" "<<name<<subname<<"->SetLabelSize("<<fLabelSize<<");"<<std::endl;
137 }
138 if (TMath::Abs(fTitleSize-0.035) > 0.001) {
139 out<<" "<<name<<subname<<"->SetTitleSize("<<fTitleSize<<");"<<std::endl;
140 }
141 if (TMath::Abs(fTickLength-0.03) > 0.001) {
142 out<<" "<<name<<subname<<"->SetTickLength("<<fTickLength<<");"<<std::endl;
143 }
144 if (TMath::Abs(fTitleOffset) > 0.001) {
145 out<<" "<<name<<subname<<"->SetTitleOffset("<<fTitleOffset<<");"<<std::endl;
146 }
147 if (fTitleColor != 1) {
148 if (fTitleColor > 228) {
150 out<<" "<<name<<subname<<"->SetTitleColor(ci);" << std::endl;
151 } else
152 out<<" "<<name<<subname<<"->SetTitleColor("<<fTitleColor<<");"<<std::endl;
153 }
154 if (fTitleFont != 62) {
155 out<<" "<<name<<subname<<"->SetTitleFont("<<fTitleFont<<");"<<std::endl;
156 }
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// Set color of the line axis and tick marks.
161
163{
164 if (alpha<1.) fAxisColor = TColor::GetColorTransparent(color, alpha);
165 else fAxisColor = color;
166 if (gPad) gPad->Modified();
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Set color of labels.
171
173{
174 if (alpha<1.) fLabelColor = TColor::GetColorTransparent(color, alpha);
175 else fLabelColor = color;
176 if (gPad) gPad->Modified();
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Set labels' font.
181
183{
184 fLabelFont = font;
185 if (gPad) gPad->Modified();
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Set distance between the axis and the labels.
190/// The distance is expressed in per cent of the pad width.
191
193{
194 fLabelOffset = offset;
195 if (gPad) gPad->Modified();
196}
197
198
199////////////////////////////////////////////////////////////////////////////////
200/// Set size of axis labels.
201/// The size is expressed in per cent of the pad size.
202
204{
205 fLabelSize = size;
206 if (gPad) gPad->Modified();
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Set the number of divisions for this axis.
211///
212/// - if optim = kTRUE (default), the number of divisions will be
213/// optimized around the specified value.
214/// - if optim = kFALSE, or n < 0, the axis will be forced to use
215/// exactly n divisions.
216///~~~ {.cpp}
217/// n = n1 + 100*n2 + 10000*n3
218///~~~
219/// Where n1 is the number of primary divisions,
220/// n2 is the number of second order divisions and
221/// n3 is the number of third order divisions.
222///
223/// e.g. 512 means 12 primary and 5 secondary divisions.
224///
225/// If the number of divisions is "optimized" (see above) n1, n2, n3 are
226/// maximum values.
227
229{
230 Int_t ndiv = (n%1000000);
231 Bool_t isOptimized = optim && (ndiv>0);
232 Int_t current_maxDigits = abs(fNdivisions)/1000000;
233 fNdivisions = abs(ndiv) + current_maxDigits*1000000;
234 if (!isOptimized) fNdivisions = -fNdivisions;
235
236 if (gPad) gPad->Modified();
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Set the number of divisions for this axis using one `int` per division level.
241
243{
244 SetNdivisions(n1+100*n2+10000*n3, optim);
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// This function sets the maximum number of digits permitted for the axis labels
249/// above which the notation with 10^N is used.
250///
251/// For example, to accept 6 digits number like 900000 on the X axis of the
252/// histogram `h` call:
253///
254/// ~~~ {.cpp}
255/// h->GetXaxis()->SetMaxDigits(6);
256/// ~~~
257///
258/// The default value is 5.
259///
260/// The default value for all axis can be set with the static function
261/// `TGaxis::SetMaxDigits`.
262
264{
265 Bool_t isOptimized = fNdivisions>0;
266 Int_t absDiv = abs(fNdivisions);
267 Int_t current_maxDigits = absDiv/1000000;
268 Int_t current_Ndivisions = absDiv - (current_maxDigits*1000000);
269 fNdivisions = (current_Ndivisions + (maxDigits*1000000));
270 if (!isOptimized) fNdivisions = -fNdivisions;
271
272 if (gPad) gPad->Modified();
273}
274
275////////////////////////////////////////////////////////////////////////////////
276/// Set tick mark length.
277/// The length is expressed in per cent of the pad width.
278
280{
281 fTickLength = length;
282 if (gPad) gPad->Modified();
283}
284
285////////////////////////////////////////////////////////////////////////////////
286/// Set distance between the axis and the axis title.
287/// Offset is a correction factor with respect to the "standard" value.
288/// - offset = 1 uses standard position that is computed in function
289/// of the label offset and size.
290/// - offset = 1.2 will add 20 per cent more to the standard offset.
291/// - offset = 0 automatic placement for the Y axis title (default).
292
294{
295 fTitleOffset = offset;
296 if (gPad) gPad->Modified();
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Set size of axis title.
301/// The size is expressed in per cent of the pad width
302
304{
305 fTitleSize = size;
306 if (gPad) gPad->Modified();
307}
308
309////////////////////////////////////////////////////////////////////////////////
310/// Set color of axis title.
311
313{
314 fTitleColor = color;
315 if (gPad) gPad->Modified();
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Set the title font.
320
322{
323 fTitleFont = font;
324 if (gPad) gPad->Modified();
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Stream an object of class TAttAxis.
329
330void TAttAxis::Streamer(TBuffer &R__b)
331{
332 if (R__b.IsReading()) {
333 UInt_t R__s, R__c;
334 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
335 if (R__v > 3) {
336 R__b.ReadClassBuffer(TAttAxis::Class(), this, R__v, R__s, R__c);
337 return;
338 }
339 //====process old versions before automatic schema evolution
340 R__b >> fNdivisions;
341 R__b >> fAxisColor;
342 R__b >> fLabelColor;
343 R__b >> fLabelFont;
344 R__b >> fLabelOffset;
345 R__b >> fLabelSize;
346 R__b >> fTickLength;
347 R__b >> fTitleOffset;
348
349 if (R__v > 1 && R__b.GetVersionOwner() > 900)
350 R__b >> fTitleSize;
351 else
353 if (R__v > 2) {
354 R__b >> fTitleColor;
355 R__b >> fTitleFont;
356 }
357 //====end of old versions
358
359 } else {
360 R__b.WriteClassBuffer(TAttAxis::Class(),this);
361 }
362}
short Version_t
Definition RtypesCore.h:65
unsigned int UInt_t
Definition RtypesCore.h:46
short Color_t
Definition RtypesCore.h:83
short Style_t
Definition RtypesCore.h:80
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
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
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:293
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:162
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:203
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:321
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
Definition TAttAxis.cxx:192
Float_t fTickLength
Length of tick marks.
Definition TAttAxis.h:26
virtual void SetLabelFont(Style_t font=62)
Set labels' font.
Definition TAttAxis.cxx:182
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title.
Definition TAttAxis.cxx:303
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:110
virtual void SetTitleColor(Color_t color=1)
Set color of axis title.
Definition TAttAxis.cxx:312
Float_t fLabelSize
Size of labels.
Definition TAttAxis.h:25
virtual ~TAttAxis()
Destructor.
Definition TAttAxis.cxx:53
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:263
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:78
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:279
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition TAttAxis.cxx:228
void Copy(TAttAxis &attaxis) const
Copy of the object.
Definition TAttAxis.cxx:60
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:172
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:2121
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:1979
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