Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:31

0001 // @(#)root/hist:$Id$
0002 // Author: Rene Brun   12/12/94
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TAxis
0013 #define ROOT_TAxis
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TAxis                                                                //
0019 //                                                                      //
0020 // Axis class.                                                          //
0021 //                                                                      //
0022 //////////////////////////////////////////////////////////////////////////
0023 
0024 #include "TNamed.h"
0025 #include "TAttAxis.h"
0026 #include "TArrayD.h"
0027 
0028 class THashList;
0029 class TAxisModLab;
0030 
0031 class TAxis : public TNamed, public TAttAxis {
0032 
0033 private:
0034    Int_t        fNbins;         ///<  Number of bins
0035    Double_t     fXmin;          ///<  Low edge of first bin
0036    Double_t     fXmax;          ///<  Upper edge of last bin
0037    TArrayD      fXbins;         ///<  Bin edges array in X
0038    Int_t        fFirst;         ///<  First bin to display
0039    Int_t        fLast;          ///<  Last bin to display
0040    UShort_t     fBits2;         ///<  Second bit status word
0041    Bool_t       fTimeDisplay;   ///<  On/off displaying time values instead of numerics
0042    TString      fTimeFormat;    ///<  Date&time format, ex: 09/12/99 12:34:00
0043    TObject     *fParent;        ///<! Object owning this axis
0044    THashList   *fLabels;        ///<  List of labels
0045    TList       *fModLabs;       ///<  List of modified labels
0046 
0047    /// TAxis extra status bits (stored in fBits2)
0048    enum {
0049       kAlphanumeric = BIT(0),   ///< Axis is alphanumeric
0050       kCanExtend = BIT(1),      ///< Axis can be extended
0051       kNotAlpha = BIT(2)        ///< Axis is forced to be not alphanumeric
0052    };
0053 
0054    Bool_t       HasBinWithoutLabel() const;
0055 
0056 
0057    TAxisModLab *FindModLab(Int_t num, Double_t v = 0., Double_t eps = 0.) const;
0058 
0059 public:
0060    /// TAxis status bits
0061    enum EStatusBits {
0062       kDecimals      = BIT(7),
0063       kTickPlus      = BIT(9),
0064       kTickMinus     = BIT(10),
0065       kAxisRange     = BIT(11),
0066       kCenterTitle   = BIT(12),
0067       kCenterLabels  = BIT(14), ///< Bit 13 is used by TObject
0068       kRotateTitle   = BIT(15),
0069       kPalette       = BIT(16),
0070       kNoExponent    = BIT(17),
0071       kLabelsHori    = BIT(18),
0072       kLabelsVert    = BIT(19),
0073       kLabelsDown    = BIT(20),
0074       kLabelsUp      = BIT(21),
0075       kIsInteger     = BIT(22),
0076       kMoreLogLabels = BIT(23)
0077    };
0078 
0079    TAxis();
0080    TAxis(Int_t nbins, Double_t xmin, Double_t xmax);
0081    TAxis(Int_t nbins, const Double_t *xbins);
0082    TAxis(const TAxis &axis);
0083    ~TAxis() override;
0084    TAxis& operator=(const TAxis&);
0085 
0086    Bool_t     CanExtend() const { return (fBits2 & kCanExtend);  }
0087    Bool_t     CanBeAlphanumeric() { return !(fBits2 & kNotAlpha); }
0088    Bool_t     IsAlphanumeric() const { return fBits2 & kAlphanumeric; }
0089    void       SetAlphanumeric(Bool_t alphanumeric = kTRUE);
0090    void       SetCanExtend(Bool_t canExtend) { fBits2 = canExtend ? (fBits2 | kCanExtend) : (fBits2 & ~kCanExtend); }
0091    void       SetNoAlphanumeric(Bool_t noalpha = kTRUE) {
0092       fBits2 = noalpha ? (fBits2 | kNotAlpha) : (fBits2 & ~kNotAlpha);
0093       if (IsAlphanumeric() ) {
0094          SetCanExtend(kFALSE);
0095          SetAlphanumeric(kFALSE);
0096       }
0097    }
0098    void               CenterLabels(Bool_t center=kTRUE);
0099    void               CenterTitle(Bool_t center=kTRUE);
0100    const char        *ChooseTimeFormat(Double_t axislength=0);
0101    void       Copy(TObject &axis) const override;
0102    void       Delete(Option_t * /*option*/ ="") override { }
0103    Int_t      DistancetoPrimitive(Int_t px, Int_t py) override;
0104    TObject   *DrawClone(Option_t * /*option*/ ="") const override {return nullptr;}
0105    void       ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
0106    virtual Int_t      FindBin(Double_t x);
0107    virtual Int_t      FindBin(Double_t x) const { return FindFixBin(x); }
0108    virtual Int_t      FindBin(const char *label);
0109    virtual Int_t      FindFixBin(Double_t x) const;
0110    virtual Int_t      FindFixBin(const char *label) const;
0111    virtual Double_t   GetBinCenter(Int_t bin) const;
0112    virtual Double_t   GetBinCenterLog(Int_t bin) const;
0113    const char        *GetBinLabel(Int_t bin) const;
0114    virtual Double_t   GetBinLowEdge(Int_t bin) const;
0115    virtual Double_t   GetBinUpEdge(Int_t bin) const;
0116    virtual Double_t   GetBinWidth(Int_t bin) const;
0117    virtual void       GetCenter(Double_t *center) const;
0118            Bool_t     GetCenterLabels() const { return TestBit(kCenterLabels); }
0119            Bool_t     GetCenterTitle() const { return TestBit(kCenterTitle); }
0120            Bool_t     GetDecimals() const { return TestBit(kDecimals); }
0121    THashList         *GetLabels() const { return fLabels; }
0122    TList             *GetModifiedLabels() const { return fModLabs; }
0123    virtual void       GetLowEdge(Double_t *edge) const;
0124            Bool_t     GetMoreLogLabels() const { return TestBit(kMoreLogLabels); }
0125            Int_t      GetNbins() const { return fNbins; }
0126            Int_t      GetNlabels() const;
0127            Bool_t     GetNoExponent() const { return TestBit(kNoExponent); }
0128    virtual TObject   *GetParent() const {return fParent;}
0129            Bool_t     GetRotateTitle() const { return TestBit(kRotateTitle); }
0130    virtual const char *GetTicks() const;
0131    virtual Bool_t     GetTimeDisplay() const {return fTimeDisplay;}
0132    virtual const char *GetTimeFormat() const {return fTimeFormat.Data();}
0133    virtual const char *GetTimeFormatOnly() const;
0134            UInt_t      GetTimeOffset();
0135    const char        *GetTitle() const override {return fTitle.Data();}
0136    const TArrayD     *GetXbins() const {return &fXbins;}
0137            Int_t      GetFirst() const;
0138            Int_t      GetLast() const;
0139            Double_t   GetXmin() const {return fXmin;}
0140            Double_t   GetXmax() const {return fXmax;}
0141    virtual void       ImportAttributes(const TAxis *axis);
0142    Bool_t             IsVariableBinSize() const {
0143                          // true if axis has variable bin sizes, false otherwise
0144                          return (fXbins.GetSize() != 0);
0145                       }
0146    virtual void       LabelsOption(Option_t *option="h");  // *MENU*
0147            void       RotateTitle(Bool_t rotate=kTRUE); // *TOGGLE* *GETTER=GetRotateTitle
0148    void       SaveAttributes(std::ostream &out, const char *name, const char *subname) override;
0149    virtual void       Set(Int_t nbins, Double_t xmin, Double_t xmax);
0150    virtual void       Set(Int_t nbins, const Float_t *xbins);
0151    virtual void       Set(Int_t nbins, const Double_t *xbins);
0152    virtual void       SetBinLabel(Int_t bin, const char *label);
0153            void       SetDecimals(Bool_t dot = kTRUE); // *TOGGLE* *GETTER=GetDecimals
0154    virtual void       SetDefaults();
0155    void       SetDrawOption(Option_t * /*option*/ ="") override { }
0156    void               ChangeLabel(Int_t labNum=0, Double_t labAngle = -1.,
0157                                   Double_t labSize = -1., Int_t labAlign = -1,
0158                                   Int_t labColor = -1 , Int_t labFont = -1,
0159                                   const TString &labText = ""); // *MENU*
0160    void               ChangeLabelByValue(Double_t labValue, Double_t labAngle = -1.,
0161                                   Double_t labSize = -1., Int_t labAlign = -1,
0162                                   Int_t labColor = -1 , Int_t labFont = -1,
0163                                   const TString &labText = ""); // *MENU*
0164    virtual void       SetLimits(Double_t xmin, Double_t xmax) { /* set axis limits */ fXmin = xmin; fXmax = xmax; } // *MENU*
0165            void       SetMoreLogLabels(Bool_t more=kTRUE);  // *TOGGLE* *GETTER=GetMoreLogLabels
0166            void       SetNoExponent(Bool_t noExponent=kTRUE);  // *TOGGLE* *GETTER=GetNoExponent
0167    virtual void       SetParent(TObject *obj) {fParent = obj;}
0168    virtual void       SetRange(Int_t first=0, Int_t last=0);  // *MENU*
0169    virtual void       SetRangeUser(Double_t ufirst, Double_t ulast);  // *MENU*
0170    virtual void       SetTicks(Option_t *option="+"); // *MENU*
0171    virtual void       SetTimeDisplay(Int_t value) {fTimeDisplay = (value != 0);} // *TOGGLE*
0172    virtual void       SetTimeFormat(const char *format="");  // *MENU*
0173    virtual void       SetTimeOffset(Double_t toffset, Option_t *option="local");
0174    virtual void       UnZoom();  // *MENU*
0175    virtual void       ZoomOut(Double_t factor=0, Double_t offset=0);  // *MENU*
0176 
0177    ClassDefOverride(TAxis,10)  //Axis class
0178 };
0179 
0180 ////////////////////////////////////////////////////////////////////////////////
0181 /// Center axis labels. If center = kTRUE axis labels will be centered
0182 /// (horizontal axes only) on the bin center. Default is to center on the primary tick marks
0183 /// This option does not make sense if there are more bins than tick marks
0184 
0185 inline void TAxis::CenterLabels(Bool_t center)
0186 {
0187    SetBit(kCenterLabels, center);
0188 }
0189 
0190 ////////////////////////////////////////////////////////////////////////////////
0191 /// Center axis title. If center = kTRUE axis title will be centered
0192 /// default is right adjusted
0193 
0194 inline void TAxis::CenterTitle(Bool_t center)
0195 {
0196    SetBit(kCenterTitle, center);
0197 }
0198 
0199 ////////////////////////////////////////////////////////////////////////////////
0200 /// Rotate title by 180 degrees. By default the title is drawn right adjusted.
0201 /// If rotate is TRUE, the title is left adjusted at the end of the axis and rotated by 180 degrees
0202 
0203 inline void TAxis::RotateTitle(Bool_t rotate)
0204 {
0205    SetBit(kRotateTitle, rotate);
0206 }
0207 
0208 ////////////////////////////////////////////////////////////////////////////////
0209 /// Sets the decimals flag
0210 /// By default, blank characters are stripped, and then the label is correctly aligned.
0211 /// If the dot is the last character of the string, it is also stripped, unless this option is specified.
0212 
0213 inline void TAxis::SetDecimals(Bool_t dot) {
0214    SetBit(kDecimals, dot);
0215 }
0216 
0217 ////////////////////////////////////////////////////////////////////////////////
0218 /// Set the kMoreLogLabels bit flag
0219 /// When this option is selected more labels are drawn when in log scale and there is a small number
0220 /// of decades  (<3).
0221 /// The flag (in fBits) is passed to the drawing function TGaxis::PaintAxis
0222 
0223 inline void TAxis::SetMoreLogLabels(Bool_t more)
0224 {
0225     SetBit(kMoreLogLabels, more);
0226 }
0227 
0228 ////////////////////////////////////////////////////////////////////////////////
0229 /// Set the NoExponent flag
0230 /// By default, an exponent of the form 10^N is used when the label value are either all very small or very large.
0231 /// The flag (in fBits) is passed to the drawing function TGaxis::PaintAxis
0232 
0233 inline void TAxis::SetNoExponent(Bool_t noExponent)
0234 {
0235    SetBit(kNoExponent, noExponent);
0236 }
0237 
0238 
0239 #endif