TAttAxis.cxx

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TAttAxis.cxx 27859 2009-03-18 07:34:41Z brun $
00002 // Author: Rene Brun   12/12/94
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "Riostream.h"
00013 #include "TAttAxis.h"
00014 #include "TStyle.h"
00015 #include "TVirtualPad.h"
00016 #include "TColor.h"
00017 #include "TClass.h"
00018 #include "TMathBase.h"
00019 #include <stdlib.h>
00020 
00021 ClassImp(TAttAxis)
00022 
00023 
00024 //______________________________________________________________________________
00025 //
00026 //  Manages histogram axis attributes
00027 //
00028 
00029 TAttAxis::TAttAxis()
00030 {
00031    // Constructor.
00032    ResetAttAxis();
00033 }
00034 
00035 
00036 //______________________________________________________________________________
00037 TAttAxis::~TAttAxis()
00038 {
00039    // Destructor.
00040 }
00041 
00042 
00043 //______________________________________________________________________________
00044 void TAttAxis::Copy(TAttAxis &attaxis) const
00045 {
00046    // Copy of the object.
00047 
00048    attaxis.fNdivisions  = fNdivisions;
00049    attaxis.fAxisColor   = fAxisColor;
00050    attaxis.fLabelColor  = fLabelColor;
00051    attaxis.fLabelFont   = fLabelFont;
00052    attaxis.fLabelOffset = fLabelOffset;
00053    attaxis.fLabelSize   = fLabelSize;
00054    attaxis.fTickLength  = fTickLength;
00055    attaxis.fTitleOffset = fTitleOffset;
00056    attaxis.fTitleSize   = fTitleSize;
00057    attaxis.fTitleColor  = fTitleColor;
00058    attaxis.fTitleFont   = fTitleFont;
00059 }
00060 
00061 
00062 //______________________________________________________________________________
00063 void TAttAxis::ResetAttAxis(Option_t *option)
00064 {
00065    // Reset axis attributes
00066 
00067    if (gStyle) {
00068       fNdivisions  = gStyle->GetNdivisions(option);
00069       fAxisColor   = gStyle->GetAxisColor(option);
00070       fLabelColor  = gStyle->GetLabelColor(option);
00071       fLabelFont   = gStyle->GetLabelFont(option);
00072       fLabelOffset = gStyle->GetLabelOffset(option);
00073       fLabelSize   = gStyle->GetLabelSize(option);
00074       fTickLength  = gStyle->GetTickLength(option);
00075       fTitleOffset = gStyle->GetTitleOffset(option);
00076       fTitleSize   = gStyle->GetTitleSize(option);
00077       fTitleColor  = gStyle->GetTitleColor(option);
00078       fTitleFont   = gStyle->GetTitleFont(option);
00079    } else {
00080       fNdivisions  = 510;
00081       fAxisColor   = 1;
00082       fLabelColor  = 1;
00083       fLabelFont   = 62;
00084       fLabelOffset = 0.005;
00085       fLabelSize   = 0.04;
00086       fTickLength  = 0.03;
00087       fTitleOffset = 1;
00088       fTitleSize   = fLabelSize;
00089       fTitleColor  = 1;
00090       fTitleFont   = 62;
00091    }
00092 }
00093 
00094 
00095 //______________________________________________________________________________
00096 void TAttAxis::SaveAttributes(ostream &out, const char *name, const char *subname)
00097 {
00098     // Save axis attributes as C++ statement(s) on output stream out
00099 
00100    if (fNdivisions != 510) {
00101       out<<"   "<<name<<subname<<"->SetNdivisions("<<fNdivisions<<");"<<endl;
00102    }
00103    if (fAxisColor != 1) {
00104       if (fAxisColor > 228) {
00105          TColor::SaveColor(out, fAxisColor);
00106          out<<"   "<<name<<subname<<"->SetAxisColor(ci);" << endl;
00107       } else
00108          out<<"   "<<name<<subname<<"->SetAxisColor("<<fAxisColor<<");"<<endl;
00109    }
00110    if (fLabelColor != 1) {
00111       if (fLabelColor > 228) {
00112          TColor::SaveColor(out, fLabelColor);
00113          out<<"   "<<name<<subname<<"->SetLabelColor(ci);" << endl;
00114       } else
00115          out<<"   "<<name<<subname<<"->SetLabelColor("<<fLabelColor<<");"<<endl;
00116    }
00117    if (fLabelFont != 62) {
00118       out<<"   "<<name<<subname<<"->SetLabelFont("<<fLabelFont<<");"<<endl;
00119    }
00120    if (TMath::Abs(fLabelOffset-0.005) > 0.0001) {
00121       out<<"   "<<name<<subname<<"->SetLabelOffset("<<fLabelOffset<<");"<<endl;
00122    }
00123    if (TMath::Abs(fLabelSize-0.04) > 0.001) {
00124       out<<"   "<<name<<subname<<"->SetLabelSize("<<fLabelSize<<");"<<endl;
00125    }
00126    if (TMath::Abs(fTitleSize-0.04) > 0.001) {
00127       out<<"   "<<name<<subname<<"->SetTitleSize("<<fTitleSize<<");"<<endl;
00128    }
00129    if (TMath::Abs(fTickLength-0.03) > 0.001) {
00130       out<<"   "<<name<<subname<<"->SetTickLength("<<fTickLength<<");"<<endl;
00131    }
00132    if (TMath::Abs(fTitleOffset-1) > 0.001) {
00133       out<<"   "<<name<<subname<<"->SetTitleOffset("<<fTitleOffset<<");"<<endl;
00134    }
00135    if (fTitleColor != 1) {
00136       if (fTitleColor > 228) {
00137          TColor::SaveColor(out, fTitleColor);
00138          out<<"   "<<name<<subname<<"->SetTitleColor(ci);" << endl;
00139       } else
00140          out<<"   "<<name<<subname<<"->SetTitleColor("<<fTitleColor<<");"<<endl;
00141    }
00142    if (fTitleFont != 62) {
00143       out<<"   "<<name<<subname<<"->SetTitleFont("<<fTitleFont<<");"<<endl;
00144    }
00145 }
00146 
00147 
00148 //______________________________________________________________________________
00149 void TAttAxis::SetAxisColor(Color_t color)
00150 {
00151    // Set color of the line axis and tick marks
00152 
00153    fAxisColor = color;
00154    if (gPad) gPad->Modified();
00155 }
00156 
00157 
00158 //______________________________________________________________________________
00159 void TAttAxis::SetLabelColor(Color_t color)
00160 {
00161    // Set color of labels
00162 
00163    fLabelColor = color;
00164    if (gPad) gPad->Modified();
00165 }
00166 
00167 
00168 //______________________________________________________________________________
00169 void TAttAxis::SetLabelFont(Style_t font)
00170 {
00171    // Set labels' font.
00172 
00173    fLabelFont = font;
00174    if (gPad) gPad->Modified();
00175 }
00176 
00177 
00178 //______________________________________________________________________________
00179 void TAttAxis::SetLabelOffset(Float_t offset)
00180 {
00181    // Set distance between the axis and the labels
00182    // The distance is expressed in per cent of the pad width
00183 
00184    fLabelOffset = offset;
00185    if (gPad) gPad->Modified();
00186 }
00187 
00188 
00189 //______________________________________________________________________________
00190 void TAttAxis::SetLabelSize(Float_t size)
00191 {
00192    // Set size of axis labels
00193    // The size is expressed in per cent of the pad width
00194 
00195    fLabelSize = size;
00196    if (gPad) gPad->Modified();
00197 }
00198 
00199 
00200 //______________________________________________________________________________
00201 void TAttAxis::SetNdivisions(Int_t n, Bool_t optim)
00202 {
00203    // Set the number of divisions for this axis.
00204    //
00205    // if optim = kTRUE (default), the number of divisions will be
00206    //                   optimized around the specified value.
00207    // if optim = kFALSE, or n < 0, the axis will be forced to use
00208    //                   exactly n divisions.
00209    //
00210    // n = n1 + 100*n2 + 10000*n3
00211    //
00212    // Where n1 is the number of primary divisions,
00213    // n2 is the number of second order divisions and
00214    // n3 is the number of third order divisions.
00215    //
00216    // e.g. 512 means 12 primary and 5 secondary divisions.
00217    //
00218    // If the number of divisions is "optimized" (see above) n1, n2, n3 are
00219    // maximum values.
00220 
00221    fNdivisions = n;
00222    if (!optim) fNdivisions = -abs(n);
00223    if (gPad) gPad->Modified();
00224 }
00225 
00226 
00227 //______________________________________________________________________________
00228 void TAttAxis::SetNdivisions(Int_t n1, Int_t n2, Int_t n3, Bool_t optim)
00229 {
00230    //see function above
00231    SetNdivisions(n1+100*n2+10000*n3, optim);
00232 }
00233 
00234 
00235 //______________________________________________________________________________
00236 void TAttAxis::SetTickLength(Float_t length)
00237 {
00238    // Set tick mark length
00239    // The length is expressed in per cent of the pad width
00240 
00241    fTickLength = length;
00242    if (gPad) gPad->Modified();
00243 }
00244 
00245 
00246 //______________________________________________________________________________
00247 void TAttAxis::SetTitleOffset(Float_t offset)
00248 {
00249    // Set distance between the axis and the axis title
00250    // Offset is a correction factor with respect to the "standard" value.
00251    // offset = 1  uses the default position that is computed in function
00252    // of the label offset and size.
00253    // offset = 1.2 will add 20 per cent more to the default offset.
00254 
00255    fTitleOffset = offset;
00256    if (gPad) gPad->Modified();
00257 }
00258 
00259 
00260 //______________________________________________________________________________
00261 void TAttAxis::SetTitleSize(Float_t size)
00262 {
00263    // Set size of axis title
00264    // The size is expressed in per cent of the pad width
00265 
00266    fTitleSize = size;
00267    if (gPad) gPad->Modified();
00268 }
00269 
00270 
00271 //______________________________________________________________________________
00272 void TAttAxis::SetTitleColor(Color_t color)
00273 {
00274    // Set color of axis title
00275 
00276    fTitleColor = color;
00277    if (gPad) gPad->Modified();
00278 }
00279 
00280 
00281 //______________________________________________________________________________
00282 void TAttAxis::SetTitleFont(Style_t font)
00283 {
00284    // Set the title font.
00285 
00286    fTitleFont = font;
00287    if (gPad) gPad->Modified();
00288 }
00289 
00290 
00291 //______________________________________________________________________________
00292 void TAttAxis::Streamer(TBuffer &R__b)
00293 {
00294    // Stream an object of class TAttAxis.
00295 
00296    if (R__b.IsReading()) {
00297       UInt_t R__s, R__c;
00298       Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00299       if (R__v > 3) {
00300          R__b.ReadClassBuffer(TAttAxis::Class(), this, R__v, R__s, R__c);
00301          return;
00302       }
00303       //====process old versions before automatic schema evolution
00304       R__b >> fNdivisions;
00305       R__b >> fAxisColor;
00306       R__b >> fLabelColor;
00307       R__b >> fLabelFont;
00308       R__b >> fLabelOffset;
00309       R__b >> fLabelSize;
00310       R__b >> fTickLength;
00311       R__b >> fTitleOffset;
00312 
00313       if (R__v > 1 && R__b.GetVersionOwner() > 900)
00314          R__b >> fTitleSize;
00315       else
00316          fTitleSize = fLabelSize;
00317       if (R__v > 2) {
00318          R__b >> fTitleColor;
00319          R__b >> fTitleFont;
00320       }
00321       //====end of old versions
00322 
00323    } else {
00324       R__b.WriteClassBuffer(TAttAxis::Class(),this);
00325    }
00326 }

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