Haxis.cxx

Go to the documentation of this file.
00001 // @(#)root/hist:$Id: Haxis.cxx 35367 2010-09-17 12:43:00Z brun $
00002 // Author: Rene Brun   18/05/95
00003 
00004 #include <string.h>
00005 #include <stdio.h>
00006 #include <ctype.h>
00007 
00008 #include "TH1.h"
00009 
00010 
00011 //______________________________________________________________________________
00012 Int_t TH1::AxisChoice( Option_t *axis) const
00013 {
00014    // Choose an axis according to "axis".
00015 
00016    char achoice = toupper(axis[0]);
00017    if (achoice == 'X') return 1;
00018    if (achoice == 'Y') return 2;
00019    if (achoice == 'Z') return 3;
00020    return 0;
00021 }
00022 
00023 
00024 //______________________________________________________________________________
00025 Int_t TH1::GetNdivisions( Option_t *axis) const
00026 {
00027    // Return the number of divisions for "axis".
00028 
00029    Int_t ax = AxisChoice(axis);
00030    if (ax == 1) return fXaxis.GetNdivisions();
00031    if (ax == 2) return fYaxis.GetNdivisions();
00032    if (ax == 3) return fZaxis.GetNdivisions();
00033    return 0;
00034 }
00035 
00036 
00037 //______________________________________________________________________________
00038 Color_t TH1::GetAxisColor( Option_t *axis) const
00039 {
00040    // Return the number of divisions for "axis".
00041 
00042    Int_t ax = AxisChoice(axis);
00043    if (ax == 1) return fXaxis.GetAxisColor();
00044    if (ax == 2) return fYaxis.GetAxisColor();
00045    if (ax == 3) return fZaxis.GetAxisColor();
00046    return 0;
00047 }
00048 
00049 
00050 //______________________________________________________________________________
00051 Color_t TH1::GetLabelColor( Option_t *axis) const
00052 {
00053    // Return the "axis" label color.
00054 
00055    Int_t ax = AxisChoice(axis);
00056    if (ax == 1) return fXaxis.GetLabelColor();
00057    if (ax == 2) return fYaxis.GetLabelColor();
00058    if (ax == 3) return fZaxis.GetLabelColor();
00059    return 0;
00060 }
00061 
00062 
00063 //______________________________________________________________________________
00064 Style_t TH1::GetLabelFont( Option_t *axis) const
00065 {
00066    // Return the "axis" label font.
00067 
00068    Int_t ax = AxisChoice(axis);
00069    if (ax == 1) return fXaxis.GetLabelFont();
00070    if (ax == 2) return fYaxis.GetLabelFont();
00071    if (ax == 3) return fZaxis.GetLabelFont();
00072    return 0;
00073 }
00074 
00075 
00076 //______________________________________________________________________________
00077 Float_t TH1::GetLabelOffset( Option_t *axis) const
00078 {
00079    // Return the "axis" label offset.
00080 
00081    Int_t ax = AxisChoice(axis);
00082    if (ax == 1) return fXaxis.GetLabelOffset();
00083    if (ax == 2) return fYaxis.GetLabelOffset();
00084    if (ax == 3) return fZaxis.GetLabelOffset();
00085    return 0;
00086 }
00087 
00088 
00089 //______________________________________________________________________________
00090 Float_t TH1::GetLabelSize( Option_t *axis) const
00091 {
00092    // Return the "axis" label size.
00093 
00094    Int_t ax = AxisChoice(axis);
00095    if (ax == 1) return fXaxis.GetLabelSize();
00096    if (ax == 2) return fYaxis.GetLabelSize();
00097    if (ax == 3) return fZaxis.GetLabelSize();
00098    return 0;
00099 }
00100 
00101 
00102 //______________________________________________________________________________
00103 Float_t TH1::GetTickLength( Option_t *axis) const
00104 {
00105    // Return the "axis" tick length.
00106 
00107    Int_t ax = AxisChoice(axis);
00108    if (ax == 1) return fXaxis.GetTickLength();
00109    if (ax == 2) return fYaxis.GetTickLength();
00110    if (ax == 3) return fZaxis.GetTickLength();
00111    return 0;
00112 }
00113 
00114 
00115 //______________________________________________________________________________
00116 Style_t TH1::GetTitleFont( Option_t *axis) const
00117 {
00118    // Return the "axis" title font.
00119 
00120    Int_t ax = AxisChoice(axis);
00121    if (ax == 1) return fXaxis.GetTitleFont();
00122    if (ax == 2) return fYaxis.GetTitleFont();
00123    if (ax == 3) return fZaxis.GetTitleFont();
00124    return 0;
00125 }
00126 
00127 
00128 //______________________________________________________________________________
00129 Float_t TH1::GetTitleOffset( Option_t *axis) const
00130 {
00131    // Return the "axis" title offset.
00132 
00133    Int_t ax = AxisChoice(axis);
00134    if (ax == 1) return fXaxis.GetTitleOffset();
00135    if (ax == 2) return fYaxis.GetTitleOffset();
00136    if (ax == 3) return fZaxis.GetTitleOffset();
00137    return 0;
00138 }
00139 
00140 
00141 //______________________________________________________________________________
00142 Float_t TH1::GetTitleSize( Option_t *axis) const
00143 {
00144    // Return the "axis" title size.
00145 
00146    Int_t ax = AxisChoice(axis);
00147    if (ax == 1) return fXaxis.GetTitleSize();
00148    if (ax == 2) return fYaxis.GetTitleSize();
00149    if (ax == 3) return fZaxis.GetTitleSize();
00150    return 0;
00151 }
00152 
00153 
00154 //______________________________________________________________________________
00155 void TH1::SetNdivisions(Int_t n, Option_t *axis)
00156 {
00157    // Set the number of divisions to draw an axis.
00158    //  ndiv      : Number of divisions.
00159    //
00160    //       n = N1 + 100*N2 + 10000*N3
00161    //       N1=number of primary divisions.
00162    //       N2=number of secondary divisions.
00163    //       N3=number of 3rd divisions.
00164    //           e.g.:
00165    //           nndi=0 --> no tick marks.
00166    //           nndi=2 --> 2 divisions, one tick mark in the middle
00167    //                      of the axis.
00168    // axis specifies which axis ("x","y","z"), default = "x"
00169    // if axis="xyz" set all 3 axes
00170 
00171    TString opt = axis;
00172    opt.ToLower();
00173 
00174    if (opt.Contains("x")) fXaxis.SetNdivisions(n);
00175    if (opt.Contains("y")) fYaxis.SetNdivisions(n);
00176    if (opt.Contains("z")) fZaxis.SetNdivisions(n);
00177 }
00178 
00179 
00180 //______________________________________________________________________________
00181 void TH1::SetAxisColor(Color_t color, Option_t *axis)
00182 {
00183    // Set color to draw the axis line and tick marks.
00184    // axis specifies which axis ("x","y","z"), default = "x"
00185    // if axis="xyz" set all 3 axes
00186 
00187    TString opt = axis;
00188    opt.ToLower();
00189 
00190    if (opt.Contains("x")) fXaxis.SetAxisColor(color);
00191    if (opt.Contains("y")) fYaxis.SetAxisColor(color);
00192    if (opt.Contains("z")) fZaxis.SetAxisColor(color);
00193 }
00194 
00195 
00196 //______________________________________________________________________________
00197 void TH1::SetAxisRange(Axis_t xmin, Axis_t xmax, Option_t *axis)
00198 {
00199    // Set the "axis" range.
00200 
00201    Int_t ax = AxisChoice(axis);
00202    TAxis *theAxis = 0;
00203    if (ax == 1) theAxis = GetXaxis();
00204    if (ax == 2) theAxis = GetYaxis();
00205    if (ax == 3) theAxis = GetZaxis();
00206    if (!theAxis) return;
00207    if (ax > fDimension) {
00208       SetMinimum(xmin);
00209       SetMaximum(xmax);
00210       return;
00211    }
00212    Int_t bin1 = theAxis->FindFixBin(xmin);
00213    Int_t bin2 = theAxis->FindFixBin(xmax);
00214    theAxis->SetRange(bin1, bin2);
00215 }
00216 
00217 
00218 //______________________________________________________________________________
00219 void TH1::SetLabelColor(Color_t color, Option_t *axis)
00220 {
00221    // Set axis labels color.
00222    // axis specifies which axis ("x","y","z"), default = "x"
00223    // if axis="xyz" set all 3 axes
00224 
00225    TString opt = axis;
00226    opt.ToLower();
00227 
00228    if (opt.Contains("x")) fXaxis.SetLabelColor(color);
00229    if (opt.Contains("y")) fYaxis.SetLabelColor(color);
00230    if (opt.Contains("z")) fZaxis.SetLabelColor(color);
00231 }
00232 
00233 
00234 //______________________________________________________________________________
00235 void TH1::SetLabelFont(Style_t font, Option_t *axis)
00236 {
00237    // Set font number used to draw axis labels.
00238    // font  : Text font code = 10*fontnumber + precision
00239    //         Font numbers must be between 1 and 14
00240    //         precision = 1 fast hardware fonts (steps in the size)
00241    //         precision = 2 scalable and rotatable hardware fonts
00242    // The default font number is 62.
00243    // axis specifies which axis ("x","y","z"), default = "x"
00244    // if axis="xyz" set all 3 axes
00245 
00246    TString opt = axis;
00247    opt.ToLower();
00248 
00249    if (opt.Contains("x")) fXaxis.SetLabelFont(font);
00250    if (opt.Contains("y")) fYaxis.SetLabelFont(font);
00251    if (opt.Contains("z")) fZaxis.SetLabelFont(font);
00252 }
00253 
00254 
00255 //______________________________________________________________________________
00256 void TH1::SetLabelOffset(Float_t offset, Option_t *axis)
00257 {
00258    // Set offset between axis and axis' labels.
00259    // The offset is expressed as a percent of the pad height.
00260    // axis specifies which axis ("x","y","z"), default = "x"
00261    // if axis="xyz" set all 3 axes
00262 
00263    TString opt = axis;
00264    opt.ToLower();
00265 
00266    if (opt.Contains("x")) fXaxis.SetLabelOffset(offset);
00267    if (opt.Contains("y")) fYaxis.SetLabelOffset(offset);
00268    if (opt.Contains("z")) fZaxis.SetLabelOffset(offset);
00269 }
00270 
00271 
00272 //______________________________________________________________________________
00273 void TH1::SetLabelSize(Float_t size, Option_t *axis)
00274 {
00275    // Set size of axis' labels.
00276    // The size is expressed as a percent of the pad height.
00277    // axis specifies which axis ("x","y","z"), default = "x"
00278    // if axis="xyz" set all 3 axes
00279 
00280    TString opt = axis;
00281    opt.ToLower();
00282 
00283    if (opt.Contains("x")) fXaxis.SetLabelSize(size);
00284    if (opt.Contains("y")) fYaxis.SetLabelSize(size);
00285    if (opt.Contains("z")) fZaxis.SetLabelSize(size);
00286 }
00287 
00288 
00289 //______________________________________________________________________________
00290 void TH1::SetTickLength(Float_t length, Option_t *axis)
00291 {
00292    // Set the axis' tick marks length.
00293    // axis specifies which axis ("x","y","z"), default = "x"
00294    // if axis="xyz" set all 3 axes
00295 
00296    TString opt = axis;
00297    opt.ToLower();
00298 
00299    if (opt.Contains("x")) fXaxis.SetTickLength(length);
00300    if (opt.Contains("y")) fYaxis.SetTickLength(length);
00301    if (opt.Contains("z")) fZaxis.SetTickLength(length);
00302 }
00303 
00304 
00305 //______________________________________________________________________________
00306 void TH1::SetTitleFont(Style_t font, Option_t *axis)
00307 {
00308    // The the axis' title font.
00309    // if axis =="x"  set the X axis title font
00310    // if axis =="y"  set the Y axis title font
00311    // if axis =="z"  set the Z axis title font
00312    // any other value of axis will set the pad title font
00313    //
00314    // if axis="xyz" set all 3 axes
00315 
00316    TString opt = axis;
00317    opt.ToLower();
00318 
00319    if (opt.Contains("x")) fXaxis.SetTitleFont(font);
00320    if (opt.Contains("y")) fYaxis.SetTitleFont(font);
00321    if (opt.Contains("z")) fZaxis.SetTitleFont(font);
00322 }
00323 
00324 
00325 //______________________________________________________________________________
00326 void TH1::SetTitleOffset(Float_t offset, Option_t *axis)
00327 {
00328    // Specify a parameter offset to control the distance between the axis
00329    // and the axis' title.
00330    // offset = 1 means : use the default distance
00331    // offset = 1.2 means: the distance will be 1.2*(default distance)
00332    // offset = 0.8 means: the distance will be 0.8*(default distance)
00333    //
00334    // axis specifies which axis ("x","y","z"), default = "x"
00335    // if axis="xyz" set all 3 axes
00336 
00337    TString opt = axis;
00338    opt.ToLower();
00339 
00340    if (opt.Contains("x")) fXaxis.SetTitleOffset(offset);
00341    if (opt.Contains("y")) fYaxis.SetTitleOffset(offset);
00342    if (opt.Contains("z")) fZaxis.SetTitleOffset(offset);
00343 }
00344 
00345 
00346 //______________________________________________________________________________
00347 void TH1::SetTitleSize(Float_t size, Option_t *axis)
00348 {
00349    // The the axis' title size.
00350    // if axis = "x" set the X axis title size
00351    // if axis = "y" set the Y axis title size
00352    // if axis = "z" set the Z axis title size
00353    //
00354    // if axis ="xyz" set all 3 axes
00355 
00356    TString opt = axis;
00357    opt.ToLower();
00358 
00359    if (opt.Contains("x")) fXaxis.SetTitleSize(size);
00360    if (opt.Contains("y")) fYaxis.SetTitleSize(size);
00361    if (opt.Contains("z")) fZaxis.SetTitleSize(size);
00362 }

Generated on Tue Jul 5 14:24:15 2011 for ROOT_528-00b_version by  doxygen 1.5.1