ROOT logo
// @(#)root/base:$Id$
// Author: Rene Brun   12/12/94

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TAttAxis.h"
#include "TStyle.h"
#include "TVirtualPad.h"
#include "TColor.h"
#include "TClass.h"
#include "TMathBase.h"
#include <stdlib.h>

ClassImp(TAttAxis)


//______________________________________________________________________________
//
//  Manages histogram axis attributes
//

TAttAxis::TAttAxis()
{
   // Constructor.
   ResetAttAxis();
}


//______________________________________________________________________________
TAttAxis::~TAttAxis()
{
   // Destructor.
}


//______________________________________________________________________________
void TAttAxis::Copy(TAttAxis &attaxis) const
{
   // Copy of the object.

   attaxis.fNdivisions  = fNdivisions;
   attaxis.fAxisColor   = fAxisColor;
   attaxis.fLabelColor  = fLabelColor;
   attaxis.fLabelFont   = fLabelFont;
   attaxis.fLabelOffset = fLabelOffset;
   attaxis.fLabelSize   = fLabelSize;
   attaxis.fTickLength  = fTickLength;
   attaxis.fTitleOffset = fTitleOffset;
   attaxis.fTitleSize   = fTitleSize;
   attaxis.fTitleColor  = fTitleColor;
   attaxis.fTitleFont   = fTitleFont;
}


//______________________________________________________________________________
void TAttAxis::ResetAttAxis(Option_t *option)
{
   // Reset axis attributes

   if (gStyle) {
      fNdivisions  = gStyle->GetNdivisions(option);
      fAxisColor   = gStyle->GetAxisColor(option);
      fLabelColor  = gStyle->GetLabelColor(option);
      fLabelFont   = gStyle->GetLabelFont(option);
      fLabelOffset = gStyle->GetLabelOffset(option);
      fLabelSize   = gStyle->GetLabelSize(option);
      fTickLength  = gStyle->GetTickLength(option);
      fTitleOffset = gStyle->GetTitleOffset(option);
      fTitleSize   = gStyle->GetTitleSize(option);
      fTitleColor  = gStyle->GetTitleColor(option);
      fTitleFont   = gStyle->GetTitleFont(option);
   } else {
      fNdivisions  = 510;
      fAxisColor   = 1;
      fLabelColor  = 1;
      fLabelFont   = 62;
      fLabelOffset = 0.005;
      fLabelSize   = 0.04;
      fTickLength  = 0.03;
      fTitleOffset = 1;
      fTitleSize   = fLabelSize;
      fTitleColor  = 1;
      fTitleFont   = 62;
   }
}


