Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TAxis.h
Go to the documentation of this file.
1// @(#)root/hist:$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#ifndef ROOT_TAxis
13#define ROOT_TAxis
14
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TAxis //
19// //
20// Axis class. //
21// //
22//////////////////////////////////////////////////////////////////////////
23
24#include "TNamed.h"
25#include "TAttAxis.h"
26#include "TArrayD.h"
27#include <vector>
28
29class THashList;
30class TAxisModLab;
31
32class TAxis : public TNamed, public TAttAxis {
33
34private:
35 Int_t fNbins; ///< Number of bins
36 Double_t fXmin; ///< Low edge of first bin
37 Double_t fXmax; ///< Upper edge of last bin
38 TArrayD fXbins; ///< Bin edges array in X
39 Int_t fFirst; ///< First bin to display
40 Int_t fLast; ///< Last bin to display
41 UShort_t fBits2; ///< Second bit status word
42 Bool_t fTimeDisplay; ///< On/off displaying time values instead of numerics
43 TString fTimeFormat; ///< Date&time format, ex: 09/12/99 12:34:00
44 TObject *fParent = nullptr; ///<! Object owning this axis
45 THashList *fLabels = nullptr; ///< List of labels
46 TList *fModLabs = nullptr; ///< List of modified labels
47
48 /// TAxis extra status bits (stored in fBits2)
49 enum {
50 kAlphanumeric = BIT(0), ///< Axis is alphanumeric
51 kCanExtend = BIT(1), ///< Axis can be extended
52 kNotAlpha = BIT(2) ///< Axis is forced to be not alphanumeric
53 };
54
56
57
58 TAxisModLab *FindModLab(Int_t num, Double_t v = 0., Double_t eps = 0.) const;
59
60public:
61 /// TAxis status bits
68 kCenterLabels = BIT(14), ///< Bit 13 is used by TObject
78 };
79
80 TAxis();
82 TAxis(Int_t nbins, const Double_t *xbins);
83 TAxis(std::vector<double> const &bins);
84 TAxis(const TAxis &axis);
85 ~TAxis() override;
86 TAxis& operator=(const TAxis&);
87
88 Bool_t CanExtend() const { return (fBits2 & kCanExtend); }
91 void SetAlphanumeric(Bool_t alphanumeric = kTRUE);
92 void SetCanExtend(Bool_t canExtend) { fBits2 = canExtend ? (fBits2 | kCanExtend) : (fBits2 & ~kCanExtend); }
93 void SetNoAlphanumeric(Bool_t noalpha = kTRUE) {
94 fBits2 = noalpha ? (fBits2 | kNotAlpha) : (fBits2 & ~kNotAlpha);
95 if (IsAlphanumeric() ) {
98 }
99 }
100 void CenterLabels(Bool_t center=kTRUE);
101 void CenterTitle(Bool_t center=kTRUE);
102 const char *ChooseTimeFormat(Double_t axislength=0);
103 void Copy(TObject &axis) const override;
104 void Delete(Option_t * /*option*/ ="") override { }
105 Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
106 TObject *DrawClone(Option_t * /*option*/ ="") const override {return nullptr;}
107 void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
108 virtual Int_t FindBin(Double_t x);
109 virtual Int_t FindBin(Double_t x) const { return FindFixBin(x); }
110 virtual Int_t FindBin(const char *label);
111 virtual Int_t FindFixBin(Double_t x) const;
112 virtual Int_t FindFixBin(const char *label) const;
113 virtual Double_t GetBinCenter(Int_t bin) const;
114 virtual Double_t GetBinCenterLog(Int_t bin) const;
115 const char *GetBinLabel(Int_t bin) const;
116 virtual Double_t GetBinLowEdge(Int_t bin) const;
117 virtual Double_t GetBinUpEdge(Int_t bin) const;
118 virtual Double_t GetBinWidth(Int_t bin) const;
119 virtual void GetCenter(Double_t *center) const;
122 Bool_t GetDecimals() const { return TestBit(kDecimals); }
123 THashList *GetLabels() const { return fLabels; }
124 TList *GetModifiedLabels() const { return fModLabs; }
125 virtual void GetLowEdge(Double_t *edge) const;
127 Int_t GetNbins() const { return fNbins; }
128 Int_t GetNlabels() const;
130 virtual TObject *GetParent() const {return fParent;}
132 virtual const char *GetTicks() const;
133 virtual Bool_t GetTimeDisplay() const {return fTimeDisplay;}
134 virtual const char *GetTimeFormat() const {return fTimeFormat.Data();}
135 virtual const char *GetTimeFormatOnly() const;
137 const char *GetTitle() const override {return fTitle.Data();}
138 const TArrayD *GetXbins() const {return &fXbins;}
139 Int_t GetFirst() const;
140 Int_t GetLast() const;
141 Double_t GetXmin() const {return fXmin;}
142 Double_t GetXmax() const {return fXmax;}
143 virtual void ImportAttributes(const TAxis *axis);
145 // true if axis has variable bin sizes, false otherwise
146 return (fXbins.GetSize() != 0);
147 }
148 virtual void LabelsOption(Option_t *option="h"); // *MENU*
149 void RotateTitle(Bool_t rotate=kTRUE); // *TOGGLE* *GETTER=GetRotateTitle
150 void SaveAttributes(std::ostream &out, const char *name, const char *subname) override;
151 virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax);
152 virtual void Set(Int_t nbins, const Float_t *xbins);
153 virtual void Set(Int_t nbins, const Double_t *xbins);
154 virtual void SetBinLabel(Int_t bin, const char *label);
155 void SetDecimals(Bool_t dot = kTRUE); // *TOGGLE* *GETTER=GetDecimals
156 virtual void SetDefaults();
157 void SetDrawOption(Option_t * /*option*/ ="") override { }
158 void ChangeLabel(Int_t labNum=0, Double_t labAngle = -1.,
159 Double_t labSize = -1., Int_t labAlign = -1,
160 Int_t labColor = -1 , Int_t labFont = -1,
161 const TString &labText = ""); // *MENU*
162 void ChangeLabelByValue(Double_t labValue, Double_t labAngle = -1.,
163 Double_t labSize = -1., Int_t labAlign = -1,
164 Int_t labColor = -1 , Int_t labFont = -1,
165 const TString &labText = ""); // *MENU*
166 virtual void SetLimits(Double_t xmin, Double_t xmax) { /* set axis limits */ fXmin = xmin; fXmax = xmax; } // *MENU*
167 void SetMoreLogLabels(Bool_t more=kTRUE); // *TOGGLE* *GETTER=GetMoreLogLabels
168 void SetNoExponent(Bool_t noExponent=kTRUE); // *TOGGLE* *GETTER=GetNoExponent
169 virtual void SetParent(TObject *obj) {fParent = obj;}
170 virtual void SetRange(Int_t first=0, Int_t last=0); // *MENU*
171 virtual void SetRangeUser(Double_t ufirst, Double_t ulast); // *MENU*
172 virtual void SetTicks(Option_t *option="+"); // *MENU*
173 virtual void SetTimeDisplay(Int_t value) {fTimeDisplay = (value != 0);} // *TOGGLE*
174 virtual void SetTimeFormat(const char *format=""); // *MENU*
175 virtual void SetTimeOffset(Double_t toffset, Option_t *option="local");
176 virtual void UnZoom(); // *MENU*
177 virtual void ZoomOut(Double_t factor=0, Double_t offset=0); // *MENU*
178
179 ClassDefOverride(TAxis,10) //Axis class
180};
181
182////////////////////////////////////////////////////////////////////////////////
183/// Center axis labels. If center = kTRUE axis labels will be centered
184/// (horizontal axes only) on the bin center. Default is to center on the primary tick marks
185/// This option does not make sense if there are more bins than tick marks
186
187inline void TAxis::CenterLabels(Bool_t center)
188{
189 SetBit(kCenterLabels, center);
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Center axis title. If center = kTRUE axis title will be centered
194/// default is right adjusted
195
196inline void TAxis::CenterTitle(Bool_t center)
197{
198 SetBit(kCenterTitle, center);
199}
200
201////////////////////////////////////////////////////////////////////////////////
202/// Rotate title by 180 degrees. By default the title is drawn right adjusted.
203/// If rotate is TRUE, the title is left adjusted at the end of the axis and rotated by 180 degrees
204
205inline void TAxis::RotateTitle(Bool_t rotate)
206{
207 SetBit(kRotateTitle, rotate);
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Sets the decimals flag
212/// By default, blank characters are stripped, and then the label is correctly aligned.
213/// If the dot is the last character of the string, it is also stripped, unless this option is specified.
214
215inline void TAxis::SetDecimals(Bool_t dot) {
216 SetBit(kDecimals, dot);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Set the kMoreLogLabels bit flag
221/// When this option is selected more labels are drawn when in log scale and there is a small number
222/// of decades (<3).
223/// The flag (in fBits) is passed to the drawing function TGaxis::PaintAxis
224
226{
227 SetBit(kMoreLogLabels, more);
228}
229
230////////////////////////////////////////////////////////////////////////////////
231/// Set the NoExponent flag
232/// By default, an exponent of the form 10^N is used when the label value are either all very small or very large.
233/// The flag (in fBits) is passed to the drawing function TGaxis::PaintAxis
234
235inline void TAxis::SetNoExponent(Bool_t noExponent)
236{
237 SetBit(kNoExponent, noExponent);
238}
239
240
241#endif
bool Bool_t
Definition RtypesCore.h:63
unsigned short UShort_t
Definition RtypesCore.h:40
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define BIT(n)
Definition Rtypes.h:90
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
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 value
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
char name[80]
Definition TGX11.cxx:110
float xmin
float xmax
Array of doubles (64 bits per element).
Definition TArrayD.h:27
Int_t GetSize() const
Definition TArray.h:47
Manages histogram axis attributes.
Definition TAttAxis.h:18
TAxis helper class used to store the modified labels.
Definition TAxisModLab.h:21
Class to manage histogram axis.
Definition TAxis.h:32
virtual void GetCenter(Double_t *center) const
Return an array with the center of all bins.
Definition TAxis.cxx:549
virtual void SetTimeOffset(Double_t toffset, Option_t *option="local")
Change the time offset If option = "gmt", set display mode to GMT.
Definition TAxis.cxx:1182
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option can be:
Definition TAxis.cxx:658
virtual void SetDefaults()
Set axis default values (from TStyle)
Definition TAxis.cxx:862
void SetDecimals(Bool_t dot=kTRUE)
Sets the decimals flag By default, blank characters are stripped, and then the label is correctly ali...
Definition TAxis.h:215
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition TAxis.cxx:882
void Delete(Option_t *="") override
Delete this object.
Definition TAxis.h:104
Int_t fLast
Last bin to display.
Definition TAxis.h:40
void CenterLabels(Bool_t center=kTRUE)
Center axis labels.
Definition TAxis.h:187
virtual Bool_t GetTimeDisplay() const
Definition TAxis.h:133
void ChangeLabel(Int_t labNum=0, Double_t labAngle=-1., Double_t labSize=-1., Int_t labAlign=-1, Int_t labColor=-1, Int_t labFont=-1, const TString &labText="")
Define new text attributes for the label number "labNum".
Definition TAxis.cxx:957
Bool_t IsAlphanumeric() const
Definition TAxis.h:90
Bool_t GetRotateTitle() const
Definition TAxis.h:131
Bool_t IsVariableBinSize() const
Definition TAxis.h:144
virtual void ZoomOut(Double_t factor=0, Double_t offset=0)
Zoom out by a factor of 'factor' (default =2) uses previous zoom factor by default Keep center define...
Definition TAxis.cxx:1343
const char * GetTitle() const override
Returns title of object.
Definition TAxis.h:137
Int_t GetNlabels() const
Return the number of axis labels.
Definition TAxis.cxx:577
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition TAxis.cxx:473
TObject * fParent
! Object owning this axis
Definition TAxis.h:44
Double_t fXmax
Upper edge of last bin.
Definition TAxis.h:37
void SetNoAlphanumeric(Bool_t noalpha=kTRUE)
Definition TAxis.h:93
Bool_t GetCenterTitle() const
Definition TAxis.h:121
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to an axis.
Definition TAxis.cxx:260
void SetMoreLogLabels(Bool_t more=kTRUE)
Set the kMoreLogLabels bit flag When this option is selected more labels are drawn when in log scale ...
Definition TAxis.h:225
Bool_t CanExtend() const
Definition TAxis.h:88
TArrayD fXbins
Bin edges array in X.
Definition TAxis.h:38
virtual void SetParent(TObject *obj)
Definition TAxis.h:169
TAxis()
Default constructor.
Definition TAxis.cxx:50
TObject * DrawClone(Option_t *="") const override
Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1).
Definition TAxis.h:106
UInt_t GetTimeOffset()
Return the time offset in GMT.
Definition TAxis.cxx:610
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TAxis.cxx:276
virtual void UnZoom()
Reset first & last bin to the full range.
Definition TAxis.cxx:1268
THashList * fLabels
List of labels.
Definition TAxis.h:45
const TArrayD * GetXbins() const
Definition TAxis.h:138
Bool_t GetMoreLogLabels() const
Definition TAxis.h:126
void SetCanExtend(Bool_t canExtend)
Definition TAxis.h:92
void Copy(TObject &axis) const override
Copy axis structure to another axis.
Definition TAxis.cxx:211
Double_t GetXmax() const
Definition TAxis.h:142
virtual void SetTicks(Option_t *option="+")
Set ticks orientation.
Definition TAxis.cxx:1108
EStatusBits
TAxis status bits.
Definition TAxis.h:62
@ kTickMinus
Definition TAxis.h:65
@ kLabelsUp
Definition TAxis.h:75
@ kCenterTitle
Definition TAxis.h:67
@ kRotateTitle
Definition TAxis.h:69
@ kNoExponent
Definition TAxis.h:71
@ kIsInteger
Definition TAxis.h:76
@ kMoreLogLabels
Definition TAxis.h:77
@ kTickPlus
Definition TAxis.h:64
@ kLabelsDown
Definition TAxis.h:74
@ kPalette
Definition TAxis.h:70
@ kLabelsHori
Definition TAxis.h:72
@ kAxisRange
Definition TAxis.h:66
@ kDecimals
Definition TAxis.h:63
@ kCenterLabels
Bit 13 is used by TObject.
Definition TAxis.h:68
@ kLabelsVert
Definition TAxis.h:73
Bool_t fTimeDisplay
On/off displaying time values instead of numerics.
Definition TAxis.h:42
Bool_t GetNoExponent() const
Definition TAxis.h:129
TList * fModLabs
List of modified labels.
Definition TAxis.h:46
const char * GetBinLabel(Int_t bin) const
Return label for bin.
Definition TAxis.cxx:435
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition TAxis.cxx:288
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition TAxis.cxx:513
Int_t fNbins
Number of bins.
Definition TAxis.h:35
@ kAlphanumeric
Axis is alphanumeric.
Definition TAxis.h:50
@ kNotAlpha
Axis is forced to be not alphanumeric.
Definition TAxis.h:52
@ kCanExtend
Axis can be extended.
Definition TAxis.h:51
virtual void SetTimeDisplay(Int_t value)
Definition TAxis.h:173
Double_t fXmin
Low edge of first bin.
Definition TAxis.h:36
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition TAxis.cxx:790
Bool_t HasBinWithoutLabel() const
This helper function checks if there is a bin without a label if all bins have labels,...
Definition TAxis.cxx:642
void RotateTitle(Bool_t rotate=kTRUE)
Rotate title by 180 degrees.
Definition TAxis.h:205
TAxisModLab * FindModLab(Int_t num, Double_t v=0., Double_t eps=0.) const
Search for axis modifier by index or value.
Definition TAxis.cxx:918
void CenterTitle(Bool_t center=kTRUE)
Center axis title.
Definition TAxis.h:196
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Definition TAxis.cxx:414
const char * ChooseTimeFormat(Double_t axislength=0)
Choose a reasonable time format from the coordinates in the active pad and the number of divisions in...
Definition TAxis.cxx:127
void SetDrawOption(Option_t *="") override
Set drawing option for object.
Definition TAxis.h:157
void SetNoExponent(Bool_t noExponent=kTRUE)
Set the NoExponent flag By default, an exponent of the form 10^N is used when the label value are eit...
Definition TAxis.h:235
void SaveAttributes(std::ostream &out, const char *name, const char *subname) override
Save axis attributes as C++ statement(s) on output stream out.
Definition TAxis.cxx:706
Bool_t GetDecimals() const
Definition TAxis.h:122
Int_t GetLast() const
Return last bin on the axis i.e.
Definition TAxis.cxx:464
virtual void SetLimits(Double_t xmin, Double_t xmax)
Definition TAxis.h:166
virtual void ImportAttributes(const TAxis *axis)
Copy axis attributes to this.
Definition TAxis.cxx:676
virtual const char * GetTimeFormatOnly() const
Return only the time format from the string fTimeFormat.
Definition TAxis.cxx:595
virtual Double_t GetBinCenterLog(Int_t bin) const
Return center of bin in log With a log-equidistant binning for a bin with low and up edges,...
Definition TAxis.cxx:496
void SetAlphanumeric(Bool_t alphanumeric=kTRUE)
Set axis alphanumeric.
Definition TAxis.cxx:838
Double_t GetXmin() const
Definition TAxis.h:141
TAxis & operator=(const TAxis &)
Assignment operator.
Definition TAxis.cxx:113
~TAxis() override
Destructor.
Definition TAxis.cxx:84
TList * GetModifiedLabels() const
Definition TAxis.h:124
Int_t GetNbins() const
Definition TAxis.h:127
void ChangeLabelByValue(Double_t labValue, Double_t labAngle=-1., Double_t labSize=-1., Int_t labAlign=-1, Int_t labColor=-1, Int_t labFont=-1, const TString &labText="")
Define new text attributes for the label value "labValue".
Definition TAxis.cxx:1005
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
Set the viewing range for the axis from ufirst to ulast (in user coordinates, that is,...
Definition TAxis.cxx:1081
virtual Int_t FindBin(Double_t x) const
Definition TAxis.h:109
virtual const char * GetTimeFormat() const
Definition TAxis.h:134
virtual void GetLowEdge(Double_t *edge) const
Return an array with the low edge of all bins.
Definition TAxis.cxx:558
Bool_t GetCenterLabels() const
Definition TAxis.h:120
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition TAxis.cxx:1156
Bool_t CanBeAlphanumeric()
Definition TAxis.h:89
TString fTimeFormat
Date&time format, ex: 09/12/99 12:34:00.
Definition TAxis.h:43
virtual TObject * GetParent() const
Definition TAxis.h:130
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition TAxis.cxx:1052
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition TAxis.cxx:537
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition TAxis.cxx:523
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition TAxis.cxx:453
virtual const char * GetTicks() const
Return the ticks option (see SetTicks)
Definition TAxis.cxx:630
UShort_t fBits2
Second bit status word.
Definition TAxis.h:41
Int_t fFirst
First bin to display.
Definition TAxis.h:39
THashList * GetLabels() const
Definition TAxis.h:123
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
A doubly linked list.
Definition TList.h:38
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
TString fTitle
Definition TNamed.h:33
Mother of all ROOT objects.
Definition TObject.h:41
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:798
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
Double_t x[n]
Definition legend1.C:17