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
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) {
118 out<<" "<<name<<subname<<"->SetAxisColor(ci);" << std::endl;
119 else
120 out<<" "<<name<<subname<<"->SetAxisColor("<<fAxisColor<<");"<<std::endl;
121 }
122 if (fLabelColor != 1) {
124 out<<" "<<name<<subname<<"->SetLabelColor(ci);" << std::endl;
125 else
126 out<<" "<<name<<subname<<"->SetLabelColor("<<fLabelColor<<");"<<std::endl;
127 }
128 if (fLabelFont != 62) {
129 out<<" "<<name<<subname<<"->SetLabelFont("<<fLabelFont<<");"<<std::endl;
130 }
131 if (TMath::Abs(fLabelOffset-0.005) > 0.0001) {
132 out<<" "<<name<<subname<<"->SetLabelOffset("<<fLabelOffset<<");"<<std::endl;
133 }
134 if (TMath::Abs(fLabelSize-0.035) > 0.001) {
135 out<<" "<<name<<subname<<"->SetLabelSize("<<fLabelSize<<");"<<std::endl;
136 }
137 if (TMath::Abs(fTitleSize-0.035) > 0.001) {
138 out<<" "<<name<<subname<<"->SetTitleSize("<<fTitleSize<<");"<<std::endl;
139 }
140 if (TMath::Abs(fTickLength-0.03) > 0.001) {
141 out<<" "<<name<<subname<<"->SetTickLength("<<fTickLength<<");"<<std::endl;
142 }
143 if (TMath::Abs(fTitleOffset) > 0.001) {
144 out<<" "<<name<<subname<<"->SetTitleOffset("<<fTitleOffset<<");"<<std::endl;
145 }
146 if (fTitleColor != 1) {
148 out<<" "<<name<<subname<<"->SetTitleColor(ci);" << std::endl;
149 else
150 out<<" "<<name<<subname<<"->SetTitleColor("<<fTitleColor<<");"<<std::endl;
151 }
152 if (fTitleFont != 62) {
153 out<<" "<<name<<subname<<"->SetTitleFont("<<fTitleFont<<");"<<std::endl;
154 }
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// Set color of the line axis and tick marks.
159
161{
162 if (alpha<1.) fAxisColor = TColor::GetColorTransparent(color, alpha);
163 else fAxisColor = color;
164 if (gPad) gPad->Modified();
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Set color of labels.
169
171{
172 if (alpha<1.) fLabelColor = TColor::GetColorTransparent(color, alpha);
173 else fLabelColor = color;
174 if (gPad) gPad->Modified();
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Set labels' font.
179
181{
182 fLabelFont = font;
183 if (gPad) gPad->Modified();
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Set distance between the axis and the labels.
188/// The distance is expressed in per cent of the pad width.
189/// A negative value allow to draw the label on the other side of the axis.
190
192{
194 if (gPad) gPad->Modified();
195}
196
197
198////////////////////////////////////////////////////////////////////////////////
199/// Set size of axis labels.
200/// The size is expressed in per cent of the pad size, unless the font precision
201/// is 3 and in that case the size is expressed in pixels.
202
204{
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/// If the number of divisions is "optimized" (see above) n1, n2, n3 are
224/// maximum values.
225///
226/// Examples:
227///
228/// - ndiv = 0: no tick marks.
229/// - ndiv = 2: 2 divisions, one tick mark in the middle of the axis.
230/// - ndiv = 510: 10 primary divisions, 5 secondary divisions.
231/// - ndiv = -10: exactly 10 primary divisions.
232
234{
235 Int_t ndiv = (n%1000000);
236 Bool_t isOptimized = optim && (ndiv>0);
237 Int_t current_maxDigits = abs(fNdivisions)/1000000;
238 fNdivisions = abs(ndiv) + current_maxDigits*1000000;
239 if (!isOptimized) fNdivisions = -fNdivisions;
240
241 if (gPad) gPad->Modified();
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// Set the number of divisions for this axis using one `int` per division level.
246
248{
249 SetNdivisions(n1+100*n2+10000*n3, optim);
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// This function sets the maximum number of digits permitted for the axis labels
254/// above which the notation with 10^N is used.
255///
256/// For example, to accept 6 digits number like 900000 on the X axis of the
257/// histogram `h` call:
258///
259/// ~~~ {.cpp}
260/// h->GetXaxis()->SetMaxDigits(6);
261/// ~~~
262///
263/// The default value is 5.
264///
265/// The default value for all axis can be set with the static function
266/// `TGaxis::SetMaxDigits`.
267
269{
270 Bool_t isOptimized = fNdivisions>0;
271 Int_t absDiv = abs(fNdivisions);
272 Int_t current_maxDigits = absDiv/1000000;
273 Int_t current_Ndivisions = absDiv - (current_maxDigits*1000000);
274 fNdivisions = (current_Ndivisions + (maxDigits*1000000));
275 if (!isOptimized) fNdivisions = -fNdivisions;
276
277 if (gPad) gPad->Modified();
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Set tick mark length.
282/// The length is expressed in per cent of the pad width.
283
285{
287 if (gPad) gPad->Modified();
288}
289
290////////////////////////////////////////////////////////////////////////////////
291/// Set distance between the axis and the axis title.
292/// Offset is a correction factor with respect to the "standard" value.
293/// - offset = 1 uses standard position that is computed in function
294/// of the label offset and size.
295/// - offset = 1.2 will add 20 per cent more to the standard offset.
296/// - offset = 0 automatic placement for the Y axis title (default).
297
299{
301 if (gPad) gPad->Modified();
302}
303
304////////////////////////////////////////////////////////////////////////////////
305/// Set size of axis title.
306/// The size is expressed in per cent of the pad size, unless the font precision
307/// is 3 and in that case the size is expressed in pixels.
308
310{
312 if (gPad) gPad->Modified();
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// Set color of axis title.
317
319{
320 fTitleColor = color;
321 if (gPad) gPad->Modified();
322}
323
324////////////////////////////////////////////////////////////////////////////////
325/// Set the title font.
326
328{
329 fTitleFont = font;
330 if (gPad) gPad->Modified();
331}
332
333////////////////////////////////////////////////////////////////////////////////
334/// Stream an object of class TAttAxis.
335
337{
338 if (R__b.IsReading()) {
339 UInt_t R__s, R__c;
340 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
341 if (R__v > 3) {
342 R__b.ReadClassBuffer(TAttAxis::Class(), this, R__v, R__s, R__c);
343 return;
344 }
345 //====process old versions before automatic schema evolution
346 R__b >> fNdivisions;
347 R__b >> fAxisColor;
348 R__b >> fLabelColor;
349 R__b >> fLabelFont;
350 R__b >> fLabelOffset;
351 R__b >> fLabelSize;
352 R__b >> fTickLength;
353 R__b >> fTitleOffset;
354
355 if (R__v > 1 && R__b.GetVersionOwner() > 900)
356 R__b >> fTitleSize;
357 else
359 if (R__v > 2) {
360 R__b >> fTitleColor;
361 R__b >> fTitleFont;
362 }
363 //====end of old versions
364
365 } else {
367 }
368}
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:377
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:433
#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:298
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:160
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:327
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
Definition TAttAxis.cxx:191
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:180
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title.
Definition TAttAxis.cxx:309
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:318
virtual void Streamer(TBuffer &)
Stream an object of class TAttAxis.
Definition TAttAxis.cxx:336
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:268
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:284
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition TAttAxis.cxx:233
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:170
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
static Bool_t 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:2362
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2056
Color_t GetLabelColor(Option_t *axis="X") const
Return the label color number in the axis.
Definition TStyle.cxx:1105
Int_t GetNdivisions(Option_t *axis="X") const
Return number of divisions.
Definition TStyle.cxx:1073
Color_t GetTitleColor(Option_t *axis="X") const
Return title color.
Definition TStyle.cxx:1200
Float_t GetLabelSize(Option_t *axis="X") const
Return label size.
Definition TStyle.cxx:1141
Float_t GetTickLength(Option_t *axis="X") const
Return tick length.
Definition TStyle.cxx:1188
Float_t GetTitleSize(Option_t *axis="X") const
Return title size.
Definition TStyle.cxx:1236
Style_t GetLabelFont(Option_t *axis="X") const
Return label font.
Definition TStyle.cxx:1117
Float_t GetTitleOffset(Option_t *axis="X") const
Return title offset.
Definition TStyle.cxx:1224
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition TStyle.cxx:1212
Float_t GetLabelOffset(Option_t *axis="X") const
Return label offset.
Definition TStyle.cxx:1129
Color_t GetAxisColor(Option_t *axis="X") const
Return the axis color number in the axis.
Definition TStyle.cxx:1085
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