//______________________________________________________________________________
void TAttAxis::SaveAttributes(ostream &out, const char *name, const char *subname)
{
    // Save axis attributes as C++ statement(s) on output stream out

   if (fNdivisions != 510) {
      out<<"   "<<name<<subname<<"->SetNdivisions("<<fNdivisions<<");"<<endl;
   }
   if (fAxisColor != 1) {
      if (fAxisColor > 228) {
         TColor::SaveColor(out, fAxisColor);
         out<<"   "<<name<<subname<<"->SetAxisColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetAxisColor("<<fAxisColor<<");"<<endl;
   }
   if (fLabelColor != 1) {
      if (fLabelColor > 228) {
         TColor::SaveColor(out, fLabelColor);
         out<<"   "<<name<<subname<<"->SetLabelColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetLabelColor("<<fLabelColor<<");"<<endl;
   }
   if (fLabelFont != 62) {
      out<<"   "<<name<<subname<<"->SetLabelFont("<<fLabelFont<<");"<<endl;
   }
   if (TMath::Abs(fLabelOffset-0.005) > 0.0001) {
      out<<"   "<<name<<subname<<"->SetLabelOffset("<<fLabelOffset<<");"<<endl;
   }
   if (TMath::Abs(fLabelSize-0.04) > 0.001) {
      out<<"   "<<name<<subname<<"->SetLabelSize("<<fLabelSize<<");"<<endl;
   }
   if (TMath::Abs(fTitleSize-0.04) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTitleSize("<<fTitleSize<<");"<<endl;
   }
   if (TMath::Abs(fTickLength-0.03) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTickLength("<<fTickLength<<");"<<endl;
   }
   if (TMath::Abs(fTitleOffset-1) > 0.001) {
      out<<"   "<<name<<subname<<"->SetTitleOffset("<<fTitleOffset<<");"<<endl;
   }
   if (fTitleColor != 1) {
      if (fTitleColor > 228) {
         TColor::SaveColor(out, fTitleColor);
         out<<"   "<<name<<subname<<"->SetTitleColor(ci);" << endl;
      } else
         out<<"   "<<name<<subname<<"->SetTitleColor("<<fTitleColor<<");"<<endl;
   }
   if (fTitleFont != 62) {
      out<<"   "<<name<<subname<<"->SetTitleFont("<<fTitleFont<<");"<<endl;
   }
}


//______________________________________________________________________________
void TAttAxis::SetAxisColor(Color_t color, Float_t alpha)
{
   // Set color of the line axis and tick marks

   if (alpha<1.) fAxisColor = TColor::GetColorTransparent(color, alpha);
   else          fAxisColor = color;
   if (gPad) gPad->Modified();
}


//______________________________________________________________________________
void TAttAxis::SetLabelColor(Color_t color, Float_t alpha)
{
   // Set color of labels

   if (alpha<1.) fLabelColor = TColor::GetColorTransparent(color, alpha);
   else          fLabelColor = color;
   if (gPad) gPad->Modified();
}


//______________________________________________________________________________
void TAttAxis::SetLabelFont(Style_t font)
{
   // Set labels' font.

   fLabelFont = font;
   if (gPad) gPad->Modified();
}


//______________________________________________________________________________
void TAttAxis::SetLabelOffset(Float_t offset)
{
   // Set distance between the axis and the labels
   // The distance is expressed in per cent of the pad width

   fLabelOffset = offset;
   if (gPad) gPad->Modified();
}


//______________________________________________________________________________
void TAttAxis::SetLabelSize(Float_t size)
{
   // Set size of axis labels
   // The size is expressed in per cent of the pad width

   fLabelSize = size;
   if (gPad) gPad->Modified();
}


//______________________________________________________________________________
void TAttAxis::SetNdivisions(Int_t n, Bool_t optim)
{
   // Set the number of divisions for this axis.
   //
   // if optim = kTRUE (default), the number of divisions will be
   //                   optimized around the specified value.
   // if optim = kFALSE, or n < 0, the axis will be forced to use
   //                   exactly n divisions.
   //
   // n = n1 + 100*n2 + 10000*n3
   //
   // Where n1 is the number of primary divisions,
   // n2 is the number of second order divisions and
   // n3 is the number of third order divisions.
   //
   // e.g. 512 means 12 primary and 5 secondary divisions.
   //
   // If the number of divisions is "optimized" (see above) n1, n2, n3 are
   // maximum values.

   fNdivisions = n;
   if (!optim) fNdivisions = -abs(n);
   if (gPad) gPad->Modified();
}


//______________________________________________________________________________
void TAttAxis::SetNdivisions(Int_t n1, Int_t n2, Int_t n3, Bool_t optim)
{
   //see function above
   SetNdivisions(n1+100*n2+10000*n3, optim);
}


//______________________________________________________________________________
void TAttAxis::SetTickLength(Float_t length)
{
   // Set tick mark length
   // The length is expressed in per cent of the pad width

   fTickLength = length;
   if (gPad) gPad->Modified();
}


//______________________________________________________________________________
void TAttAxis::SetTitleOffset(Float_t offset)
{
   // Set distance between the axis and the axis title
   // Offset is a correction factor with respect to the "standard" value.
   // offset = 1  uses the default position that is computed in function
   // of the label offset and size.
   // offset = 1.2 will add 20 per cent more to the default offset.

   fTitleOffset = offset;
   if (gPad) gPad->Modified();
}


//______________________________________________________________________________
void TAttAxis::SetTitleSize(Float_t size)
{
   // Set size of axis title
   // The size is expressed in per cent of the pad width

   fTitleSize = size;
   if (gPad) gPad->Modified();
}


//______________________________________________________________________________
void TAttAxis::SetTitleColor(Color_t color)
{
   // Set color of axis title

   fTitleColor = color;
   if (gPad) gPad->Modified();
}


//______________________________________________________________________________
void TAttAxis::SetTitleFont(Style_t font)
{
   // Set the title font.

   fTitleFont = font;
   if (gPad) gPad->Modified();
}


//______________________________________________________________________________
void TAttAxis::Streamer(TBuffer &R__b)
{
   // Stream an object of class TAttAxis.

   if (R__b.IsReading()) {
      UInt_t R__s, R__c;
      Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
      if (R__v > 3) {
         R__b.ReadClassBuffer(TAttAxis::Class(), this, R__v, R__s, R__c);
         return;
      }
      //====process old versions before automatic schema evolution
      R__b >> fNdivisions;
      R__b >> fAxisColor;
      R__b >> fLabelColor;
      R__b >> fLabelFont;
      R__b >> fLabelOffset;
      R__b >> fLabelSize;
      R__b >> fTickLength;
      R__b >> fTitleOffset;

      if (R__v > 1 && R__b.GetVersionOwner() > 900)
         R__b >> fTitleSize;
      else
         fTitleSize = fLabelSize;
      if (R__v > 2) {
         R__b >> fTitleColor;
         R__b >> fTitleFont;
      }
      //====end of old versions

   } else {
      R__b.WriteClassBuffer(TAttAxis::Class(),this);
   }
}
 TAttAxis.cxx:1
 TAttAxis.cxx:2
 TAttAxis.cxx:3
 TAttAxis.cxx:4
 TAttAxis.cxx:5
 TAttAxis.cxx:6
 TAttAxis.cxx:7
 TAttAxis.cxx:8
 TAttAxis.cxx:9
 TAttAxis.cxx:10
 TAttAxis.cxx:11
 TAttAxis.cxx:12
 TAttAxis.cxx:13
 TAttAxis.cxx:14
 TAttAxis.cxx:15
 TAttAxis.cxx:16
 TAttAxis.cxx:17
 TAttAxis.cxx:18
 TAttAxis.cxx:19
 TAttAxis.cxx:20
 TAttAxis.cxx:21
 TAttAxis.cxx:22
 TAttAxis.cxx:23
 TAttAxis.cxx:24
 TAttAxis.cxx:25
 TAttAxis.cxx:26
 TAttAxis.cxx:27
 TAttAxis.cxx:28
 TAttAxis.cxx:29
 TAttAxis.cxx:30
 TAttAxis.cxx:31
 TAttAxis.cxx:32
 TAttAxis.cxx:33
 TAttAxis.cxx:34
 TAttAxis.cxx:35
 TAttAxis.cxx:36
 TAttAxis.cxx:37
 TAttAxis.cxx:38
 TAttAxis.cxx:39
 TAttAxis.cxx:40
 TAttAxis.cxx:41
 TAttAxis.cxx:42
 TAttAxis.cxx:43
 TAttAxis.cxx:44
 TAttAxis.cxx:45
 TAttAxis.cxx:46
 TAttAxis.cxx:47
 TAttAxis.cxx:48
 TAttAxis.cxx:49
 TAttAxis.cxx:50
 TAttAxis.cxx:51
 TAttAxis.cxx:52
 TAttAxis.cxx:53
 TAttAxis.cxx:54
 TAttAxis.cxx:55
 TAttAxis.cxx:56
 TAttAxis.cxx:57
 TAttAxis.cxx:58
 TAttAxis.cxx:59
 TAttAxis.cxx:60
 TAttAxis.cxx:61
 TAttAxis.cxx:62
 TAttAxis.cxx:63
 TAttAxis.cxx:64
 TAttAxis.cxx:65
 TAttAxis.cxx:66
 TAttAxis.cxx:67
 TAttAxis.cxx:68
 TAttAxis.cxx:69
 TAttAxis.cxx:70
 TAttAxis.cxx:71
 TAttAxis.cxx:72
 TAttAxis.cxx:73
 TAttAxis.cxx:74
 TAttAxis.cxx:75
 TAttAxis.cxx:76
 TAttAxis.cxx:77
 TAttAxis.cxx:78
 TAttAxis.cxx:79
 TAttAxis.cxx:80
 TAttAxis.cxx:81
 TAttAxis.cxx:82
 TAttAxis.cxx:83
 TAttAxis.cxx:84
 TAttAxis.cxx:85
 TAttAxis.cxx:86
 TAttAxis.cxx:87
 TAttAxis.cxx:88
 TAttAxis.cxx:89
 TAttAxis.cxx:90
 TAttAxis.cxx:91
 TAttAxis.cxx:92
 TAttAxis.cxx:93
 TAttAxis.cxx:94
 TAttAxis.cxx:95
 TAttAxis.cxx:96
 TAttAxis.cxx:97
 TAttAxis.cxx:98
 TAttAxis.cxx:99
 TAttAxis.cxx:100
 TAttAxis.cxx:101
 TAttAxis.cxx:102
 TAttAxis.cxx:103
 TAttAxis.cxx:104
 TAttAxis.cxx:105
 TAttAxis.cxx:106
 TAttAxis.cxx:107
 TAttAxis.cxx:108
 TAttAxis.cxx:109
 TAttAxis.cxx:110
 TAttAxis.cxx:111
 TAttAxis.cxx:112
 TAttAxis.cxx:113
 TAttAxis.cxx:114
 TAttAxis.cxx:115
 TAttAxis.cxx:116
 TAttAxis.cxx:117
 TAttAxis.cxx:118
 TAttAxis.cxx:119
 TAttAxis.cxx:120
 TAttAxis.cxx:121
 TAttAxis.cxx:122
 TAttAxis.cxx:123
 TAttAxis.cxx:124
 TAttAxis.cxx:125
 TAttAxis.cxx:126
 TAttAxis.cxx:127
 TAttAxis.cxx:128
 TAttAxis.cxx:129
 TAttAxis.cxx:130
 TAttAxis.cxx:131
 TAttAxis.cxx:132
 TAttAxis.cxx:133
 TAttAxis.cxx:134
 TAttAxis.cxx:135
 TAttAxis.cxx:136
 TAttAxis.cxx:137
 TAttAxis.cxx:138
 TAttAxis.cxx:139
 TAttAxis.cxx:140
 TAttAxis.cxx:141
 TAttAxis.cxx:142
 TAttAxis.cxx:143
 TAttAxis.cxx:144
 TAttAxis.cxx:145
 TAttAxis.cxx:146
 TAttAxis.cxx:147
 TAttAxis.cxx:148
 TAttAxis.cxx:149
 TAttAxis.cxx:150
 TAttAxis.cxx:151
 TAttAxis.cxx:152
 TAttAxis.cxx:153
 TAttAxis.cxx:154
 TAttAxis.cxx:155
 TAttAxis.cxx:156
 TAttAxis.cxx:157
 TAttAxis.cxx:158
 TAttAxis.cxx:159
 TAttAxis.cxx:160
 TAttAxis.cxx:161
 TAttAxis.cxx:162
 TAttAxis.cxx:163
 TAttAxis.cxx:164
 TAttAxis.cxx:165
 TAttAxis.cxx:166
 TAttAxis.cxx:167
 TAttAxis.cxx:168
 TAttAxis.cxx:169
 TAttAxis.cxx:170
 TAttAxis.cxx:171
 TAttAxis.cxx:172
 TAttAxis.cxx:173
 TAttAxis.cxx:174
 TAttAxis.cxx:175
 TAttAxis.cxx:176
 TAttAxis.cxx:177
 TAttAxis.cxx:178
 TAttAxis.cxx:179
 TAttAxis.cxx:180
 TAttAxis.cxx:181
 TAttAxis.cxx:182
 TAttAxis.cxx:183
 TAttAxis.cxx:184
 TAttAxis.cxx:185
 TAttAxis.cxx:186
 TAttAxis.cxx:187
 TAttAxis.cxx:188
 TAttAxis.cxx:189
 TAttAxis.cxx:190
 TAttAxis.cxx:191
 TAttAxis.cxx:192
 TAttAxis.cxx:193
 TAttAxis.cxx:194
 TAttAxis.cxx:195
 TAttAxis.cxx:196
 TAttAxis.cxx:197
 TAttAxis.cxx:198
 TAttAxis.cxx:199
 TAttAxis.cxx:200
 TAttAxis.cxx:201
 TAttAxis.cxx:202
 TAttAxis.cxx:203
 TAttAxis.cxx:204
 TAttAxis.cxx:205
 TAttAxis.cxx:206
 TAttAxis.cxx:207
 TAttAxis.cxx:208
 TAttAxis.cxx:209
 TAttAxis.cxx:210
 TAttAxis.cxx:211
 TAttAxis.cxx:212
 TAttAxis.cxx:213
 TAttAxis.cxx:214
 TAttAxis.cxx:215
 TAttAxis.cxx:216
 TAttAxis.cxx:217
 TAttAxis.cxx:218
 TAttAxis.cxx:219
 TAttAxis.cxx:220
 TAttAxis.cxx:221
 TAttAxis.cxx:222
 TAttAxis.cxx:223
 TAttAxis.cxx:224
 TAttAxis.cxx:225
 TAttAxis.cxx:226
 TAttAxis.cxx:227
 TAttAxis.cxx:228
 TAttAxis.cxx:229
 TAttAxis.cxx:230
 TAttAxis.cxx:231
 TAttAxis.cxx:232
 TAttAxis.cxx:233
 TAttAxis.cxx:234
 TAttAxis.cxx:235
 TAttAxis.cxx:236
 TAttAxis.cxx:237
 TAttAxis.cxx:238
 TAttAxis.cxx:239
 TAttAxis.cxx:240
 TAttAxis.cxx:241
 TAttAxis.cxx:242
 TAttAxis.cxx:243
 TAttAxis.cxx:244
 TAttAxis.cxx:245
 TAttAxis.cxx:246
 TAttAxis.cxx:247
 TAttAxis.cxx:248
 TAttAxis.cxx:249
 TAttAxis.cxx:250
 TAttAxis.cxx:251
 TAttAxis.cxx:252
 TAttAxis.cxx:253
 TAttAxis.cxx:254
 TAttAxis.cxx:255
 TAttAxis.cxx:256
 TAttAxis.cxx:257
 TAttAxis.cxx:258
 TAttAxis.cxx:259
 TAttAxis.cxx:260
 TAttAxis.cxx:261
 TAttAxis.cxx:262
 TAttAxis.cxx:263
 TAttAxis.cxx:264
 TAttAxis.cxx:265
 TAttAxis.cxx:266
 TAttAxis.cxx:267
 TAttAxis.cxx:268
 TAttAxis.cxx:269
 TAttAxis.cxx:270
 TAttAxis.cxx:271
 TAttAxis.cxx:272
 TAttAxis.cxx:273
 TAttAxis.cxx:274
 TAttAxis.cxx:275
 TAttAxis.cxx:276
 TAttAxis.cxx:277
 TAttAxis.cxx:278
 TAttAxis.cxx:279
 TAttAxis.cxx:280
 TAttAxis.cxx:281
 TAttAxis.cxx:282
 TAttAxis.cxx:283
 TAttAxis.cxx:284
 TAttAxis.cxx:285
 TAttAxis.cxx:286
 TAttAxis.cxx:287
 TAttAxis.cxx:288
 TAttAxis.cxx:289
 TAttAxis.cxx:290
 TAttAxis.cxx:291
 TAttAxis.cxx:292
 TAttAxis.cxx:293
 TAttAxis.cxx:294
 TAttAxis.cxx:295
 TAttAxis.cxx:296
 TAttAxis.cxx:297
 TAttAxis.cxx:298
 TAttAxis.cxx:299
 TAttAxis.cxx:300
 TAttAxis.cxx:301
 TAttAxis.cxx:302
 TAttAxis.cxx:303
 TAttAxis.cxx:304
 TAttAxis.cxx:305
 TAttAxis.cxx:306
 TAttAxis.cxx:307
 TAttAxis.cxx:308
 TAttAxis.cxx:309
 TAttAxis.cxx:310
 TAttAxis.cxx:311
 TAttAxis.cxx:312
 TAttAxis.cxx:313
 TAttAxis.cxx:314
 TAttAxis.cxx:315
 TAttAxis.cxx:316
 TAttAxis.cxx:317
 TAttAxis.cxx:318
 TAttAxis.cxx:319
 TAttAxis.cxx:320
 TAttAxis.cxx:321
 TAttAxis.cxx:322
 TAttAxis.cxx:323
 TAttAxis.cxx:324
 TAttAxis.cxx:325
 TAttAxis.cxx:326
 TAttAxis.cxx:327
 TAttAxis.cxx:328