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: 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
57
58////////////////////////////////////////////////////////////////////////////////
59/// Copy of the object.
60
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
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 TString prefix = TString(" ") + name + subname + "->";
114
115 if (fNdivisions != 510)
116 out << prefix << "SetNdivisions(" << fNdivisions << ");\n";
117 if (fAxisColor != 1)
118 out << prefix << "SetAxisColor(" << TColor::SavePrimitiveColor(fAxisColor) << ");\n";
119 if (fLabelColor != 1)
120 out << prefix << "SetLabelColor(" << TColor::SavePrimitiveColor(fLabelColor) << ");\n";
121 if (fLabelFont != 62)
122 out << prefix << "SetLabelFont(" << fLabelFont << ");\n";
123 if (TMath::Abs(fLabelOffset - 0.005) > 0.0001)
124 out << prefix << "SetLabelOffset(" << fLabelOffset << ");\n";
125 if (TMath::Abs(fLabelSize - 0.035) > 0.001)
126 out << prefix << "SetLabelSize(" << fLabelSize << ");\n";
127 if (TMath::Abs(fTitleSize - 0.035) > 0.001)
128 out << prefix << "SetTitleSize(" << fTitleSize << ");\n";
129 if (TMath::Abs(fTickLength - 0.03) > 0.001)
130 out << prefix << "SetTickLength(" << fTickLength << ");\n";
131 if (TMath::Abs(fTitleOffset) > 0.001)
132 out << prefix << "SetTitleOffset(" << fTitleOffset << ");\n";
133 if (fTitleColor != 1)
134 out << prefix << "SetTitleColor(" << TColor::SavePrimitiveColor(fTitleColor) << ");\n";
135 if (fTitleFont != 62)
136 out << prefix << "SetTitleFont(" << fTitleFont << ");\n";
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Set color of the line axis and tick marks.
141
143{
144 if (alpha<1.) fAxisColor = TColor::GetColorTransparent(color, alpha);
145 else fAxisColor = color;
146 if (gPad) gPad->Modified();
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Set color of labels.
151
153{
154 if (alpha<1.) fLabelColor = TColor::GetColorTransparent(color, alpha);
155 else fLabelColor = color;
156 if (gPad) gPad->Modified();
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// Set labels' font.
161
163{
164 fLabelFont = font;
165 if (gPad) gPad->Modified();
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Set distance between the axis and the labels.
170/// The distance is expressed in per cent of the pad width.
171/// A negative value allow to draw the label on the other side of the axis.
172
174{
176 if (gPad) gPad->Modified();
177}
178
179
180////////////////////////////////////////////////////////////////////////////////
181/// Set size of axis labels.
182/// The size is expressed in per cent of the pad size, unless the font precision
183/// is 3 and in that case the size is expressed in pixels.
184
186{
188 if (gPad) gPad->Modified();
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// Set the number of divisions for this axis.
193///
194/// - if optim = kTRUE (default), the number of divisions will be
195/// optimized around the specified value.
196/// - if optim = kFALSE, or n < 0, the axis will be forced to use
197/// exactly n divisions.
198///~~~ {.cpp}
199/// n = n1 + 100*n2 + 10000*n3
200///~~~
201/// Where n1 is the number of primary divisions,
202/// n2 is the number of second order divisions and
203/// n3 is the number of third order divisions.
204///
205/// If the number of divisions is "optimized" (see above) n1, n2, n3 are
206/// maximum values.
207///
208/// Examples:
209///
210/// - ndiv = 0: no tick marks.
211/// - ndiv = 2: 2 divisions, one tick mark in the middle of the axis.
212/// - ndiv = 510: 10 primary divisions, 5 secondary divisions.
213/// - ndiv = -10: exactly 10 primary divisions.
214
216{
217 Int_t ndiv = (n%1000000);
218 Bool_t isOptimized = optim && (ndiv>0);
219 Int_t current_maxDigits = abs(fNdivisions)/1000000;
220 fNdivisions = abs(ndiv) + current_maxDigits*1000000;
222
223 if (gPad) gPad->Modified();
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Set the number of divisions for this axis using one `int` per division level.
228
233
234////////////////////////////////////////////////////////////////////////////////
235/// This function sets the maximum number of digits permitted for the axis labels
236/// above which the notation with 10^N is used.
237///
238/// For example, to accept 6 digits number like 900000 on the X axis of the
239/// histogram `h` call:
240///
241/// ~~~ {.cpp}
242/// h->GetXaxis()->SetMaxDigits(6);
243/// ~~~
244///
245/// The default value is 5.
246///
247/// The default value for all axis can be set with the static function
248/// `TGaxis::SetMaxDigits`.
249
261
262////////////////////////////////////////////////////////////////////////////////
263/// Set tick mark length.
264/// The length is expressed in per cent of the pad width.
265
267{
269 if (gPad) gPad->Modified();
270}
271
272////////////////////////////////////////////////////////////////////////////////
273/// Set distance between the axis and the axis title.
274/// Offset is a correction factor with respect to the "standard" value.
275/// - offset = 1 uses standard position that is computed in function
276/// of the label offset and size.
277/// - offset = 1.2 will add 20 per cent more to the standard offset.
278/// - offset = 0 automatic placement for the Y axis title (default).
279
281{
283 if (gPad) gPad->Modified();
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// Set size of axis title.
288/// The size is expressed in per cent of the pad size, unless the font precision
289/// is 3 and in that case the size is expressed in pixels.
290
292{
294 if (gPad) gPad->Modified();
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// Set color of axis title.
299
301{
302 fTitleColor = color;
303 if (gPad) gPad->Modified();
304}
305
306////////////////////////////////////////////////////////////////////////////////
307/// Set the title font.
308
310{
311 fTitleFont = font;
312 if (gPad) gPad->Modified();
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// Stream an object of class TAttAxis.
317
319{
320 if (R__b.IsReading()) {
322 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
323 if (R__v > 3) {
324 R__b.ReadClassBuffer(TAttAxis::Class(), this, R__v, R__s, R__c);
325 return;
326 }
327 //====process old versions before automatic schema evolution
328 R__b >> fNdivisions;
329 R__b >> fAxisColor;
330 R__b >> fLabelColor;
331 R__b >> fLabelFont;
333 R__b >> fLabelSize;
334 R__b >> fTickLength;
336
337 if (R__v > 1 && R__b.GetVersionOwner() > 900)
338 R__b >> fTitleSize;
339 else
341 if (R__v > 2) {
342 R__b >> fTitleColor;
343 R__b >> fTitleFont;
344 }
345 //====end of old versions
346
347 } else {
348 R__b.WriteClassBuffer(TAttAxis::Class(),this);
349 }
350}
351
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Style_t
Definition RtypesCore.h:82
short Color_t
Definition RtypesCore.h:85
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:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:442
#define gPad
Manages histogram axis attributes.
Definition TAttAxis.h:19
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:280
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:142
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:185
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:309
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
Definition TAttAxis.cxx:173
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:162
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title.
Definition TAttAxis.cxx:291
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:300
virtual void Streamer(TBuffer &)
Stream an object of class TAttAxis.
Definition TAttAxis.cxx:318
Float_t fLabelSize
Size of labels.
Definition TAttAxis.h:26
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:250
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:79
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:266
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition TAttAxis.cxx:215
void Copy(TAttAxis &attaxis) const
Copy of the object.
Definition TAttAxis.cxx:61
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:152
Buffer base class used for serializing objects.
Definition TBuffer.h:43
static TString SavePrimitiveColor(Int_t ci)
Convert color in C++ statement which can be used in SetColor directives Produced statement either inc...
Definition TColor.cxx:2557
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2183
Basic string class.
Definition TString.h:139
Color_t GetLabelColor(Option_t *axis="X") const
Return the label color number in the axis.
Definition TStyle.cxx:1111
Int_t GetNdivisions(Option_t *axis="X") const
Return number of divisions.
Definition TStyle.cxx:1079
Color_t GetTitleColor(Option_t *axis="X") const
Return title color.
Definition TStyle.cxx:1206
Float_t GetLabelSize(Option_t *axis="X") const
Return label size.
Definition TStyle.cxx:1147
Float_t GetTickLength(Option_t *axis="X") const
Return tick length.
Definition TStyle.cxx:1194
Float_t GetTitleSize(Option_t *axis="X") const
Return title size.
Definition TStyle.cxx:1242
Style_t GetLabelFont(Option_t *axis="X") const
Return label font.
Definition TStyle.cxx:1123
Float_t GetTitleOffset(Option_t *axis="X") const
Return title offset.
Definition TStyle.cxx:1230
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition TStyle.cxx:1218
Float_t GetLabelOffset(Option_t *axis="X") const
Return label offset.
Definition TStyle.cxx:1135
Color_t GetAxisColor(Option_t *axis="X") const
Return the axis color number in the axis.
Definition TStyle.cxx:1091
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