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{
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, unless the font precision
204/// is 3 and in that case the size is expressed in pixels.
205
207{
209 if (gPad) gPad->Modified();
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Set the number of divisions for this axis.
214///
215/// - if optim = kTRUE (default), the number of divisions will be
216/// optimized around the specified value.
217/// - if optim = kFALSE, or n < 0, the axis will be forced to use
218/// exactly n divisions.
219///~~~ {.cpp}
220/// n = n1 + 100*n2 + 10000*n3
221///~~~
222/// Where n1 is the number of primary divisions,
223/// n2 is the number of second order divisions and
224/// n3 is the number of third order divisions.
225///
226/// If the number of divisions is "optimized" (see above) n1, n2, n3 are
227/// maximum values.
228///
229/// Examples:
230///
231/// - ndiv = 0: no tick marks.
232/// - ndiv = 2: 2 divisions, one tick mark in the middle of the axis.
233/// - ndiv = 510: 10 primary divisions, 5 secondary divisions.
234/// - ndiv = -10: exactly 10 primary divisions.
235
237{
238 Int_t ndiv = (n%1000000);
239 Bool_t isOptimized = optim && (ndiv>0);
240 Int_t current_maxDigits = abs(fNdivisions)/1000000;
241 fNdivisions = abs(ndiv) + current_maxDigits*1000000;
242 if (!isOptimized) fNdivisions = -fNdivisions;
243
244 if (gPad) gPad->Modified();
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Set the number of divisions for this axis using one `int` per division level.
249
251{
252 SetNdivisions(n1+100*n2+10000*n3, optim);
253}
254
255////////////////////////////////////////////////////////////////////////////////
256/// This function sets the maximum number of digits permitted for the axis labels
257/// above which the notation with 10^N is used.
258///
259/// For example, to accept 6 digits number like 900000 on the X axis of the
260/// histogram `h` call:
261///
262/// ~~~ {.cpp}
263/// h->GetXaxis()->SetMaxDigits(6);
264/// ~~~
265///
266/// The default value is 5.
267///
268/// The default value for all axis can be set with the static function
269/// `TGaxis::SetMaxDigits`.
270
272{
273 Bool_t isOptimized = fNdivisions>0;
274 Int_t absDiv = abs(fNdivisions);
275 Int_t current_maxDigits = absDiv/1000000;
276 Int_t current_Ndivisions = absDiv - (current_maxDigits*1000000);
277 fNdivisions = (current_Ndivisions + (maxDigits*1000000));
278 if (!isOptimized) fNdivisions = -fNdivisions;
279
280 if (gPad) gPad->Modified();
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Set tick mark length.
285/// The length is expressed in per cent of the pad width.
286
288{
290 if (gPad) gPad->Modified();
291}
292
293////////////////////////////////////////////////////////////////////////////////
294/// Set distance between the axis and the axis title.
295/// Offset is a correction factor with respect to the "standard" value.
296/// - offset = 1 uses standard position that is computed in function
297/// of the label offset and size.
298/// - offset = 1.2 will add 20 per cent more to the standard offset.
299/// - offset = 0 automatic placement for the Y axis title (default).
300
302{
304 if (gPad) gPad->Modified();
305}
306
307////////////////////////////////////////////////////////////////////////////////
308/// Set size of axis title.
309/// The size is expressed in per cent of the pad size, unless the font precision
310/// is 3 and in that case the size is expressed in pixels.
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
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}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Style_t
Definition: RtypesCore.h:89
short Color_t
Definition: RtypesCore.h:92
short Version_t
Definition: RtypesCore.h:65
float Float_t
Definition: RtypesCore.h:57
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:375
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
char name[80]
Definition: TGX11.cxx:110
R__EXTERN TStyle * gStyle
Definition: TStyle.h:414
#define gPad
Definition: TVirtualPad.h:288
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:301
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:206
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
static TClass * Class()
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
virtual void Streamer(TBuffer &)
Stream an object of class TAttAxis.
Definition: TAttAxis.cxx:339
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:271
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:287
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:236
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:2186
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:2033
Color_t GetLabelColor(Option_t *axis="X") const
Return the label color number in the axis.
Definition: TStyle.cxx:1065
Int_t GetNdivisions(Option_t *axis="X") const
Return number of divisions.
Definition: TStyle.cxx:1033
Color_t GetTitleColor(Option_t *axis="X") const
Return title color.
Definition: TStyle.cxx:1153
Float_t GetLabelSize(Option_t *axis="X") const
Return label size.
Definition: TStyle.cxx:1101
Float_t GetTickLength(Option_t *axis="X") const
Return tick length.
Definition: TStyle.cxx:1141
Float_t GetTitleSize(Option_t *axis="X") const
Return title size.
Definition: TStyle.cxx:1189
Style_t GetLabelFont(Option_t *axis="X") const
Return label font.
Definition: TStyle.cxx:1077
Float_t GetTitleOffset(Option_t *axis="X") const
Return title offset.
Definition: TStyle.cxx:1177
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition: TStyle.cxx:1165
Float_t GetLabelOffset(Option_t *axis="X") const
Return label offset.
Definition: TStyle.cxx:1089
Color_t GetAxisColor(Option_t *axis="X") const
Return the axis color number in the axis.
Definition: TStyle.cxx:1045
RVec< PromoteType< T > > abs(const RVec< T > &v)
Definition: RVec.hxx:1739
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:123