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
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
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{
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;
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
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
260
261////////////////////////////////////////////////////////////////////////////////
262/// Set tick mark length.
263/// The length is expressed in per cent of the pad width.
264
266{
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{
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()) {
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;
332 R__b >> fLabelSize;
333 R__b >> fTickLength;
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 {
347 R__b.WriteClassBuffer(TAttAxis::Class(),this);
348 }
349}
350
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Style_t
Style number (short)
Definition RtypesCore.h:96
short Color_t
Color number (short)
Definition RtypesCore.h:99
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
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: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
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:2556
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2182
Basic string class.
Definition TString.h:138
Color_t GetLabelColor(Option_t *axis="X") const
Return the label color number in the axis.
Definition TStyle.cxx:1110
Int_t GetNdivisions(Option_t *axis="X") const
Return number of divisions.
Definition TStyle.cxx:1078
Color_t GetTitleColor(Option_t *axis="X") const
Return title color.
Definition TStyle.cxx:1205
Float_t GetLabelSize(Option_t *axis="X") const
Return label size.
Definition TStyle.cxx:1146
Float_t GetTickLength(Option_t *axis="X") const
Return tick length.
Definition TStyle.cxx:1193
Float_t GetTitleSize(Option_t *axis="X") const
Return title size.
Definition TStyle.cxx:1241
Style_t GetLabelFont(Option_t *axis="X") const
Return label font.
Definition TStyle.cxx:1122
Float_t GetTitleOffset(Option_t *axis="X") const
Return title offset.
Definition TStyle.cxx:1229
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition TStyle.cxx:1217
Float_t GetLabelOffset(Option_t *axis="X") const
Return label offset.
Definition TStyle.cxx:1134
Color_t GetAxisColor(Option_t *axis="X") const
Return the axis color number in the axis.
Definition TStyle.cxx:1090
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:124