Logo ROOT   6.08/07
Reference Guide
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 #ifndef ROOT_TNamed
25 #include "TNamed.h"
26 #endif
27 #ifndef ROOT_TAttAxis
28 #include "TAttAxis.h"
29 #endif
30 #ifndef ROOT_TArrayD
31 #include "TArrayD.h"
32 #endif
33 
34 class THashList;
35 
36 class TAxis : public TNamed, public TAttAxis {
37 
38 private:
39  Int_t fNbins; //Number of bins
40  Double_t fXmin; //low edge of first bin
41  Double_t fXmax; //upper edge of last bin
42  TArrayD fXbins; //Bin edges array in X
43  Int_t fFirst; //first bin to display
44  Int_t fLast; //last bin to display
45  UShort_t fBits2; //second bit status word
46  Bool_t fTimeDisplay; //on/off displaying time values instead of numerics
47  TString fTimeFormat; //Date&time format, ex: 09/12/99 12:34:00
48  TObject *fParent; //!Object owning this axis
49  THashList *fLabels; //List of labels
50  TList *fModLabs; //List of modified labels
51 
52  // TAxis extra status bits (stored in fBits2)
53  enum {
54  kAlphanumeric = BIT(0), // axis is alphanumeric
55  kCanExtend = BIT(1), // axis can be extended
56  kNotAlpha = BIT(2) // axis is forced to be not alphanumeric
57  };
58 
59  Bool_t HasBinWithoutLabel() const;
60 
61 public:
62  // TAxis status bits
63  enum {
64  kDecimals = BIT(7),
65  kTickPlus = BIT(9),
66  kTickMinus = BIT(10),
67  kAxisRange = BIT(11),
69  kCenterLabels = BIT(14), //bit 13 is used by TObject
71  kPalette = BIT(16),
76  kLabelsUp = BIT(21),
77  kIsInteger = BIT(22),
79  };
80 
81  TAxis();
83  TAxis(Int_t nbins, const Double_t *xbins);
84  TAxis(const TAxis &axis);
85  virtual ~TAxis();
86  TAxis& operator=(const TAxis&);
87 
88  Bool_t CanExtend() const { return (fBits2 & kCanExtend); }
89  Bool_t CanBeAlphanumeric() { return !(fBits2 & kNotAlpha); }
90  Bool_t IsAlphanumeric() { return fBits2 & kAlphanumeric; }
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  virtual void Copy(TObject &axis) const;
104  virtual void Delete(Option_t * /*option*/ ="") { }
105  virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
106  virtual TObject *DrawClone(Option_t * /*option*/ ="") const {return 0;}
107  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
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; }
129  virtual TObject *GetParent() const {return fParent;}
131  virtual const char *GetTicks() const;
132  virtual Bool_t GetTimeDisplay() const {return fTimeDisplay;}
133  virtual const char *GetTimeFormat() const {return fTimeFormat.Data();}
134  virtual const char *GetTimeFormatOnly() const;
135  const char *GetTitle() const {return fTitle.Data();}
136  const TArrayD *GetXbins() const {return &fXbins;}
137  Int_t GetFirst() const;
138  Int_t GetLast() const;
139  Double_t GetXmin() const {return fXmin;}
140  Double_t GetXmax() const {return fXmax;}
141  virtual void ImportAttributes(const TAxis *axis);
143  // true if axis has variable bin sizes, false otherwise
144  return (fXbins.GetSize() != 0);
145  }
146  virtual void LabelsOption(Option_t *option="h"); // *MENU*
147  void RotateTitle(Bool_t rotate=kTRUE); // *TOGGLE* *GETTER=GetRotateTitle
148  virtual void SaveAttributes(std::ostream &out, const char *name, const char *subname);
149  virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax);
150  virtual void Set(Int_t nbins, const Float_t *xbins);
151  virtual void Set(Int_t nbins, const Double_t *xbins);
152  virtual void SetBinLabel(Int_t bin, const char *label);
153  void SetDecimals(Bool_t dot = kTRUE); // *TOGGLE* *GETTER=GetDecimals
154  virtual void SetDefaults();
155  virtual void SetDrawOption(Option_t * /*option*/ ="") { }
156  void ChangeLabel(Int_t labNum=0, Double_t labAngle = -1.,
157  Double_t labSize = -1., Int_t labAlign = -1,
158  Int_t labColor = -1 , Int_t labFont = -1,
159  TString labText = ""); // *MENU*
160  virtual void SetLimits(Double_t xmin, Double_t xmax) { /* set axis limits */ fXmin = xmin; fXmax = xmax; }
161  void SetMoreLogLabels(Bool_t more=kTRUE); // *TOGGLE* *GETTER=GetMoreLogLabels
162  void SetNoExponent(Bool_t noExponent=kTRUE); // *TOGGLE* *GETTER=GetNoExponent
163  virtual void SetParent(TObject *obj) {fParent = obj;}
164  virtual void SetRange(Int_t first=0, Int_t last=0); // *MENU*
165  virtual void SetRangeUser(Double_t ufirst, Double_t ulast); // *MENU*
166  virtual void SetTicks(Option_t *option="+"); // *MENU*
167  virtual void SetTimeDisplay(Int_t value) {fTimeDisplay = (value != 0);} // *TOGGLE*
168  virtual void SetTimeFormat(const char *format=""); // *MENU*
169  virtual void SetTimeOffset(Double_t toffset, Option_t *option="local");
170  virtual void UnZoom(); // *MENU*
171  virtual void ZoomOut(Double_t factor=0, Double_t offset=0); // *MENU*
172 
173  ClassDef(TAxis,10) //Axis class
174 };
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Center axis labels. If center = kTRUE axis labels will be centered
178 /// (hori axes only) on the bin center default is to center on the primary tick marks
179 /// This option does not make sense if there are more bins than tick marks
180 
181 inline void TAxis::CenterLabels(Bool_t center)
182 {
183  SetBit(kCenterLabels, center);
184 }
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// Center axis title. If center = kTRUE axis title will be centered
188 /// default is right adjusted
189 
190 inline void TAxis::CenterTitle(Bool_t center)
191 {
192  SetBit(kCenterTitle, center);
193 }
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// Rotate title by 180 degrees. By default the title is drawn right adjusted.
197 /// If rotate is TRUE, the title is left adjusted at the end of the axis and rotated by 180 degrees
198 
199 inline void TAxis::RotateTitle(Bool_t rotate)
200 {
201  SetBit(kRotateTitle, rotate);
202 }
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// Sets the decimals flag
206 /// By default, blank characters are stripped, and then the label is correctly aligned.
207 /// If the dot is the last character of the string, it is also stripped, unless this option is specified.
208 
209 inline void TAxis::SetDecimals(Bool_t dot) {
210  SetBit(kDecimals, dot);
211 }
212 
213 ////////////////////////////////////////////////////////////////////////////////
214 /// Set the kMoreLogLabels bit flag
215 /// When this option is selected more labels are drawn when in log scale and there is a small number
216 /// of decades (<3).
217 /// The flag (in fBits) is passed to the drawing function TGaxis::PaintAxis
218 
220 {
221  SetBit(kMoreLogLabels, more);
222 }
223 
224 ////////////////////////////////////////////////////////////////////////////////
225 /// Set the NoExponent flag
226 /// By default, an exponent of the form 10^N is used when the label value are either all very small or very large.
227 /// The flag (in fBits) is passed to the drawing function TGaxis::PaintAxis
228 
229 inline void TAxis::SetNoExponent(Bool_t noExponent)
230 {
231  SetBit(kNoExponent, noExponent);
232 }
233 
234 
235 #endif
236 
TString fTitle
Definition: TNamed.h:37
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to an axis.
Definition: TAxis.cxx:251
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:487
virtual void SaveAttributes(std::ostream &out, const char *name, const char *subname)
Save axis attributes as C++ statement(s) on output stream out.
Definition: TAxis.cxx:646
Int_t fFirst
Definition: TAxis.h:43
float xmin
Definition: THbookFile.cxx:93
const char * GetBinLabel(Int_t bin) const
Return label for bin.
Definition: TAxis.cxx:426
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:444
virtual void SetLimits(Double_t xmin, Double_t xmax)
Definition: TAxis.h:160
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition: TAxis.cxx:999
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:504
Bool_t GetCenterLabels() const
Definition: TAxis.h:120
unsigned short UShort_t
Definition: RtypesCore.h:36
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:157
#define BIT(n)
Definition: Rtypes.h:120
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TAxis.cxx:267
UShort_t fBits2
Definition: TAxis.h:45
Basic string class.
Definition: TString.h:137
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:1025
Bool_t HasBinWithoutLabel() const
this helper function checks if there is a bin without a label if all bins have labels, the axis can / will become alphanumeric
Definition: TAxis.cxx:583
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
int nbins[3]
virtual TObject * GetParent() const
Definition: TAxis.h:129
virtual void Copy(TObject &axis) const
Copy axis structure to another axis.
Definition: TAxis.cxx:208
static std::string format(double x, double y, int digits, int width)
void CenterTitle(Bool_t center=kTRUE)
Center axis title.
Definition: TAxis.h:190
Manages histogram axis attributes.
Definition: TAttAxis.h:23
Bool_t CanExtend() const
Definition: TAxis.h:88
void SetNoAlphanumeric(Bool_t noalpha=kTRUE)
Definition: TAxis.h:93
Bool_t GetDecimals() const
Definition: TAxis.h:122
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:739
TAxis()
Default constructor.
Definition: TAxis.cxx:47
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition: TAxis.cxx:514
Bool_t GetMoreLogLabels() const
Definition: TAxis.h:126
Double_t fXmax
Definition: TAxis.h:41
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
Set the viewing range for the axis from ufirst to ulast (in user coordinates).
Definition: TAxis.cxx:925
Double_t GetXmin() const
Definition: TAxis.h:139
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
virtual Bool_t GetTimeDisplay() const
Definition: TAxis.h:132
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
THashList * GetLabels() const
Definition: TAxis.h:123
virtual void SetDrawOption(Option_t *="")
Set drawing option for object.
Definition: TAxis.h:155
virtual void GetCenter(Double_t *center) const
Return an array with the center of all bins.
Definition: TAxis.cxx:539
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:464
Bool_t IsAlphanumeric()
Definition: TAxis.h:90
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option = "a" sort by alphabetic order = ">" sort by decreasing...
Definition: TAxis.cxx:598
virtual void GetLowEdge(Double_t *edge) const
Return an array with the lod edge of all bins.
Definition: TAxis.cxx:548
TList * GetModifiedLabels() const
Definition: TAxis.h:124
virtual const char * GetTimeFormat() const
Definition: TAxis.h:133
virtual void SetTimeDisplay(Int_t value)
Definition: TAxis.h:167
Bool_t GetRotateTitle() const
Definition: TAxis.h:130
virtual void SetDefaults()
Set axis default values (from TStyle)
Definition: TAxis.cxx:788
A doubly linked list.
Definition: TList.h:47
virtual void ImportAttributes(const TAxis *axis)
Copy axis attributes to this.
Definition: TAxis.cxx:616
TList * fModLabs
Definition: TAxis.h:50
virtual const char * GetTicks() const
Return the ticks option (see SetTicks)
Definition: TAxis.cxx:572
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, TString labText="")
Define new text attributes for the label number "labNum".
Definition: TAxis.cxx:857
void CenterLabels(Bool_t center=kTRUE)
Center axis labels.
Definition: TAxis.h:181
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis from bin first to last.
Definition: TAxis.cxx:887
TString fTimeFormat
Definition: TAxis.h:47
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:124
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:455
const char * GetTitle() const
Returns title of object.
Definition: TAxis.h:135
Class to manage histogram axis.
Definition: TAxis.h:36
Int_t GetSize() const
Definition: TArray.h:49
virtual ~TAxis()
Destructor.
Definition: TAxis.cxx:86
void SetCanExtend(Bool_t canExtend)
Definition: TAxis.h:92
virtual void UnZoom()
Reset first & last bin to the full range.
Definition: TAxis.cxx:1111
Bool_t fTimeDisplay
Definition: TAxis.h:46
float xmax
Definition: THbookFile.cxx:93
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:279
Bool_t CanBeAlphanumeric()
Definition: TAxis.h:89
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:229
double Double_t
Definition: RtypesCore.h:55
Bool_t GetCenterTitle() const
Definition: TAxis.h:121
virtual void Delete(Option_t *="")
Delete this object.
Definition: TAxis.h:104
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:808
virtual const char * GetTimeFormatOnly() const
Return only the time format from the string fTimeFormat.
Definition: TAxis.cxx:557
virtual void SetTicks(Option_t *option="+")
Set ticks orientation.
Definition: TAxis.cxx:951
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:209
Array of doubles (64 bits per element).
Definition: TArrayD.h:29
Bool_t IsVariableBinSize() const
Definition: TAxis.h:142
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:405
Int_t fNbins
Definition: TAxis.h:39
void SetAlphanumeric(Bool_t alphanumeric=kTRUE)
Set axis alphanumeric.
Definition: TAxis.cxx:764
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition: TAxis.cxx:526
void RotateTitle(Bool_t rotate=kTRUE)
Rotate title by 180 degrees.
Definition: TAxis.h:199
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:219
Bool_t GetNoExponent() const
Definition: TAxis.h:128
TAxis & operator=(const TAxis &)
Assignment operator.
Definition: TAxis.cxx:111
TArrayD fXbins
Definition: TAxis.h:42
virtual Int_t FindBin(Double_t x) const
Definition: TAxis.h:109
virtual void SetParent(TObject *obj)
Definition: TAxis.h:163
virtual TObject * DrawClone(Option_t *="") const
Draw a clone of this object in the current pad.
Definition: TAxis.h:106
Definition: first.py:1
Int_t GetNbins() const
Definition: TAxis.h:127
TObject * fParent
Definition: TAxis.h:48
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Definition: TAxis.cxx:716
const Bool_t kTRUE
Definition: Rtypes.h:91
Double_t fXmin
Definition: TAxis.h:40
Double_t GetXmax() const
Definition: TAxis.h:140
Int_t fLast
Definition: TAxis.h:44
char name[80]
Definition: TGX11.cxx:109
virtual void ZoomOut(Double_t factor=0, Double_t offset=0)
Zoom out by a factor of &#39;factor&#39; (default =2) uses previous zoom factor by default Keep center define...
Definition: TAxis.cxx:1183
const TArrayD * GetXbins() const
Definition: TAxis.h:136
THashList * fLabels
Object owning this axis.
Definition: TAxis.h:49
const char * Data() const
Definition: TString.h:349