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
21
22/** \class TAttAxis
23\ingroup Base
24\ingroup GraphicsAtt
25
26Manages histogram axis attributes.
27
28They are:
29
30 - The number of divisions: TAttAxis::SetNdivisions.
31 - The line axis' color: TAttAxis::SetAxisColor.
32 - The axis labels' color: TAttAxis::SetLabelColor.
33 - The axis labels' font: TAttAxis::SetLabelFont.
34 - The axis labels' offset: TAttAxis::SetLabelOffset.
35 - The axis labels' size: TAttAxis::SetLabelSize.
36 - The tick marks's length: TAttAxis::SetTickLength or TAttAxis::SetTickSize .
37 - The axis title's offset: TAttAxis::SetTitleOffset.
38 - The axis title's size: TAttAxis::SetTitleSize.
39 - The axis title's color: TAttAxis::SetTitleColor.
40 - The axis title's font: TAttAxis::SetTitleFont.
41
42*/
43
45{
46 // Constructor.
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Destructor.
52
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) {
81 fNdivisions = gStyle->GetNdivisions(option);
82 fAxisColor = gStyle->GetAxisColor(option);
83 fLabelColor = gStyle->GetLabelColor(option);
84 fLabelFont = gStyle->GetLabelFont(option);
85 fLabelOffset = gStyle->GetLabelOffset(option);
86 fLabelSize = gStyle->GetLabelSize(option);
87 fTickLength = gStyle->GetTickLength(option);
88 fTitleOffset = gStyle->GetTitleOffset(option);
89 fTitleSize = gStyle->GetTitleSize(option);
90 fTitleColor = gStyle->GetTitleColor(option);
91 fTitleFont = gStyle->GetTitleFont(option);
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 TString prefix = TString(" ") + name + subname + "->";
113
114 if (fNdivisions != 510)
115 out << prefix << "SetNdivisions(" << fNdivisions << ");\n";
116 if (fAxisColor != 1)
117 out << prefix << "SetAxisColor(" << TColor::SavePrimitiveColor(fAxisColor) << ");\n";
118 if (fLabelColor != 1)
119 out << prefix << "SetLabelColor(" << TColor::SavePrimitiveColor(fLabelColor) << ");\n";
120 if (fLabelFont != 62)
121 out << prefix << "SetLabelFont(" << fLabelFont << ");\n";
122 if (TMath::Abs(fLabelOffset - 0.005) > 0.0001)
123 out << prefix << "SetLabelOffset(" << fLabelOffset << ");\n";
124 if (TMath::Abs(fLabelSize - 0.035) > 0.001)
125 out << prefix << "SetLabelSize(" << fLabelSize << ");\n";
126 if (TMath::Abs(fTitleSize - 0.035) > 0.001)
127 out << prefix << "SetTitleSize(" << fTitleSize << ");\n";
128 if (TMath::Abs(fTickLength - 0.03) > 0.001)
129 out << prefix << "SetTickLength(" << fTickLength << ");\n";
130 if (TMath::Abs(fTitleOffset) > 0.001)
131 out << prefix << "SetTitleOffset(" << fTitleOffset << ");\n";
132 if (fTitleColor != 1)
133 out << prefix << "SetTitleColor(" << TColor::SavePrimitiveColor(fTitleColor) << ");\n";
134 if (fTitleFont != 62)
135 out << prefix << "SetTitleFont(" << fTitleFont << ");\n";
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Set color of the line axis and tick marks.
140
142{
143 if (alpha<1.) fAxisColor = TColor::GetColorTransparent(color, alpha);
144 else fAxisColor = color;
145 if (gPad) gPad->Modified();
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Set color of labels.
150
152{
153 if (alpha<1.) fLabelColor = TColor::GetColorTransparent(color, alpha);
154 else fLabelColor = color;
155 if (gPad) gPad->Modified();
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Set labels' font.
160
162{
163 fLabelFont = font;
164 if (gPad) gPad->Modified();
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Set distance between the axis and the labels.
169/// The distance is expressed in per cent of the pad width.
170/// A negative value allow to draw the label on the other side of the axis.
171
173{
174 fLabelOffset = offset;
175 if (gPad) gPad->Modified();
176}
177
178
179////////////////////////////////////////////////////////////////////////////////
180/// Set size of axis labels.
181/// The size is expressed in per cent of the pad size, unless the font precision
182/// is 3 and in that case the size is expressed in pixels.
183
185{
187 if (gPad) gPad->Modified();
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Set the number of divisions for this axis.
192///
193/// - if optim = kTRUE (default), the number of divisions will be
194/// optimized around the specified value.
195/// - if optim = kFALSE, or n < 0, the axis will be forced to use
196/// exactly n divisions.
197///~~~ {.cpp}
198/// n = n1 + 100*n2 + 10000*n3
199///~~~
200/// Where n1 is the number of primary divisions,
201/// n2 is the number of second order divisions and
202/// n3 is the number of third order divisions.
203///
204/// If the number of divisions is "optimized" (see above) n1, n2, n3 are
205/// maximum values.
206///
207/// Examples:
208///
209/// - ndiv = 0: no tick marks.
210/// - ndiv = 2: 2 divisions, one tick mark in the middle of the axis.
211/// - ndiv = 510: 10 primary divisions, 5 secondary divisions.
212/// - ndiv = -10: exactly 10 primary divisions.
213
215{
216 Int_t ndiv = (n%1000000);
217 Bool_t isOptimized = optim && (ndiv>0);
218 Int_t current_maxDigits = abs(fNdivisions)/1000000;
219 fNdivisions = abs(ndiv) + current_maxDigits*1000000;
220 if (!isOptimized) fNdivisions = -fNdivisions;
221
222 if (gPad) gPad->Modified();
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Set the number of divisions for this axis using one `int` per division level.
227
229{
230 SetNdivisions(n1+100*n2+10000*n3, optim);
231}
232
233////////////////////////////////////////////////////////////////////////////////
234/// This function sets the maximum number of digits permitted for the axis labels
235/// above which the notation with 10^N is used.
236///
237/// For example, to accept 6 digits number like 900000 on the X axis of the
238/// histogram `h` call:
239///
240/// ~~~ {.cpp}
241/// h->GetXaxis()->SetMaxDigits(6);
242/// ~~~
243///
244/// The default value is 5.
245///
246/// The default value for all axis can be set with the static function
247/// `TGaxis::SetMaxDigits`.
248
250{
251 Bool_t isOptimized = fNdivisions>0;
252 Int_t absDiv = abs(fNdivisions);
253 Int_t current_maxDigits = absDiv/1000000;
254 Int_t current_Ndivisions = absDiv - (current_maxDigits*1000000);
255 fNdivisions = (current_Ndivisions + (maxDigits*1000000));
256 if (!isOptimized) fNdivisions = -fNdivisions;
257
258 if (gPad) gPad->Modified();
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// Set tick mark length.
263/// The length is expressed in per cent of the pad width.
264
266{
267 fTickLength = length;
268 if (gPad) gPad->Modified();
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Set distance between the axis and the axis title.
273/// Offset is a correction factor with respect to the "standard" value.
274/// - offset = 1 uses standard position that is computed in function
275/// of the label offset and size.
276/// - offset = 1.2 will add 20 per cent more to the standard offset.
277/// - offset = 0 automatic placement for the Y axis title (default).
278
280{
281 fTitleOffset = offset;
282 if (gPad) gPad->Modified();
283}
284
285////////////////////////////////////////////////////////////////////////////////
286/// Set size of axis title.
287/// The size is expressed in per cent of the pad size, unless the font precision
288/// is 3 and in that case the size is expressed in pixels.
289
291{
293 if (gPad) gPad->Modified();
294}
295
296////////////////////////////////////////////////////////////////////////////////
297/// Set color of axis title.
298
300{
301 fTitleColor = color;
302 if (gPad) gPad->Modified();
303}
304
305////////////////////////////////////////////////////////////////////////////////
306/// Set the title font.
307
309{
310 fTitleFont = font;
311 if (gPad) gPad->Modified();
312}
313
314////////////////////////////////////////////////////////////////////////////////
315/// Stream an object of class TAttAxis.
316
318{
319 if (R__b.IsReading()) {
320 UInt_t R__s, R__c;
321 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
322 if (R__v > 3) {
323 R__b.ReadClassBuffer(TAttAxis::Class(), this, R__v, R__s, R__c);
324 return;
325 }
326 //====process old versions before automatic schema evolution
327 R__b >> fNdivisions;
328 R__b >> fAxisColor;
329 R__b >> fLabelColor;
330 R__b >> fLabelFont;
331 R__b >> fLabelOffset;
332 R__b >> fLabelSize;
333 R__b >> fTickLength;
334 R__b >> fTitleOffset;
335
336 if (R__v > 1 && R__b.GetVersionOwner() > 900)
337 R__b >> fTitleSize;
338 else
340 if (R__v > 2) {
341 R__b >> fTitleColor;
342 R__b >> fTitleFont;
343 }
344 //====end of old versions
345
346 } else {
348 }
349}
350
352{
353 SetLabelColor(lcolor.number());
354}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
short Version_t
Class version identifier (short).
Definition RtypesCore.h:79
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
short Color_t
Color number (short).
Definition RtypesCore.h:99
short Style_t
Style number (short).
Definition RtypesCore.h:96
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
char name[80]
Definition TGX11.cxx:148
externTStyle * gStyle
Definition TStyle.h:442
#define gPad
Color_t fAxisColor
Color of the line axis.
Definition TAttAxis.h:22
Int_t fNdivisions
Number of divisions(10000*n3 + 100*n2 + n1).
Definition TAttAxis.h:21
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:279
Style_t fTitleFont
Font for axis title.
Definition TAttAxis.h:31
virtual void SetAxisColor(Color_t color=1, Float_t alpha=1.)
Set color of the line axis and tick marks.
Definition TAttAxis.cxx:141
Float_t fTitleSize
Size of axis title.
Definition TAttAxis.h:29
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition TAttAxis.cxx:184
Float_t fTitleOffset
Offset of axis title.
Definition TAttAxis.h:28
virtual void SetTitleFont(Style_t font=62)
Set the title font.
Definition TAttAxis.cxx:308
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
Definition TAttAxis.cxx:172
static TClass * Class()
Float_t fTickLength
Length of tick marks.
Definition TAttAxis.h:27
virtual void SetLabelFont(Style_t font=62)
Set labels' font.
Definition TAttAxis.cxx:161
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title.
Definition TAttAxis.cxx:290
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:299
virtual void Streamer(TBuffer &)
Stream an object of class TAttAxis.
Definition TAttAxis.cxx:317
Float_t fLabelSize
Size of labels.
Definition TAttAxis.h:26
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:249
Style_t fLabelFont
Font for labels.
Definition TAttAxis.h:24
Color_t fLabelColor
Color of labels.
Definition TAttAxis.h:23
virtual void ResetAttAxis(Option_t *option="")
Reset axis attributes.
Definition TAttAxis.cxx:78
Color_t fTitleColor
Color of axis title.
Definition TAttAxis.h:30
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length.
Definition TAttAxis.cxx:265
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition TAttAxis.cxx:214
void Copy(TAttAxis &attaxis) const
Copy of the object.
Definition TAttAxis.cxx:60
Float_t fLabelOffset
Offset of labels.
Definition TAttAxis.h:25
virtual void SetLabelColor(Color_t color=1, Float_t alpha=1.)
Set color of labels.
Definition TAttAxis.cxx:151
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=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
Int_t number() const
Definition TColor.h:151
static Int_t GetColorTransparent(Int_t color, Float_t a)
static TString SavePrimitiveColor(Int_t ci)
Basic string class.
Definition TString.h:138
const Int_t n
Definition legend1.C:16
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122