ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
51  // TAxis extra status bits (stored in fBits2)
52  enum {
53  kAlphanumeric = BIT(0), // axis is alphanumeric
54  kCanExtend = BIT(1), // axis can be extended
55  kNotAlpha = BIT(2) // axis is forced to be not alphanumeric
56  };
57 
58  Bool_t HasBinWithoutLabel() const;
61  void SetAlphanumeric(Bool_t alphanumeric = kTRUE);
62 
63 public:
64  // TAxis status bits
65  enum {
66  kDecimals = BIT(7),
67  kTickPlus = BIT(9),
68  kTickMinus = BIT(10),
69  kAxisRange = BIT(11),
71  kCenterLabels = BIT(14), //bit 13 is used by TObject
73  kPalette = BIT(16),
78  kLabelsUp = BIT(21),
79  kIsInteger = BIT(22),
81  };
82 
83  TAxis();
85  TAxis(Int_t nbins, const Double_t *xbins);
86  TAxis(const TAxis &axis);
87  virtual ~TAxis();
88  TAxis& operator=(const TAxis&);
89 
90  Bool_t CanExtend() const { return (fBits2 & kCanExtend); }
91  void SetCanExtend(Bool_t canExtend) { fBits2 = canExtend ? (fBits2 | kCanExtend) : (fBits2 & ~kCanExtend); }
92  void SetNoAlphanumeric(Bool_t noalpha = kTRUE) {
93  fBits2 = noalpha ? (fBits2 | kNotAlpha) : (fBits2 & ~kNotAlpha);
94  if (IsAlphanumeric() ) {
97  }
98  }
99  void CenterLabels(Bool_t center=kTRUE);
100  void CenterTitle(Bool_t center=kTRUE);
101  const char *ChooseTimeFormat(Double_t axislength=0);
102  virtual void Copy(TObject &axis) const;
103  virtual void Delete(Option_t * /*option*/ ="") { }
105  virtual TObject *DrawClone(Option_t * /*option*/ ="") const {return 0;}
106  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
107  virtual Int_t FindBin(Double_t x);
108  virtual Int_t FindBin(Double_t x) const { return FindFixBin(x); }
109  virtual Int_t FindBin(const char *label);
110  virtual Int_t FindFixBin(Double_t x) const;
111  virtual Int_t FindFixBin(const char *label) const;
112  virtual Double_t GetBinCenter(Int_t bin) const;
113  virtual Double_t GetBinCenterLog(Int_t bin) const;
114  const char *GetBinLabel(Int_t bin) const;
115  virtual Double_t GetBinLowEdge(Int_t bin) const;
116  virtual Double_t GetBinUpEdge(Int_t bin) const;
117  virtual Double_t GetBinWidth(Int_t bin) const;
118  virtual void GetCenter(Double_t *center) const;
121  Bool_t GetDecimals() const { return TestBit(kDecimals); }
122  THashList *GetLabels() const { return fLabels; }
123  virtual void GetLowEdge(Double_t *edge) const;
125  Int_t GetNbins() const { return fNbins; }
127  virtual TObject *GetParent() const {return fParent;}
129  virtual const char *GetTicks() const;
130  virtual Bool_t GetTimeDisplay() const {return fTimeDisplay;}
131  virtual const char *GetTimeFormat() const {return fTimeFormat.Data();}
132  virtual const char *GetTimeFormatOnly() const;
133  const char *GetTitle() const {return fTitle.Data();}
134  const TArrayD *GetXbins() const {return &fXbins;}
135  Int_t GetFirst() const;
136  Int_t GetLast() const;
137  Double_t GetXmin() const {return fXmin;}
138  Double_t GetXmax() const {return fXmax;}
139  virtual void ImportAttributes(const TAxis *axis);
141  // true if axis has variable bin sizes, false otherwise
142  return (fXbins.GetSize() != 0);
143  }
144  virtual void LabelsOption(Option_t *option="h"); // *MENU*
145  void RotateTitle(Bool_t rotate=kTRUE); // *TOGGLE* *GETTER=GetRotateTitle
146  virtual void SaveAttributes(std::ostream &out, const char *name, const char *subname);
147  virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax);
148  virtual void Set(Int_t nbins, const Float_t *xbins);
149  virtual void Set(Int_t nbins, const Double_t *xbins);
150  virtual void SetBinLabel(Int_t bin, const char *label);
151  void SetDecimals(Bool_t dot = kTRUE); // *TOGGLE* *GETTER=GetDecimals
152  virtual void SetDefaults();
153  virtual void SetDrawOption(Option_t * /*option*/ ="") { }
154  virtual void SetLimits(Double_t xmin, Double_t xmax) { /* set axis limits */ fXmin = xmin; fXmax = xmax; }
155  void SetMoreLogLabels(Bool_t more=kTRUE); // *TOGGLE* *GETTER=GetMoreLogLabels
156  void SetNoExponent(Bool_t noExponent=kTRUE); // *TOGGLE* *GETTER=GetNoExponent
157  virtual void SetParent(TObject *obj) {fParent = obj;}
158  virtual void SetRange(Int_t first=0, Int_t last=0); // *MENU*
159  virtual void SetRangeUser(Double_t ufirst, Double_t ulast); // *MENU*
160  virtual void SetTicks(Option_t *option="+"); // *MENU*
161  virtual void SetTimeDisplay(Int_t value) {fTimeDisplay = (value != 0);} // *TOGGLE*
162  virtual void SetTimeFormat(const char *format=""); // *MENU*
163  virtual void SetTimeOffset(Double_t toffset, Option_t *option="local");
164  virtual void UnZoom(); // *MENU*
165  virtual void ZoomOut(Double_t factor=0, Double_t offset=0); // *MENU*
166 
167  ClassDef(TAxis,9) //Axis class
168 };
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Center axis labels. If center = kTRUE axis labels will be centered
172 /// (hori axes only) on the bin center default is to center on the primary tick marks
173 /// This option does not make sense if there are more bins than tick marks
174 
175 inline void TAxis::CenterLabels(Bool_t center)
176 {
177  SetBit(kCenterLabels, center);
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Center axis title. If center = kTRUE axis title will be centered
182 /// default is right adjusted
183 
184 inline void TAxis::CenterTitle(Bool_t center)
185 {
186  SetBit(kCenterTitle, center);
187 }
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// Rotate title by 180 degrees. By default the title is drawn right adjusted.
191 /// If rotate is TRUE, the title is left adjusted at the end of the axis and rotated by 180 degrees
192 
193 inline void TAxis::RotateTitle(Bool_t rotate)
194 {
195  SetBit(kRotateTitle, rotate);
196 }
197 
198 ////////////////////////////////////////////////////////////////////////////////
199 /// Sets the decimals flag
200 /// By default, blank characters are stripped, and then the label is correctly aligned.
201 /// If the dot is the last character of the string, it is also stripped, unless this option is specified.
202 
204  SetBit(kDecimals, dot);
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// Set the kMoreLogLabels bit flag
209 /// When this option is selected more labels are drawn when in log scale and there is a small number
210 /// of decades (<3).
211 /// The flag (in fBits) is passed to the drawing function TGaxis::PaintAxis
212 
214 {
215  SetBit(kMoreLogLabels, more);
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Set the NoExponent flag
220 /// By default, an exponent of the form 10^N is used when the label value are either all very small or very large.
221 /// The flag (in fBits) is passed to the drawing function TGaxis::PaintAxis
222 
223 inline void TAxis::SetNoExponent(Bool_t noExponent)
224 {
225  SetBit(kNoExponent, noExponent);
226 }
227 
228 
229 #endif
230 
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:236
Bool_t GetCenterLabels() const
Definition: TAxis.h:119
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:429
virtual TObject * DrawClone(Option_t *="") const
Draw a clone of this object in the current pad.
Definition: TAxis.h:105
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:631
Int_t fFirst
Definition: TAxis.h:43
float xmin
Definition: THbookFile.cxx:93
virtual void GetLowEdge(Double_t *edge) const
Return an array with the lod edge of all bins.
Definition: TAxis.cxx:533
Bool_t CanExtend() const
Definition: TAxis.h:90
virtual void SetLimits(Double_t xmin, Double_t xmax)
Definition: TAxis.h:154
virtual void SetTimeFormat(const char *format="")
Change the format used for time plotting.
Definition: TAxis.cxx:943
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
const char * GetBinLabel(Int_t bin) const
Return label for bin.
Definition: TAxis.cxx:411
tuple offset
Definition: tree.py:93
unsigned short UShort_t
Definition: RtypesCore.h:36
#define BIT(n)
Definition: Rtypes.h:120
ClassDef(TAttAxis, 4)
virtual Bool_t GetTimeDisplay() const
Definition: TAxis.h:130
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:489
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TAxis.cxx:252
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:969
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition: TAxis.cxx:511
int nbins[3]
static std::string format(double x, double y, int digits, int width)
Float_t py
Definition: hprod.C:33
void CenterTitle(Bool_t center=kTRUE)
Center axis title.
Definition: TAxis.h:184
Manages histogram axis attributes.
Definition: TAttAxis.h:32
void SetNoAlphanumeric(Bool_t noalpha=kTRUE)
Definition: TAxis.h:92
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
Bool_t IsVariableBinSize() const
Definition: TAxis.h:140
Double_t fXmax
Definition: TAxis.h:41
const char * Data() const
Definition: TString.h:349
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:869
Double_t dot(const TVector2 &v1, const TVector2 &v2)
Definition: CsgOps.cxx:333
Double_t x[n]
Definition: legend1.C:17
virtual const char * GetTicks() const
Return the ticks option (see SetTicks)
Definition: TAxis.cxx:557
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual void SetDrawOption(Option_t *="")
Set drawing option for object.
Definition: TAxis.h:153
Bool_t IsAlphanumeric()
Definition: TAxis.h:59
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:583
Double_t GetXmin() const
Definition: TAxis.h:137
virtual TObject * GetParent() const
Definition: TAxis.h:127
char * out
Definition: TBase64.cxx:29
virtual void SetTimeDisplay(Int_t value)
Definition: TAxis.h:161
virtual void SetDefaults()
Set axis default values (from TStyle)
Definition: TAxis.cxx:773
virtual void ImportAttributes(const TAxis *axis)
Copy axis attributes to this.
Definition: TAxis.cxx:601
virtual const char * GetTimeFormat() const
Definition: TAxis.h:131
virtual const char * GetTimeFormatOnly() const
Return only the time format from the string fTimeFormat.
Definition: TAxis.cxx:542
void CenterLabels(Bool_t center=kTRUE)
Center axis labels.
Definition: TAxis.h:175
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:831
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:114
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:472
Class to manage histogram axis.
Definition: TAxis.h:36
Int_t GetNbins() const
Definition: TAxis.h:125
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition: TAxis.cxx:499
virtual ~TAxis()
Destructor.
Definition: TAxis.cxx:81
void SetCanExtend(Bool_t canExtend)
Definition: TAxis.h:91
virtual void UnZoom()
Reset first & last bin to the full range.
Definition: TAxis.cxx:1055
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
bool first
Definition: line3Dfit.C:48
const char * GetTitle() const
Returns title of object.
Definition: TAxis.h:133
Bool_t fTimeDisplay
Definition: TAxis.h:46
float xmax
Definition: THbookFile.cxx:93
Bool_t GetDecimals() const
Definition: TAxis.h:121
Bool_t GetNoExponent() const
Definition: TAxis.h:126
Int_t GetSize() const
Definition: TArray.h:49
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:264
Bool_t CanBeAlphanumeric()
Definition: TAxis.h:60
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:223
Bool_t GetCenterTitle() const
Definition: TAxis.h:120
double Double_t
Definition: RtypesCore.h:55
virtual void Copy(TObject &axis) const
Copy axis structure to another axis.
Definition: TAxis.cxx:198
Double_t GetXmax() const
Definition: TAxis.h:138
virtual void Delete(Option_t *="")
Delete this object.
Definition: TAxis.h:103
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:793
virtual void SetTicks(Option_t *option="+")
Set ticks orientation.
Definition: TAxis.cxx:895
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:203
Array of doubles (64 bits per element).
Definition: TArrayD.h:29
#define name(a, b)
Definition: linkTestLib0.cpp:5
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:440
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:449
Mother of all ROOT objects.
Definition: TObject.h:58
Int_t fNbins
Definition: TAxis.h:39
void SetAlphanumeric(Bool_t alphanumeric=kTRUE)
Set axis alphanumeric.
Definition: TAxis.cxx:749
Float_t px
Definition: hprod.C:33
THashList * GetLabels() const
Definition: TAxis.h:122
Bool_t axis
Definition: geodemo.C:37
virtual Int_t FindBin(Double_t x) const
Definition: TAxis.h:108
virtual void GetCenter(Double_t *center) const
Return an array with the center of all bins.
Definition: TAxis.cxx:524
virtual Int_t FindFixBin(Double_t x) const
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:390
void RotateTitle(Bool_t rotate=kTRUE)
Rotate title by 180 degrees.
Definition: TAxis.h:193
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:213
TAxis & operator=(const TAxis &)
Assignment operator.
Definition: TAxis.cxx:101
TArrayD fXbins
Definition: TAxis.h:42
virtual void SetParent(TObject *obj)
Definition: TAxis.h:157
const TArrayD * GetXbins() const
Definition: TAxis.h:134
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:568
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:701
Bool_t GetRotateTitle() const
Definition: TAxis.h:128
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
float value
Definition: math.cpp:443
Bool_t GetMoreLogLabels() const
Definition: TAxis.h:124
Double_t fXmin
Definition: TAxis.h:40
Int_t fLast
Definition: TAxis.h:44
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:1125
THashList * fLabels
Object owning this axis.
Definition: TAxis.h:49